-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DowngradePhp81] Handle New_ inside array on DowngradeNewInInitialize…
…rRector (#1508) * [DowngradePhp81] Handle New_ inside array on DowngradeNewInInitializerRector * add failing fixture * Fixed 🎉 * [ci-review] Rector Rectify * phpstan * [ci-review] Rector Rectify Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
59089f4
commit e0ba9a3
Showing
6 changed files
with
156 additions
and
9 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...adePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector/Fixture/new_in_array.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,34 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
class NewInArray | ||
{ | ||
public function __construct(public array $property = [ | ||
'a' => new stdClass() | ||
]) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
class NewInArray | ||
{ | ||
public function __construct(public ?array $property = null) | ||
{ | ||
$this->property = $property ?? [ | ||
'a' => new stdClass() | ||
]; | ||
} | ||
} | ||
|
||
?> |
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
33 changes: 33 additions & 0 deletions
33
...s/DowngradeNewInArrayInitializerPromotion/DowngradeNewInArrayInitializerPromotionTest.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\DowngradeNewInArrayInitializerPromotion; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class DowngradeNewInArrayInitializerPromotionTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @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'; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
tests/Issues/DowngradeNewInArrayInitializerPromotion/Fixture/new_in_array.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,45 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\DowngradeNewInArrayInitializerPromotion\Fixture; | ||
|
||
use stdClass; | ||
|
||
class NewInArray | ||
{ | ||
/** | ||
* @param array<string, object> $property | ||
*/ | ||
public function __construct(public array $property = [ | ||
'a' => new stdClass() | ||
]) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\DowngradeNewInArrayInitializerPromotion\Fixture; | ||
|
||
use stdClass; | ||
|
||
class NewInArray | ||
{ | ||
/** | ||
* @var array<string, object> | ||
*/ | ||
public $property; | ||
/** | ||
* @param array<string, object> $property | ||
*/ | ||
public function __construct(array $property = null) | ||
{ | ||
$property ??= [ | ||
'a' => new stdClass() | ||
]; | ||
$this->property = $property; | ||
} | ||
} | ||
|
||
?> |
15 changes: 15 additions & 0 deletions
15
tests/Issues/DowngradeNewInArrayInitializerPromotion/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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector; | ||
use Rector\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector; | ||
use Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(DowngradeNewInInitializerRector::class); | ||
$services->set(DowngradePropertyPromotionRector::class); | ||
$services->set(DowngradeTypedPropertyRector::class); | ||
}; |