mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-08 04:10:51 +00:00
[PHP 8.0] Promoted property fixes (#8)
Co-authored-by: kaizen-ci <info@kaizen-ci.org>
This commit is contained in:
parent
f451b0b8e1
commit
0684911cdf
28
rector.php
28
rector.php
|
@ -25,20 +25,20 @@ use Symplify\SymfonyPhpConfig\ValueObjectInliner;
|
|||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
// include sets
|
||||
// $containerConfigurator->import(SetList::CODING_STYLE);
|
||||
// $containerConfigurator->import(SetList::CODE_QUALITY);
|
||||
// $containerConfigurator->import(SetList::CODE_QUALITY_STRICT);
|
||||
// $containerConfigurator->import(SetList::DEAD_CODE);
|
||||
// $containerConfigurator->import(SetList::PRIVATIZATION);
|
||||
// $containerConfigurator->import(SetList::NAMING);
|
||||
// $containerConfigurator->import(SetList::TYPE_DECLARATION);
|
||||
// $containerConfigurator->import(SetList::PHP_71);
|
||||
// $containerConfigurator->import(SetList::PHP_72);
|
||||
// $containerConfigurator->import(SetList::PHP_73);
|
||||
// $containerConfigurator->import(SetList::EARLY_RETURN);
|
||||
// $containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
|
||||
// $containerConfigurator->import(NetteSetList::NETTE_UTILS_CODE_QUALITY);
|
||||
// $containerConfigurator->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);
|
||||
$containerConfigurator->import(SetList::CODING_STYLE);
|
||||
$containerConfigurator->import(SetList::CODE_QUALITY);
|
||||
$containerConfigurator->import(SetList::CODE_QUALITY_STRICT);
|
||||
$containerConfigurator->import(SetList::DEAD_CODE);
|
||||
$containerConfigurator->import(SetList::PRIVATIZATION);
|
||||
$containerConfigurator->import(SetList::NAMING);
|
||||
$containerConfigurator->import(SetList::TYPE_DECLARATION);
|
||||
$containerConfigurator->import(SetList::PHP_71);
|
||||
$containerConfigurator->import(SetList::PHP_72);
|
||||
$containerConfigurator->import(SetList::PHP_73);
|
||||
$containerConfigurator->import(SetList::EARLY_RETURN);
|
||||
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
|
||||
$containerConfigurator->import(NetteSetList::NETTE_UTILS_CODE_QUALITY);
|
||||
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture;
|
||||
|
||||
final class AddArrayDefaults
|
||||
{
|
||||
public function __construct(
|
||||
protected array $values = [])
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector\Fixture;
|
||||
|
||||
final class AddArrayDefaults
|
||||
{
|
||||
protected array $values = [];
|
||||
public function __construct(array $values = [])
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -17,7 +17,7 @@ namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRe
|
|||
|
||||
class Fixture
|
||||
{
|
||||
public float $value;
|
||||
public float $value = 0.0;
|
||||
public function __construct(float $value = 0.0)
|
||||
{
|
||||
$this->value = $value;
|
||||
|
|
|
@ -75,7 +75,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$properties = $this->addPropertiesFromParams($promotedParams, $node);
|
||||
$properties = $this->resolvePropertiesFromPromotedParams($promotedParams, $node);
|
||||
|
||||
$this->addPropertyAssignsToConstructorClassMethod($properties, $node);
|
||||
|
||||
|
@ -113,7 +113,7 @@ CODE_SAMPLE
|
|||
* @param Param[] $promotedParams
|
||||
* @return Property[]
|
||||
*/
|
||||
private function addPropertiesFromParams(array $promotedParams, Class_ $class): array
|
||||
private function resolvePropertiesFromPromotedParams(array $promotedParams, Class_ $class): array
|
||||
{
|
||||
$properties = $this->createPropertiesFromParams($promotedParams);
|
||||
$this->classInsertManipulator->addPropertiesToClass($class, $properties);
|
||||
|
@ -155,6 +155,10 @@ CODE_SAMPLE
|
|||
$property->flags = $param->flags;
|
||||
$property->type = $param->type;
|
||||
|
||||
if ($param->default !== null) {
|
||||
$property->props[0]->default = $param->default;
|
||||
}
|
||||
|
||||
$properties[] = $property;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user