Skip to content

Commit 825f399

Browse files
committed
[Downgrade][Php81][Php80] Handle nullable downgrade initialization on use DowngradeNewInInitializerRector+DowngradePropertyPromotionRector
1 parent edf3b13 commit 825f399

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Issues\DowngradeNullableInitialization;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class DowngradeNullableInitializationTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Rector\Tests\Issues\DowngradeNullableInitialization\Fixture;
4+
5+
final class AddNullableInitializtion
6+
{
7+
public function __construct(
8+
private array $doctrineTypeToScalarType = [
9+
'tinyint' => new \PHPStan\Type\BooleanType(),
10+
]
11+
) {}
12+
}
13+
14+
?>
15+
-----
16+
<?php
17+
18+
namespace Rector\Tests\Issues\DowngradeNullableInitialization\Fixture;
19+
20+
final class AddNullableInitializtion
21+
{
22+
private array $doctrineTypeToScalarType;
23+
public function __construct(?array $doctrineTypeToScalarType = null)
24+
{
25+
$doctrineTypeToScalarType ??= [
26+
'tinyint' => new \PHPStan\Type\BooleanType(),
27+
];
28+
$this->doctrineTypeToScalarType = $doctrineTypeToScalarType;
29+
}
30+
}
31+
32+
?>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector;
7+
use Rector\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->rules([
11+
DowngradeNewInInitializerRector::class,
12+
DowngradePropertyPromotionRector::class,
13+
]);
14+
};

0 commit comments

Comments
 (0)