-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeDeclaration] Add BoolReturnTypeFromStrictScalarReturnsRector (#3898
- Loading branch information
1 parent
11b9411
commit a4d6d41
Showing
11 changed files
with
375 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
28 changes: 28 additions & 0 deletions
28
...turnTypeFromStrictScalarReturnsRector/BoolReturnTypeFromStrictScalarReturnsRectorTest.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class BoolReturnTypeFromStrictScalarReturnsRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...r/ClassMethod/BoolReturnTypeFromStrictScalarReturnsRector/Fixture/skip_all_nested.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,17 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector\Fixture; | ||
|
||
final class SkipAllNested | ||
{ | ||
public function resolve($first, $second) | ||
{ | ||
if ($first) { | ||
return false; | ||
} | ||
|
||
if ($second) { | ||
return $first > $second; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...Rector/ClassMethod/BoolReturnTypeFromStrictScalarReturnsRector/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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public function resolve($first, $second) | ||
{ | ||
if ($first) { | ||
return false; | ||
} | ||
|
||
return $first > $second; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public function resolve($first, $second): bool | ||
{ | ||
if ($first) { | ||
return false; | ||
} | ||
|
||
return $first > $second; | ||
} | ||
} | ||
|
||
?> |
43 changes: 43 additions & 0 deletions
43
...ssMethod/BoolReturnTypeFromStrictScalarReturnsRector/Fixture/with_simple_function.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,43 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector\Fixture; | ||
|
||
final class WithSimpleFunction | ||
{ | ||
public function resolve($first, $second) | ||
{ | ||
if ($first) { | ||
return false; | ||
} | ||
|
||
if ($second) { | ||
return $first > $second; | ||
} | ||
|
||
return is_bool($second); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector\Fixture; | ||
|
||
final class WithSimpleFunction | ||
{ | ||
public function resolve($first, $second): bool | ||
{ | ||
if ($first) { | ||
return false; | ||
} | ||
|
||
if ($second) { | ||
return $first > $second; | ||
} | ||
|
||
return is_bool($second); | ||
} | ||
} | ||
|
||
?> |
11 changes: 11 additions & 0 deletions
11
...Rector/ClassMethod/BoolReturnTypeFromStrictScalarReturnsRector/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\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(BoolReturnTypeFromStrictScalarReturnsRector::class); | ||
}; |
Oops, something went wrong.