Skip to content

Typehints sometimes incorrectly prepend the current namespace #76

Open
@GuySartorelli

Description

@GuySartorelli

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions