Repository navigation
Fix global constant discovery after class name tokens #6756
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
Changes from all commits
926babb
6fe3c97
eb89ea1
c654fb3
45d7d34
29f4de3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| parameters: | ||
| level: max | ||
| paths: | ||
| - src |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?php | ||
|
|
||
| echo BAR; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?php | ||
|
|
||
| function foo(): string | ||
| { | ||
| return stdClass::class; | ||
| } | ||
|
|
||
| const BAR = 'bar'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,8 @@ public function clean(string $contents, int $maxMatches): string | |
| if ($inType) { | ||
| $typeLevel--; | ||
|
|
||
| if ($typeLevel === 0) { | ||
| if ($typeLevel <= 0) { | ||
| $typeLevel = 0; | ||
|
Comment on lines
+100
to
+101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this just noise or a required change?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is required. I ran the PR's fixture with the PR's |
||
| $inType = false; | ||
| } | ||
| } | ||
|
|
@@ -146,7 +147,10 @@ public function clean(string $contents, int $maxMatches): string | |
| if (isset($this->typeConfig[$char])) { | ||
| $type = $this->typeConfig[$char]; | ||
|
|
||
| if (substr($this->contents, $this->index, $type['length']) === $type['name']) { | ||
| if ( | ||
| substr($this->contents, $this->index, $type['length']) === $type['name'] | ||
| && $this->match('~.\\b(?<![\\$:>])' . $type['name'] . '\\b~Ais', $match, $this->index - 1) | ||
| ) { | ||
| if ($maxMatches === 1 && $this->match($type['pattern'], $match, $this->index - 1)) { | ||
| return $clean . $match[0]; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| function symbolFinderClassName(): string | ||
| { | ||
| return \stdClass::class; | ||
| } | ||
|
|
||
| const AFTER_CLASS_NAME = 'found'; | ||
|
|
||
| function className(): string | ||
| { | ||
| return 'not a class declaration'; | ||
| } | ||
|
|
||
| const AFTER_CLASS_PREFIX = 'still found'; | ||
|
|
||
| function symbolFinderAnonymousClass(): object | ||
| { | ||
| return new class { | ||
| public const MEMBER = 'not global'; | ||
| }; | ||
| } | ||
|
|
||
| const AFTER_ANONYMOUS_CLASS = 'also found'; | ||
|
|
||
| function symbolFinderNamedArgument(string $class): string | ||
| { | ||
| return $class; | ||
| } | ||
|
|
||
| function symbolFinderNamedArgumentCall(): string | ||
| { | ||
| return symbolFinderNamedArgument(class: 'named argument'); | ||
| } | ||
|
|
||
| const AFTER_NAMED_CLASS_ARGUMENT = 'found after named argument'; | ||
|
|
||
| function symbolFinderSpacedClassConstant(): string | ||
| { | ||
| return \stdClass:: class; | ||
| } | ||
|
|
||
| const AFTER_SPACED_CLASS_CONSTANT = 'found after spaced class constant'; |
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.
on my macOS machine the added reproducer does not emit the errors of the origin reproducer, without the fix beeing applied
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.
for some reason I can reproduce the initial errors now, after I renamed the tests