-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Downgrade][Php81][Php80] Handle nullable downgrade initialization on…
… use DowngradeNewInInitializerRector+DowngradePropertyPromotionRector (#243) * [Downgrade][Php81][Php80] Handle nullable downgrade initialization on use DowngradeNewInInitializerRector+DowngradePropertyPromotionRector * [ci-review] Rector Rectify * fix * fix --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
edf3b13
commit 590e1ba
Showing
6 changed files
with
76 additions
and
6 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
tests/Issues/DowngradeNullableInitialization/DowngradeNullableInitializationTest.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\Issues\DowngradeNullableInitialization; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class DowngradeNullableInitializationTest 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'; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/Issues/DowngradeNullableInitialization/Fixture/add_nullable_initialization.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\Issues\DowngradeNullableInitialization\Fixture; | ||
|
||
final class AddNullableInitializtion | ||
{ | ||
public function __construct( | ||
private array $doctrineTypeToScalarType = [ | ||
'tinyint' => new \PHPStan\Type\BooleanType(), | ||
] | ||
) {} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Issues\DowngradeNullableInitialization\Fixture; | ||
|
||
final class AddNullableInitializtion | ||
{ | ||
private array $doctrineTypeToScalarType; | ||
public function __construct(?array $doctrineTypeToScalarType = null) | ||
{ | ||
$this->doctrineTypeToScalarType = $doctrineTypeToScalarType ?? [ | ||
'tinyint' => new \PHPStan\Type\BooleanType(), | ||
]; | ||
$this->doctrineTypeToScalarType = $doctrineTypeToScalarType; | ||
} | ||
} | ||
|
||
?> |
11 changes: 11 additions & 0 deletions
11
tests/Issues/DowngradeNullableInitialization/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\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector; | ||
use Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([DowngradeNewInInitializerRector::class, DowngradePropertyPromotionRector::class]); | ||
}; |