-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeDeclaration] Skip union intersection types on php 8.1, allow on …
…php 8.2+ (#6395) * [TypeDeclaration] Skip union intersection types on php 8.1 * Fix * fix other test * check when multi only
- Loading branch information
1 parent
69d3af9
commit d415260
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...ion/Rector/ClassMethod/ReturnUnionTypeRector/FixturePhp81/skip_union_intersection.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,15 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\FixturePhp81; | ||
|
||
final class SkipUnionIntersection | ||
{ | ||
public function run(\Iterator&\Countable $obj) | ||
{ | ||
if (rand(0, 1)) { | ||
return $obj; | ||
} | ||
|
||
return '10'; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...tor/ClassMethod/ReturnUnionTypeRector/FixtureUnionIntersection/union_intersection.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,41 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\FixtureUnionIntersection; | ||
|
||
/** | ||
* union intersection works on php 8.2+ | ||
*/ | ||
final class UnionIntersection | ||
{ | ||
public function run(\Iterator&\Countable $obj) | ||
{ | ||
if (rand(0, 1)) { | ||
return $obj; | ||
} | ||
|
||
return '10'; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\FixtureUnionIntersection; | ||
|
||
/** | ||
* union intersection works on php 8.2+ | ||
*/ | ||
final class UnionIntersection | ||
{ | ||
public function run(\Iterator&\Countable $obj): (\Iterator&\Countable)|string | ||
{ | ||
if (rand(0, 1)) { | ||
return $obj; | ||
} | ||
|
||
return '10'; | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
...-tests/TypeDeclaration/Rector/ClassMethod/ReturnUnionTypeRector/UnionIntersectionTest.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\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class UnionIntersectionTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureUnionIntersection'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule_union_intersection.php'; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...on/Rector/ClassMethod/ReturnUnionTypeRector/config/configured_rule_union_intersection.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector; | ||
use Rector\ValueObject\PhpVersionFeature; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(ReturnUnionTypeRector::class); | ||
$rectorConfig->phpVersion(PhpVersionFeature::UNION_INTERSECTION_TYPES); | ||
}; |
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