-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Downgrade PHP 8.0] Fix downgrade type copying to property (#1592)
Co-authored-by: Ondrej Mirtes <ondrej@mirtes.cz> Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
58db667
commit b25e351
Showing
16 changed files
with
207 additions
and
10 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
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
32 changes: 32 additions & 0 deletions
32
...owngradePhp80/Rector/Class_/DowngradePropertyPromotionRector/Fixture/array_shapes.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\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture; | ||
|
||
class ArrayShapes | ||
{ | ||
/** @param array<string, array{\stdClass, \Exception}> $value */ | ||
public function __construct(private array $value) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture; | ||
|
||
class ArrayShapes | ||
{ | ||
/** | ||
* @var array<string, array{\stdClass, \Exception}> | ||
*/ | ||
private array $value; | ||
/** @param array<string, array{\stdClass, \Exception}> $value */ | ||
public function __construct(array $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
} | ||
|
||
?> |
32 changes: 32 additions & 0 deletions
32
...tests/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector/Fixture/mixed.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\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture; | ||
|
||
class MixedTypeInPhpDoc | ||
{ | ||
/** @param mixed $value */ | ||
public function __construct(public $value) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture; | ||
|
||
class MixedTypeInPhpDoc | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
public $value; | ||
/** @param mixed $value */ | ||
public function __construct($value) | ||
{ | ||
$this->value = $value; | ||
} | ||
} | ||
|
||
?> |
34 changes: 34 additions & 0 deletions
34
...wngradePhp80/Rector/Class_/DowngradePropertyPromotionRector/Fixture/template_type.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,34 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture; | ||
|
||
/** @template T of \stdClass */ | ||
class TemplateType | ||
{ | ||
/** @param T $value */ | ||
public function __construct(private \stdClass $value) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture; | ||
|
||
/** @template T of \stdClass */ | ||
class TemplateType | ||
{ | ||
/** | ||
* @var T | ||
*/ | ||
private \stdClass $value; | ||
/** @param T $value */ | ||
public function __construct(\stdClass $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
} | ||
|
||
?> |
32 changes: 32 additions & 0 deletions
32
...owngradePhp80/Rector/Class_/DowngradePropertyPromotionRector/Fixture/true_vs_bool.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\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture; | ||
|
||
class TrueVsBool | ||
{ | ||
/** @param array<string, true> $value */ | ||
public function __construct(private array $value) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture; | ||
|
||
class TrueVsBool | ||
{ | ||
/** | ||
* @var array<string, true> | ||
*/ | ||
private array $value; | ||
/** @param array<string, true> $value */ | ||
public function __construct(array $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
} | ||
|
||
?> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Privatization\TypeManipulator; | ||
|
||
use PHPStan\Type\BooleanType; | ||
use PHPStan\Type\Constant\ConstantBooleanType; | ||
use PHPStan\Type\Type; | ||
use PHPStan\Type\TypeTraverser; | ||
|
||
final class TypeNormalizer | ||
{ | ||
/** | ||
* Generalize false/true type to bool, | ||
* as mostly default value but accepts both | ||
*/ | ||
public function generalizeConstantBoolTypes(Type $type): Type | ||
{ | ||
return TypeTraverser::map($type, function (Type $type, callable $traverseCallback): BooleanType|Type { | ||
if ($type instanceof ConstantBooleanType) { | ||
return new BooleanType(); | ||
} | ||
|
||
return $traverseCallback($type, $traverseCallback); | ||
}); | ||
} | ||
} |
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