-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php80][TypeDeclaration] Fix crash on ClassPropertyAssignToConstructo…
…rPromotionRector + ReturnNeverTypeRector (#6694) * [Php80][TypeDeclaration] Fix crash on ClassPropertyAssignToConstructorPromotionRector + ReturnNeverTypeRector * fix * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <[email protected]>
- Loading branch information
1 parent
fcd141b
commit a1170ac
Showing
4 changed files
with
91 additions
and
1 deletion.
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
42 changes: 42 additions & 0 deletions
42
tests/Issues/PropertyPromoNeverReturn/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,42 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Issues\PropertyPromoNeverReturn\Fixture; | ||
|
||
class Fixture | ||
{ | ||
private $value; | ||
private array $rules; | ||
|
||
public function __construct($value) | ||
{ | ||
$this->value = $value; | ||
|
||
$this->rules = [ | ||
'chave' => function ($value) { | ||
return is_string($value) ? true : 'deve ser uma string'; | ||
}, | ||
]; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Issues\PropertyPromoNeverReturn\Fixture; | ||
|
||
class Fixture | ||
{ | ||
private array $rules; | ||
|
||
public function __construct(private $value) | ||
{ | ||
$this->rules = [ | ||
'chave' => function ($value) { | ||
return is_string($value) ? true : 'deve ser uma string'; | ||
}, | ||
]; | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
tests/Issues/PropertyPromoNeverReturn/PropertyPromoNeverReturnTest.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\PropertyPromoNeverReturn; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class PropertyPromoNeverReturnTest 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'; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Issues/PropertyPromoNeverReturn/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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; | ||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([ | ||
ClassPropertyAssignToConstructorPromotionRector::class, | ||
ReturnNeverTypeRector::class, | ||
]); | ||
}; |