-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeQuality] Handle possibly has '0' value on string on ExplicitBool…
…CompareRector (#709) * [CodeQuality] Skip explode() on ExplicitBoolCompareRector * Fixed 🎉 * clean up * update failing fixture * Fixed 🎉 * better check * [ci-review] Rector Rectify * fix * naming * cs fix * clean up Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
582d1d3
commit 25f7193
Showing
6 changed files
with
250 additions
and
7 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/explode.php.inc
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,37 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\If_\ExplicitBoolCompareRector\Fixture; | ||
|
||
class SomeExplode | ||
{ | ||
public function run() | ||
{ | ||
$values = explode('_', 'a_0_b'); | ||
foreach ($values as $value) { | ||
if ($value) { | ||
echo $value . PHP_EOL; | ||
} | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\If_\ExplicitBoolCompareRector\Fixture; | ||
|
||
class SomeExplode | ||
{ | ||
public function run() | ||
{ | ||
$values = explode('_', 'a_0_b'); | ||
foreach ($values as $value) { | ||
if ($value !== '' && $value !== '0') { | ||
echo $value . PHP_EOL; | ||
} | ||
} | ||
} | ||
} | ||
|
||
?> |
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
53 changes: 53 additions & 0 deletions
53
...tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value.php.inc
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,53 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\If_\ExplicitBoolCompareRector\Fixture; | ||
|
||
final class StringKnownvalue | ||
{ | ||
public function run() | ||
{ | ||
$item = 'a value'; | ||
|
||
if (!$item) { | ||
return 'empty'; | ||
} | ||
} | ||
|
||
public function run2() | ||
{ | ||
$item = 'a value'; | ||
|
||
if ($item) { | ||
return 'not empty'; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\If_\ExplicitBoolCompareRector\Fixture; | ||
|
||
final class StringKnownvalue | ||
{ | ||
public function run() | ||
{ | ||
$item = 'a value'; | ||
|
||
if ($item === '') { | ||
return 'empty'; | ||
} | ||
} | ||
|
||
public function run2() | ||
{ | ||
$item = 'a value'; | ||
|
||
if ($item !== '') { | ||
return 'not empty'; | ||
} | ||
} | ||
} | ||
|
||
?> |
53 changes: 53 additions & 0 deletions
53
...ests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value2.php.inc
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,53 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\If_\ExplicitBoolCompareRector\Fixture; | ||
|
||
final class StringKnownvalue2 | ||
{ | ||
public function run() | ||
{ | ||
$item = ''; | ||
|
||
if (!$item) { | ||
return 'empty'; | ||
} | ||
} | ||
|
||
public function run2() | ||
{ | ||
$item = ''; | ||
|
||
if ($item) { | ||
return 'not empty'; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\If_\ExplicitBoolCompareRector\Fixture; | ||
|
||
final class StringKnownvalue2 | ||
{ | ||
public function run() | ||
{ | ||
$item = ''; | ||
|
||
if ($item === '') { | ||
return 'empty'; | ||
} | ||
} | ||
|
||
public function run2() | ||
{ | ||
$item = ''; | ||
|
||
if ($item !== '') { | ||
return 'not empty'; | ||
} | ||
} | ||
} | ||
|
||
?> |
53 changes: 53 additions & 0 deletions
53
...ests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value3.php.inc
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,53 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\If_\ExplicitBoolCompareRector\Fixture; | ||
|
||
final class StringSingleChar | ||
{ | ||
public function run() | ||
{ | ||
$item = 'a'; | ||
|
||
if (!$item) { | ||
return 'empty'; | ||
} | ||
} | ||
|
||
public function run2() | ||
{ | ||
$item = 'a'; | ||
|
||
if ($item) { | ||
return 'not empty'; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\If_\ExplicitBoolCompareRector\Fixture; | ||
|
||
final class StringSingleChar | ||
{ | ||
public function run() | ||
{ | ||
$item = 'a'; | ||
|
||
if ($item === '0') { | ||
return 'empty'; | ||
} | ||
} | ||
|
||
public function run2() | ||
{ | ||
$item = 'a'; | ||
|
||
if ($item !== '0') { | ||
return 'not empty'; | ||
} | ||
} | ||
} | ||
|
||
?> |
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