[PHP 8.0] Promoted property fixes (#8)

Co-authored-by: kaizen-ci <info@kaizen-ci.org>
This commit is contained in:
Tomas Votruba 2021-05-11 12:35:03 +02:00 committed by GitHub
parent f451b0b8e1
commit 0684911cdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 17 deletions

View File

@ -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();

View File

@ -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;
}
}
?>

View File

@ -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;

View File

@ -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;
}