-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix: Do not shorten FQN for class resolution if imported symbol is not a class #7705
base: master
Are you sure you want to change the base?
fix: Do not shorten FQN for class resolution if imported symbol is not a class #7705
Conversation
in #7704 there is a fix already :) |
@mvorisek Are you telling me I wasted my time for implementing this 😩? Eeehhhh.... |
if ($this->cacheUsesLast === $uses) { | ||
return; | ||
} | ||
foreach ($uses as $kind => $kindUses) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the foreach must be put right before the other foreach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a bit more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is evident, the lines after the first foreach
are unrelated to the loop, ie. must be placed before the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still don't get it, sorry. Can you provide it as a suggestion (diff)?
This comment was marked as outdated.
This comment was marked as outdated.
Previously all imports in the processed namespace were flattened to one list and use later for shortening. We need to have imports list sliced by import kind, so we can use proper imports in the context of currently processed part of code (e.g. use only class imports when processing function arguments).
68491f7
to
2811185
Compare
/** @var class-string $fqn */ | ||
$fqn = $fullName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do that because of PHPStan, which expects class-string
, but infers string
from the code above (rightfully), and I couldn't do /** @var class-string $fullName */
before return
because Fixer wants to change it to //
comment and then PHPStan can't see the enforced type 😕.
if ($this->cacheUsesLast === $uses) { | ||
return; | ||
} | ||
foreach ($uses as $kind => $kindUses) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a bit more?
e8bf8bb
to
375464b
Compare
@kubawerlos do you have an idea why this fails? It imports and shortens |
@Wirone I guess the |
@mvorisek I've added this rule explicitly to the "highest" config, but it sometimes works and sometimes not 🤔. |
Well, it looks fine on my PC 😁 I see in the job's log:
but when I run locally from the branch I have:
and I would expect that in CI here too |
I guess we can move updating |
@kubawerlos it works differently when you apply the "highest" ruleset to a single file or to the whole codebase. The CI outcome can be reproduced locally by running the exact command that is run in the CI, and the running |
Fixes #7652