-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DowngradePhp70] Add class out of trait
- Loading branch information
1 parent
534f30d
commit 00e1ca2
Showing
3 changed files
with
73 additions
and
13 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...s/DowngradePhp70/Rector/New_/DowngradeAnonymousClassRector/Fixture/class_in_trait.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,32 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\New_\DowngradeAnonymousClassRector\Fixture; | ||
|
||
trait ClassInTrait | ||
{ | ||
public function run() | ||
{ | ||
$message = 'error'; | ||
return new class($message) extends \InvalidArgumentException {}; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp70\Rector\New_\DowngradeAnonymousClassRector\Fixture; | ||
|
||
class AnonymousFor_NotInFunction extends \InvalidArgumentException | ||
{ | ||
} | ||
trait ClassInTrait | ||
{ | ||
public function run() | ||
{ | ||
$message = 'error'; | ||
return new AnonymousFor_NotInFunction($message); | ||
} | ||
} | ||
|
||
?> |
21 changes: 21 additions & 0 deletions
21
rules/DowngradePhp70/NodeFactory/ClassFromAnonymousFactory.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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\DowngradePhp70\NodeFactory; | ||
|
||
use PhpParser\Node\Stmt\Class_; | ||
|
||
final class ClassFromAnonymousFactory | ||
{ | ||
public function create(string $className, Class_ $newClass): Class_ | ||
{ | ||
return new Class_($className, [ | ||
'flags' => $newClass->flags, | ||
'extends' => $newClass->extends, | ||
'implements' => $newClass->implements, | ||
'stmts' => $newClass->stmts, | ||
'attrGroups' => $newClass->attrGroups, | ||
]); | ||
} | ||
} |
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