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

Support wider array @param syntax #24

Closed
juliangut opened this issue Jun 8, 2018 · 3 comments
Closed

Support wider array @param syntax #24

juliangut opened this issue Jun 8, 2018 · 3 comments

Comments

@juliangut
Copy link

juliangut commented Jun 8, 2018

PHPStan supports @param array syntax such as

interface MyClass
{
    /**
     * @param array<string, int> $attributes
     */
    public function __construct(array $attributes = []);
}

But \TheCodingMachine\PHPStan\Rules\TypeHints\AbstractMissingTypeHintRule returns error when analyzing the docblock

In method "\MyClass::__construct", for parameter $attributes, invalid docblock @param encountered. "\MyClass\array<string," is not a valid Fqsen.

We end up having to document as @param int[] or @param mixed[]

@moufmouf
Copy link
Member

Interesting, I was under the impression that the "array<string, int>" was not supported by PHPStan. I'll give it another look!

AbstractMissingTypeHintRule is using "better-reflection" under the hood, that itself uses "phpdocumentor/type-resolver". I'll keep this issue open until I have some time to see if I can use the same API that PHPStan uses internally.

@juliangut
Copy link
Author

I have not given this a thorough inspection but PHPStan holds reflection information directly on Scope (https://github.com/phpstan/phpstan/blob/master/src/Rules/FunctionDefinitionCheck.php#L79) so there should be no need to use Better Reflection but to use PHPStan's reflection

This could also fix the problem with speed phpstan-strict-rules have, if I remove them from phpstan.neon execution is much faster

@moufmouf
Copy link
Member

moufmouf commented Jul 3, 2018

Excellent idea!

That was a hell of a refactoring, but I'm almost done: #27

@moufmouf moufmouf closed this as completed Jul 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants