-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php81] Add ConstFetch and ClassConstFetch arg support on NewInInitia…
…lizerRector (#1848) Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
234721a
commit 88d7be3
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...hp81/Rector/ClassMethod/NewInInitializerRector/Fixture/pass_class_const_fetch_arg.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Fixture; | ||
|
||
use DateTime; | ||
use Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Source\SomeValueObject; | ||
|
||
class PassClassConstFetchArg | ||
{ | ||
private DateTime $dateTime; | ||
|
||
public function __construct( | ||
?DateTime $dateTime = null | ||
) { | ||
$this->dateTime = $dateTime ?? new DateTime(SomeValueObject::NOW); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Fixture; | ||
|
||
use DateTime; | ||
use Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Source\SomeValueObject; | ||
|
||
class PassClassConstFetchArg | ||
{ | ||
public function __construct(private DateTime $dateTime = new DateTime(SomeValueObject::NOW)) | ||
{ | ||
} | ||
} | ||
|
||
?> |
37 changes: 37 additions & 0 deletions
37
...ests/Php81/Rector/ClassMethod/NewInInitializerRector/Fixture/pass_const_fetch_arg.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,37 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Fixture; | ||
|
||
use DateTime; | ||
|
||
const NOW = 'now'; | ||
|
||
class PassConstFetchArg | ||
{ | ||
private DateTime $dateTime; | ||
|
||
public function __construct( | ||
?DateTime $dateTime = null | ||
) { | ||
$this->dateTime = $dateTime ?? new DateTime(NOW); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Fixture; | ||
|
||
use DateTime; | ||
|
||
const NOW = 'now'; | ||
|
||
class PassConstFetchArg | ||
{ | ||
public function __construct(private DateTime $dateTime = new DateTime(NOW)) | ||
{ | ||
} | ||
} | ||
|
||
?> |
18 changes: 18 additions & 0 deletions
18
...thod/NewInInitializerRector/Fixture/skip_pass_class_const_fetch_arg_dynamic_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,18 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Fixture; | ||
|
||
use DateTime; | ||
use Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Source\SomeValueObject; | ||
|
||
class SkipPassClassConstFetchArgDynamicClass | ||
{ | ||
private DateTime $dateTime; | ||
|
||
public function __construct( | ||
?DateTime $dateTime = null | ||
) { | ||
$class = SomeValueObject::class; | ||
$this->dateTime = $dateTime ?? new DateTime($class::NOW); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
rules-tests/Php81/Rector/ClassMethod/NewInInitializerRector/Source/SomeValueObject.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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php81\Rector\ClassMethod\NewInInitializerRector\Source; | ||
|
||
final class SomeValueObject | ||
{ | ||
public const NOW = 'now'; | ||
} |
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