-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Downgrade PHP 7.0] Move Throwable out of type hints
It is only available on PHP 7.0+: https://www.php.net/manual/en/class.throwable.php
- Loading branch information
Showing
17 changed files
with
498 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
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
34 changes: 34 additions & 0 deletions
34
...e/DowngradeThrowableTypeDeclarationRector/DowngradeThrowableTypeDeclarationRectorTest.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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class DowngradeThrowableTypeDeclarationRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @requires PHP 8.0 | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ke/DowngradeThrowableTypeDeclarationRector/Fixture/arrow_function_param_throwable.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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class ArrowFunctionParamThrowable | ||
{ | ||
public function run() | ||
{ | ||
$value = fn (\Throwable $param): bool => true; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class ArrowFunctionParamThrowable | ||
{ | ||
public function run() | ||
{ | ||
$value = fn ($param): bool => true; | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
...e/DowngradeThrowableTypeDeclarationRector/Fixture/arrow_function_return_throwable.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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
final class ArrowFunctionReturnThrowable | ||
{ | ||
public function run() | ||
{ | ||
$value = fn () : \Throwable => new \Exception('Yikes!'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
final class ArrowFunctionReturnThrowable | ||
{ | ||
public function run() | ||
{ | ||
$value = fn () => new \Exception('Yikes!'); | ||
} | ||
} | ||
|
||
?> |
30 changes: 30 additions & 0 deletions
30
...ctor/FunctionLike/DowngradeThrowableTypeDeclarationRector/Fixture/docblock_exists.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,30 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class DocblockExists { | ||
/** | ||
* This property is the best one | ||
*/ | ||
public function someFunction(\Throwable $anything) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class DocblockExists { | ||
/** | ||
* This property is the best one | ||
* @param \Throwable $anything | ||
*/ | ||
public function someFunction($anything) | ||
{ | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
.../FunctionLike/DowngradeThrowableTypeDeclarationRector/Fixture/docblock_tag_exists.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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class DocblockTagExists { | ||
/** | ||
* This property is the best one | ||
* @param \Throwable $anything | ||
*/ | ||
public function someFunction(\Throwable $anything) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class DocblockTagExists { | ||
/** | ||
* This property is the best one | ||
* @param \Throwable $anything | ||
*/ | ||
public function someFunction($anything) | ||
{ | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
...Php70/Rector/FunctionLike/DowngradeThrowableTypeDeclarationRector/Fixture/fixture.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,28 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function someFunction(\Throwable $anything) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
/** | ||
* @param \Throwable $anything | ||
*/ | ||
public function someFunction($anything) | ||
{ | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...tionLike/DowngradeThrowableTypeDeclarationRector/Fixture/multiple_matching_params.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,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class MultipleMatchingParams | ||
{ | ||
public function someFunction(\Throwable $anything, string $someOtherVar, \Throwable $someOtherObject) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class MultipleMatchingParams | ||
{ | ||
/** | ||
* @param \Throwable $anything | ||
* @param \Throwable $someOtherObject | ||
*/ | ||
public function someFunction($anything, string $someOtherVar, $someOtherObject) | ||
{ | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
...ctor/FunctionLike/DowngradeThrowableTypeDeclarationRector/Fixture/multiple_params.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,28 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class MultipleParams | ||
{ | ||
public function someFunction(\Throwable $anything, string $someOtherVar) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class MultipleParams | ||
{ | ||
/** | ||
* @param \Throwable $anything | ||
*/ | ||
public function someFunction($anything, string $someOtherVar) | ||
{ | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...hp70/Rector/FunctionLike/DowngradeThrowableTypeDeclarationRector/Fixture/nullable.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,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function someFunction(?\Throwable $anything): ?\Throwable | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
/** | ||
* @param \Throwable|null $anything | ||
* @return \Throwable|null | ||
*/ | ||
public function someFunction($anything) | ||
{ | ||
} | ||
} | ||
|
||
?> |
37 changes: 37 additions & 0 deletions
37
...70/Rector/FunctionLike/DowngradeThrowableTypeDeclarationRector/Fixture/on_closure.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\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class OnClosure | ||
{ | ||
public function run() | ||
{ | ||
$foo = array_filter( | ||
$list, | ||
function (\Throwable $fieldArgValue) { | ||
return is_null($fieldArgValue); | ||
} | ||
); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class OnClosure | ||
{ | ||
public function run() | ||
{ | ||
$foo = array_filter( | ||
$list, | ||
function ($fieldArgValue) { | ||
return is_null($fieldArgValue); | ||
} | ||
); | ||
} | ||
} | ||
|
||
?> |
32 changes: 32 additions & 0 deletions
32
...nctionLike/DowngradeThrowableTypeDeclarationRector/Fixture/return_docblock_exists.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,32 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class ReturnDocblockExists { | ||
/** | ||
* This property is the best one | ||
*/ | ||
public function getAnything(): \Throwable | ||
{ | ||
return new \Exception('Yikes!'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\FunctionLike\DowngradeThrowableTypeDeclarationRector\Fixture; | ||
|
||
class ReturnDocblockExists { | ||
/** | ||
* This property is the best one | ||
* @return \Throwable | ||
*/ | ||
public function getAnything() | ||
{ | ||
return new \Exception('Yikes!'); | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.