-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ignore unused foreach option (#66)
* Tests: add tests for ignoreUnusedForeachVariables * README: Add ignoreUnusedForeachVariables * Tests: add normal warnings just to be sure * Add ignoreUnusedForeachVariables option * Add tags to gitignore * Add isForeachLoopVar to VariableInfo * Rename variable to allowUnusedForeachVariables This better matches the other bool options. * Tests: Add foreach loop without key
- Loading branch information
1 parent
6e022ca
commit 30e1278
Showing
6 changed files
with
101 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
phpunit.xml | ||
.phpcs.xml | ||
phpcs.xml | ||
tags |
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
36 changes: 36 additions & 0 deletions
36
VariableAnalysis/Tests/CodeAnalysis/fixtures/UnusedForeachFixture.php
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,36 @@ | ||
<?php | ||
|
||
function loopWithUnusedKey() { | ||
$array = []; | ||
foreach ( $array as $key => $value ) { // maybe marked as unused | ||
echo $value; | ||
$unused = 'foobar'; // should always be marked as unused | ||
echo $undefined; // should always be marked as undefined | ||
} | ||
} | ||
|
||
function loopWithUnusedValue() { | ||
$array = []; | ||
foreach ( $array as $key => $value ) { // maybe marked as unused | ||
echo $key; | ||
$unused = 'foobar'; // should always be marked as unused | ||
echo $undefined; // should always be marked as undefined | ||
} | ||
} | ||
|
||
function loopWithUnusedKeyAndValue() { | ||
$array = []; | ||
foreach ( $array as $key => $value ) { // maybe marked as unused | ||
echo 'hello'; | ||
$unused = 'foobar'; // should always be marked as unused | ||
echo $undefined; // should always be marked as undefined | ||
} | ||
} | ||
|
||
function loopWithUnusedValueOnly() { | ||
$array = []; | ||
foreach ( $array as $value ) { // maybe marked as unused | ||
$unused = 'foobar'; // should always be marked as unused | ||
echo $undefined; // should always be marked as undefined | ||
} | ||
} |