-
-
Notifications
You must be signed in to change notification settings - Fork 431
[type-declarations] Open isset check in StrictArrayParamDimFetchRectorTest, move to last position in type-declaration level #7388
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
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 |
|---|---|---|
|
|
@@ -51,4 +51,4 @@ final class DifferentUsage { | |
| } | ||
| } | ||
|
|
||
| ?> | ||
| ?> | ||
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 |
|---|---|---|
|
|
@@ -51,4 +51,4 @@ final class WithArrayFilterAndArrayWalk | |
| } | ||
| } | ||
|
|
||
| ?> | ||
| ?> | ||
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 |
|---|---|---|
|
|
@@ -36,4 +36,4 @@ final class TryCatchFinallySameType | |
| } | ||
| } | ||
|
|
||
| ?> | ||
| ?> | ||
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 |
|---|---|---|
|
|
@@ -24,4 +24,4 @@ class FuncCallFound | |
| } | ||
| } | ||
|
|
||
| ?> | ||
| ?> | ||
43 changes: 43 additions & 0 deletions
43
...tor/ClassMethod/StrictArrayParamDimFetchRector/Fixture/cover_isset_with_dim_fetch.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,43 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture; | ||
|
|
||
| final class CoverIssetWithDimFetch | ||
| { | ||
| public function run($param, $item): bool | ||
| { | ||
| if (! isset($param[$item])) { | ||
| return false; | ||
| } | ||
|
|
||
| if ($param[$item] === 100) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture; | ||
|
|
||
| final class CoverIssetWithDimFetch | ||
| { | ||
| public function run(array $param, $item): bool | ||
| { | ||
| if (! isset($param[$item])) { | ||
| return false; | ||
| } | ||
|
|
||
| if ($param[$item] === 100) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
27 changes: 27 additions & 0 deletions
27
...ion/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/include_isset_index.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,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture; | ||
|
|
||
| final class IncludeIssetIndex | ||
| { | ||
| public function run($param): void | ||
| { | ||
| echo isset($param['index']) ? $param['index'] : 'test'; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture; | ||
|
|
||
| final class IncludeIssetIndex | ||
| { | ||
| public function run(array $param): void | ||
| { | ||
| echo isset($param['index']) ? $param['index'] : 'test'; | ||
| } | ||
| } | ||
|
|
||
| ?> |
11 changes: 0 additions & 11 deletions
11
...ration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_isset_index.php.inc
This file was deleted.
Oops, something went wrong.
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
in this case $param could be anything which implements ArrayAccess not just the rare case of string-offset access.
in case you "wrongly guess" the
arraytype a call with a ArrayAccess object will produce a fatal error at runtime - see https://3v4l.org/csROVThere 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.
Indeed, it's a choice of practice over risk of few edge cases. We apply same logic to other rules too, to ease manual daunting work on project upgrades.
If your codebase uses any type in this case, exclude the rule.
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.
Indeed, it's a choice of practice over risk of few edge cases. We apply same logic to other rules too, to ease manual daunting work on project upgrades.
If your codebase uses any type in this case, exclude the rule.