-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeDeclaration] Handle Anonymous class extends existing class in un…
…ion (#3161) Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
91ebee8
commit d3abaa1
Showing
6 changed files
with
179 additions
and
3 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
31 changes: 31 additions & 0 deletions
31
.../Property/TypedPropertyFromAssignsRector/Fixture/anonymous_extends_existing_class.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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\Fixture; | ||
|
||
final class AnonymousExtendsExistingClass | ||
{ | ||
private $x; | ||
|
||
public function __construct() | ||
{ | ||
$this->x = new class extends \DateTime {}; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\Fixture; | ||
|
||
final class AnonymousExtendsExistingClass | ||
{ | ||
private \DateTime $x; | ||
|
||
public function __construct() | ||
{ | ||
$this->x = new class extends \DateTime {}; | ||
} | ||
} | ||
|
||
?> |
42 changes: 42 additions & 0 deletions
42
.../TypedPropertyFromAssignsRector/Fixture/anonymous_extends_existing_class_in_union.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\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\Fixture; | ||
|
||
final class AnonymousExtendsExistingClassInUnion | ||
{ | ||
private $x; | ||
|
||
public function __construct() | ||
{ | ||
if (rand(0,1)) { | ||
$this->x = new \DateTime('now'); | ||
} else { | ||
$this->x = new class extends \DateTime {}; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\Fixture; | ||
|
||
final class AnonymousExtendsExistingClassInUnion | ||
{ | ||
/** | ||
* @var \DateTime|null | ||
*/ | ||
private $x; | ||
|
||
public function __construct() | ||
{ | ||
if (rand(0,1)) { | ||
$this->x = new \DateTime('now'); | ||
} else { | ||
$this->x = new class extends \DateTime {}; | ||
} | ||
} | ||
} | ||
|
||
?> |
39 changes: 39 additions & 0 deletions
39
...pedPropertyFromAssignsRector/FixtureComplexTypes/anonymous_extends_existing_class.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\Property\TypedPropertyFromAssignsRector\FixtureComplexTypes; | ||
|
||
final class AnonymousExtendsExistingClassInUnion | ||
{ | ||
private $x; | ||
|
||
public function __construct() | ||
{ | ||
if (rand(0,1)) { | ||
$this->x = new \DateTime('now'); | ||
} else { | ||
$this->x = new class extends \DateTime {}; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\FixtureComplexTypes; | ||
|
||
final class AnonymousExtendsExistingClassInUnion | ||
{ | ||
private \DateTime|null $x = null; | ||
|
||
public function __construct() | ||
{ | ||
if (rand(0,1)) { | ||
$this->x = new \DateTime('now'); | ||
} else { | ||
$this->x = new class extends \DateTime {}; | ||
} | ||
} | ||
} | ||
|
||
?> |
44 changes: 44 additions & 0 deletions
44
...romAssignsRector/FixtureComplexTypes/anonymous_extends_existing_class_remove_docblock.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,44 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\FixtureComplexTypes; | ||
|
||
final class AnonymousExtendsExistingClassInUnionRemoveDocblock | ||
{ | ||
/** | ||
* @var \DateTime|null | ||
*/ | ||
private $x; | ||
|
||
public function __construct() | ||
{ | ||
if (rand(0, 1)) { | ||
$this->x = new \DateTime('now'); | ||
} else { | ||
$this->x = new class() extends \DateTime { | ||
}; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\FixtureComplexTypes; | ||
|
||
final class AnonymousExtendsExistingClassInUnion | ||
{ | ||
private \DateTime|null $x = null; | ||
|
||
public function __construct() | ||
{ | ||
if (rand(0, 1)) { | ||
$this->x = new \DateTime('now'); | ||
} else { | ||
$this->x = new class() extends \DateTime { | ||
}; | ||
} | ||
} | ||
} | ||
|
||
?> |
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