-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeDeclaration] Handle return self and static on ReturnTypeFromRetu…
…rnNewRector (#603) * Add failing test fixture for ReturnTypeFromReturnNewRector # Failing Test for ReturnTypeFromReturnNewRector Based on https://getrector.org/demo/1ebef269-093c-6afe-9c29-afdc8959befb refs rectorphp/rector#6595 * Closes #602 Fixes rectorphp/rector#6595 * final touch * centralize check in TypeFactory * mixed * clean up Co-authored-by: Dominik Peters <kuhlesdominik@gmx.de>
- Loading branch information
1 parent
7c937fa
commit e740a93
Showing
6 changed files
with
143 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
25 changes: 25 additions & 0 deletions
25
...eDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/Fixture/return_self.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,25 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Fixture; | ||
|
||
final class ReturnSelf | ||
{ | ||
public function run() | ||
{ | ||
return new self(); | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Fixture; | ||
|
||
final class ReturnSelf | ||
{ | ||
public function run(): self | ||
{ | ||
return new self(); | ||
} | ||
} | ||
?> |
25 changes: 25 additions & 0 deletions
25
...eclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/Fixture/return_static.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,25 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Fixture; | ||
|
||
final class ReturnStatic | ||
{ | ||
public function run() | ||
{ | ||
return new static(); | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Fixture; | ||
|
||
final class ReturnStatic | ||
{ | ||
public function run(): static | ||
{ | ||
return new static(); | ||
} | ||
} | ||
?> |
12 changes: 12 additions & 0 deletions
12
.../Rector/ClassMethod/ReturnTypeFromReturnNewRector/FixturePhp74/skip_return_static.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,12 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\FixturePhp74; | ||
|
||
final class SkipReturnStatic | ||
{ | ||
public function run() | ||
{ | ||
return new static(); | ||
} | ||
} | ||
?> |
33 changes: 33 additions & 0 deletions
33
rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/Php74Test.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\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class Php74Test extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp74'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/php74.php'; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...s-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/config/php74.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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Core\Configuration\Option; | ||
use Rector\Core\ValueObject\PhpVersionFeature; | ||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(ReturnTypeFromReturnNewRector::class); | ||
|
||
$parameters = $containerConfigurator->parameters(); | ||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::STATIC_RETURN_TYPE - 1); | ||
}; |