-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeCoverage] Add EmptyOnNullableObjectToInstanceOfRector (#3230)
Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
394fa70
commit c80cd6f
Showing
16 changed files
with
345 additions
and
196 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
55 changes: 0 additions & 55 deletions
55
...tor/Identical/FlipTypeControlToUseExclusiveTypeRector/Fixture/empty_on_exact_type.php.inc
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
...uality/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector/Fixture/fqcn_type.php.inc
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
...Quality/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector/Source/SomeExactType.php
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
..._/EmptyOnNullableObjectToInstanceOfRector/EmptyOnNullableObjectToInstanceOfRectorTest.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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class EmptyOnNullableObjectToInstanceOfRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
/** | ||
* @return Iterator<string> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector/Fixture/empty_on_exact_type.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,55 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Fixture; | ||
|
||
use Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\VariableTypeResolver\Source\AnotherType; | ||
|
||
final class EmptyOnExactType | ||
{ | ||
public function run() | ||
{ | ||
$exactType = $this->getExactType(); | ||
if (empty($exactType)) { | ||
return; | ||
} | ||
} | ||
|
||
private function getExactType(): ?AnotherType | ||
{ | ||
if (mt_rand(0, 1)) { | ||
return new AnotherType(); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Fixture; | ||
|
||
use Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\VariableTypeResolver\Source\AnotherType; | ||
|
||
final class EmptyOnExactType | ||
{ | ||
public function run() | ||
{ | ||
$exactType = $this->getExactType(); | ||
if (!$exactType instanceof \Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\VariableTypeResolver\Source\AnotherType) { | ||
return; | ||
} | ||
} | ||
|
||
private function getExactType(): ?AnotherType | ||
{ | ||
if (mt_rand(0, 1)) { | ||
return new AnotherType(); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
?> |
39 changes: 39 additions & 0 deletions
39
...ation/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector/Fixture/negated_empty.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,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Fixture; | ||
|
||
use Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Source\AnotherObject; | ||
|
||
final class NegatedEmpty | ||
{ | ||
public function run(?AnotherObject $anotherObject) | ||
{ | ||
if (! empty($anotherObject)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Fixture; | ||
|
||
use Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Source\AnotherObject; | ||
|
||
final class NegatedEmpty | ||
{ | ||
public function run(?AnotherObject $anotherObject) | ||
{ | ||
if ($anotherObject instanceof \Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Source\AnotherObject) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> |
39 changes: 39 additions & 0 deletions
39
...laration/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector/Fixture/some_class.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,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Fixture; | ||
|
||
use Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Source\AnotherObject; | ||
|
||
final class SomeClass | ||
{ | ||
public function run(?AnotherObject $anotherObject) | ||
{ | ||
if (empty($anotherObject)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Fixture; | ||
|
||
use Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Source\AnotherObject; | ||
|
||
final class SomeClass | ||
{ | ||
public function run(?AnotherObject $anotherObject) | ||
{ | ||
if (!$anotherObject instanceof \Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Source\AnotherObject) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> |
8 changes: 8 additions & 0 deletions
8
...eclaration/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector/Source/AnotherObject.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,8 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\Source; | ||
|
||
final class AnotherObject | ||
{ | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...laration/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector/config/configured_rule.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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
|
||
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(EmptyOnNullableObjectToInstanceOfRector::class); | ||
}; |
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
Oops, something went wrong.