Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typehints sometimes incorrectly prepend the current namespace #76

Open
GuySartorelli opened this issue Mar 18, 2025 · 0 comments · May be fixed by #77
Open

Typehints sometimes incorrectly prepend the current namespace #76

GuySartorelli opened this issue Mar 18, 2025 · 0 comments · May be fixed by #77

Comments

@GuySartorelli
Copy link

GuySartorelli commented Mar 18, 2025

Type hints sometimes incorrectly include the namespace of the class they're from when they shouldn't.

For example: https://api.silverstripe.org/6/SilverStripe/Admin/AdminController.html#method_getRequiredPermissions
The markup for the typehint here is <abbr title="SilverStripe\Admin\array|string|false">array|string|false</abbr> - you can see it has evaluated array as SilverStripe\Admin\array.

The source code for this is
https://github.com/silverstripe/silverstripe-admin/blob/eafa62e9ff167f4d5444b20867641f415be9b9f8/code/AdminController.php#L69
public static function getRequiredPermissions(): array|string|false

The namespace declaration in that class is namespace SilverStripe\Admin;

This seems to be happening because NodeVisitor::manageHint() converts the typehint to a string (array|string|false) from its array representation which had the types separated into individual type declarations.

Then NodeVisitor::resolvehint() expects them to still be in the form of an array, but since they're not it goes "array|string|false isn't a PHP type and isn't a FQCN so it must be a class name relative to the current namespace", resulting in SilverStripe\Admin\array|string|false.

PR

GuySartorelli added a commit to GuySartorelli/silverstripe-deprecation-checker that referenced this issue Mar 19, 2025
- Work out types as best as we can
- Ugly workaround for code-lts/doctum#76
- Don't rely on indexes for function comparison
- Detect renamed params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant