-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rules] Skip valid return bool on ReturnNullOverFalseRule (#20)
* tests: Add new test cases for the issue * [Rules] Skip valid return bool on ReturnNullOverFalseRule --------- Co-authored-by: Michael Telgmann <m.telgmann@shopware.com>
- Loading branch information
1 parent
476f8ee
commit df83404
Showing
4 changed files
with
75 additions
and
0 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
29 changes: 29 additions & 0 deletions
29
tests/Rules/ReturnNullOverFalseRule/Fixture/CheckResultFromOtherMethod.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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\TypePerfect\Tests\Rules\ReturnNullOverFalseRule\Fixture; | ||
|
||
class Loader | ||
{ | ||
/** | ||
* @return bool | ||
*/ | ||
public function exists(string $name) | ||
{ | ||
if (!$this->loadFromDb($name)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private function loadFromDb(string $name): ?array | ||
{ | ||
if (mt_rand(1, 0)) { | ||
return null; | ||
} | ||
|
||
return ['test' => 'foo']; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/Rules/ReturnNullOverFalseRule/Fixture/CheckResultFromOtherMethod2.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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\TypePerfect\Tests\Rules\ReturnNullOverFalseRule\Fixture; | ||
|
||
class Entity | ||
{ | ||
/** | ||
* @param string $name | ||
* | ||
* @return bool | ||
*/ | ||
public function __isset($name) | ||
{ | ||
if (!$this->isPropertyVisible($name)) { | ||
return false; | ||
} | ||
|
||
return isset($this->$name); | ||
} | ||
|
||
private function isPropertyVisible(string $name): bool | ||
{ | ||
if (mt_rand(1, 0)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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