-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit separate type of issue when foreach value is unused (#5932)
* Emit separate type of issue when foreach value is unused Fixes #5929 * Fixed var name case sensitivity
- Loading branch information
Showing
8 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 @@ | ||
# UnusedForeachValue | ||
|
||
Emitted when `--find-dead-code` is turned on and Psalm cannot find any | ||
references to the foreach value | ||
|
||
```php | ||
<?php | ||
|
||
/** @param non-empty-array<string, int> $a */ | ||
function foo(array $a) : void { | ||
foreach ($a as $key => $value) { // $value is unused | ||
break; | ||
} | ||
echo $key; | ||
} | ||
``` | ||
|
||
Can be suppressed by prefixing the variable name with an underscore or naming | ||
it `$_`: | ||
|
||
```php | ||
<?php | ||
|
||
foreach ([1, 2, 3] as $key => $_val) {} | ||
|
||
foreach ([1, 2, 3] as $key => $_) {} | ||
``` |
This file contains 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 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 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 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,9 @@ | ||
<?php | ||
|
||
namespace Psalm\Issue; | ||
|
||
class UnusedForeachValue extends CodeIssue | ||
{ | ||
public const ERROR_LEVEL = -2; | ||
public const SHORTCODE = 275; | ||
} |
This file contains 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