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

@var annotations in the view files #4486

Closed
b1rdex opened this issue Feb 3, 2021 · 5 comments
Closed

@var annotations in the view files #4486

b1rdex opened this issue Feb 3, 2021 · 5 comments

Comments

@b1rdex
Copy link
Contributor

b1rdex commented Feb 3, 2021

Bug report

@var above use statement works correctly only when the referenced class matches the one imported in use. Is it possible to read all use statements to get the right class name? BTW, PhpStorm supports this correctly.

Code snippet that reproduces the problem

<?php
/**
 * @var ClassName2 $two
 * @var ClassName1 $one
 */

use \Some\Namespaced\ClassName1;
use \Some\Namespaced\ClassName2;

\PHPStan\dumpType($one); // yields Some\Namespaced\ClassName1 – perfect
\PHPStan\dumpType($two); // yields ClassName2 (not a FQCN, error)

https://phpstan.org/r/de78892f-e561-4b25-b54b-a8e1e0f93408

@ondrejmirtes
Copy link
Member

Hi, the bug is actually the opposite of what you expect. Both dumpType should be without the namespace, because the uses are below the PHPDocs. I want to match PHP behaviour: https://3v4l.org/pdAoQ

@b1rdex
Copy link
Contributor Author

b1rdex commented Feb 3, 2021

You're absolutely correct. But, as you know, we're talking about the view templates here 😅
Unfortunately, almost all of our templates are in the mentioned state. That's because PhpStorm imports classes after the file level doc block. But, as I mentioned, PhpStorm supports the syntax and there is no problem.

So as original issues regarding the view templates are – this one is weird too. I can tag other people from the original issues here to see whether they have such a problem too if you want... Pretty sure they're.

@ondrejmirtes
Copy link
Member

Yeah but PHPStan's job is to tell you when your code is wrong, and in this case it is. So expect more pain stemming from this scenario, not less :)

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@4fff79c

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants