-
-
Notifications
You must be signed in to change notification settings - Fork 431
Cover named args in ClassMethodArrayDocblockParamFromLocalCallsRector #7357
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
.../ClassMethodArrayDocblockParamFromLocalCallsRector/Fixture/NamedArgs/flipped_args.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture\NamedArgs; | ||
|
|
||
| final class FlippedArgs | ||
| { | ||
| public function go() | ||
| { | ||
| $this->run(names: ['John', 'Doe'], items: [123, 456]); | ||
| } | ||
|
|
||
| private function run(array $items, array $names) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture\NamedArgs; | ||
|
|
||
| final class FlippedArgs | ||
| { | ||
| public function go() | ||
| { | ||
| $this->run(names: ['John', 'Doe'], items: [123, 456]); | ||
| } | ||
|
|
||
| /** | ||
| * @param int[] $items | ||
| * @param string[] $names | ||
| */ | ||
| private function run(array $items, array $names) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| ?> |
38 changes: 38 additions & 0 deletions
38
...ss_/ClassMethodArrayDocblockParamFromLocalCallsRector/Fixture/NamedArgs/named_arg.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture\NamedArgs; | ||
|
|
||
| final class CoverMixedAndKnown | ||
| { | ||
| public function go() | ||
| { | ||
| $this->run(items: ['item1', 'item2']); | ||
| } | ||
|
|
||
| private function run(array $items) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture\NamedArgs; | ||
|
|
||
| final class CoverMixedAndKnown | ||
| { | ||
| public function go() | ||
| { | ||
| $this->run(items: ['item1', 'item2']); | ||
| } | ||
|
|
||
| /** | ||
| * @param string[] $items | ||
| */ | ||
| private function run(array $items) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -58,7 +58,7 @@ public function resolveStrictTypesFromCalls(array $calls): array | |||
|
|
||||
| /** | ||||
| * @param MethodCall[]|StaticCall[] $calls | ||||
| * @return array<int, Type> | ||||
| * @return array<int|string, Type> | ||||
| */ | ||||
| public function resolveTypesFromCalls(array $calls): array | ||||
| { | ||||
|
|
@@ -67,7 +67,7 @@ public function resolveTypesFromCalls(array $calls): array | |||
| foreach ($calls as $call) { | ||||
| foreach ($call->args as $position => $arg) { | ||||
| if ($this->shouldSkipArg($arg)) { | ||||
| return []; | ||||
| continue; | ||||
| } | ||||
|
|
||||
| /** @var Arg $arg */ | ||||
|
|
@@ -76,7 +76,13 @@ public function resolveTypesFromCalls(array $calls): array | |||
| continue; | ||||
| } | ||||
|
|
||||
| $staticTypesByArgumentPosition[$position][] = $this->resolveArgValueType($arg); | ||||
| if ($arg->name instanceof Identifier) { | ||||
| $positionOrName = $arg->name->toString(); | ||||
| } else { | ||||
| $positionOrName = $position; | ||||
| } | ||||
|
|
||||
| $staticTypesByArgumentPosition[$positionOrName][] = $this->resolveArgValueType($arg); | ||||
|
Member
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. There is
I will create a PR for it.
Member
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. nvm, seems ok on this case 👍 |
||||
| } | ||||
| } | ||||
|
|
||||
|
|
@@ -206,11 +212,7 @@ private function shouldSkipArg(Arg|VariadicPlaceholder $arg): bool | |||
| return true; | ||||
| } | ||||
|
|
||||
| if ($arg->unpack) { | ||||
| return true; | ||||
| } | ||||
|
|
||||
| return $arg->name instanceof Identifier; | ||||
| return $arg->unpack; | ||||
| } | ||||
|
|
||||
| private function isEmptyArray(Expr $expr): bool | ||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
return []was right, when there is a first class callable or unpack in list of calls, should be immediatelly stop all together since we don't know what the arg passed allowed.I will create new PR for it.
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 created PR
for it.