-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ClassPropertyAssignToConstructorPromotionRector to skip propertie…
…s that have attributes (#468) * Add failing test fixture for ClassPropertyAssignToConstructorPromotionRector # Failing Test for ClassPropertyAssignToConstructorPromotionRector Based on https://getrector.org/demo/1ebe95c8-2d22-6d0e-b6ff-7be843d783d4 The ClassPropertyAssignToConstructorPromotionRector should ignore properties that have properties linked to them. Looking at the demo it seems to have gotten rid of both properties, which I did not expect/want it to do * Update coordinate.php.inc reverse order of use statement and namespace * fix: skip properties that have attributes * copy over attrGroups from to to keep them * added test case for multiple attributes Co-authored-by: Dominik Peters <d.peters@billiger-mietwagen.de>
- Loading branch information
Dominik Peters
and
Dominik Peters
committed
Jul 22, 2021
1 parent
99e5c8a
commit 0f9dd92
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...signToConstructorPromotionRector/Fixture/mix_non_attribute_and_attribute_property.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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture; | ||
|
||
use JetBrains\PhpStorm\Immutable; | ||
|
||
final class Coordinate | ||
{ | ||
#[Immutable] | ||
public float $latitude; | ||
|
||
public float $longitude; | ||
|
||
public function __construct(float $latitude, float $longitude) | ||
{ | ||
$this->latitude = $latitude; | ||
$this->longitude = $longitude; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture; | ||
|
||
use JetBrains\PhpStorm\Immutable; | ||
|
||
final class Coordinate | ||
{ | ||
public function __construct(#[Immutable] public float $latitude, public float $longitude) | ||
{ | ||
} | ||
} | ||
?> |
35 changes: 35 additions & 0 deletions
35
..._/ClassPropertyAssignToConstructorPromotionRector/Fixture/property_with_attribute.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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture; | ||
|
||
use JetBrains\PhpStorm\Immutable; | ||
|
||
final class Coordinate | ||
{ | ||
#[Immutable] | ||
public float $latitude; | ||
|
||
public function __construct(float $latitude) | ||
{ | ||
$this->latitude = $latitude; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture; | ||
|
||
use JetBrains\PhpStorm\Immutable; | ||
|
||
final class Coordinate | ||
{ | ||
public function __construct(#[Immutable] public float $latitude) | ||
{ | ||
} | ||
} | ||
?> |
38 changes: 38 additions & 0 deletions
38
...pertyAssignToConstructorPromotionRector/Fixture/property_with_multiple_attributes.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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture; | ||
|
||
use JetBrains\PhpStorm\Deprecated; | ||
use JetBrains\PhpStorm\Immutable; | ||
|
||
final class Coordinate | ||
{ | ||
#[Immutable] | ||
#[Deprecated] | ||
public float $latitude; | ||
|
||
public function __construct(float $latitude) | ||
{ | ||
$this->latitude = $latitude; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture; | ||
|
||
use JetBrains\PhpStorm\Deprecated; | ||
use JetBrains\PhpStorm\Immutable; | ||
|
||
final class Coordinate | ||
{ | ||
public function __construct(#[Immutable] #[Deprecated] public float $latitude) | ||
{ | ||
} | ||
} | ||
?> |
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