-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeDeclaration] Skip anonymous class and other object on ReturnUnio…
…nTypeRector (#4670) Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
f45662a
commit 6110a50
Showing
10 changed files
with
156 additions
and
9 deletions.
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
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
39 changes: 39 additions & 0 deletions
39
...turnUnionTypeRector/Fixture/anonymous_class_implements_interface_and_other_object.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,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Fixture; | ||
|
||
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Source\SomeAnonymousInterface; | ||
|
||
final class AnonymousClassImplementsInterface | ||
{ | ||
public function run() | ||
{ | ||
if (rand(0,1)) { | ||
return new AnonymousClassImplementsInterface(); | ||
} | ||
|
||
return new class implements SomeAnonymousInterface{}; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Fixture; | ||
|
||
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Source\SomeAnonymousInterface; | ||
|
||
final class AnonymousClassImplementsInterface | ||
{ | ||
public function run(): \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Fixture\AnonymousClassImplementsInterface|\Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Source\SomeAnonymousInterface | ||
{ | ||
if (rand(0,1)) { | ||
return new AnonymousClassImplementsInterface(); | ||
} | ||
|
||
return new class implements SomeAnonymousInterface{}; | ||
} | ||
} | ||
|
||
?> |
15 changes: 15 additions & 0 deletions
15
...r/ClassMethod/ReturnUnionTypeRector/Fixture/skip_anonymous_class_and_other_object.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\Fixture; | ||
|
||
final class SkipAnonymousClassAndOtherObject | ||
{ | ||
public function run() | ||
{ | ||
if (rand(0,1)) { | ||
return new SkipAnonymousClassAndOtherObject(); | ||
} | ||
|
||
return new class {}; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../ClassMethod/ReturnUnionTypeRector/Fixture/skip_anonymous_class_and_other_object2.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,16 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Fixture; | ||
|
||
final class SkipAnonymousClassAndOtherObject2 | ||
{ | ||
public function run() | ||
{ | ||
if (rand(0,1)) { | ||
return new SkipAnonymousClassAndOtherObject(); | ||
} | ||
|
||
$obj = new class {}; | ||
return $obj; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...peDeclaration/Rector/ClassMethod/ReturnUnionTypeRector/Fixture/skip_docblock_call.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,20 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
final class SkipDocblockCall | ||
{ | ||
public function run() | ||
{ | ||
return $this->execute(); | ||
} | ||
|
||
/** | ||
* @return null|stdClass | ||
*/ | ||
private function execute() | ||
{ | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...aration/Rector/ClassMethod/ReturnUnionTypeRector/Fixture/skip_from_docblock_param.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,16 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
final class SkipFromDocblockParam | ||
{ | ||
/** | ||
* @param null|stdClass | ||
*/ | ||
public function run($param) | ||
{ | ||
return $param; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ypeDeclaration/Rector/ClassMethod/ReturnUnionTypeRector/Source/SomeAnonymousInterface.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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Source; | ||
|
||
interface SomeAnonymousInterface | ||
{ | ||
} |
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