Skip to content

Commit

Permalink
[Php80] Do not remove Parameter attribute on ClassPropertyAssignToCon…
Browse files Browse the repository at this point in the history
…structorPromotionRector (#3179)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Dec 10, 2022
1 parent b23e1fb commit 44ebace
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture;

final class DoNotRemoveParameterAttribute
{
private string $password;

public function __construct(#[\SensitiveParameter] string $password)
{
$this->password = $password;
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture;

final class DoNotRemoveParameterAttribute
{
public function __construct(#[\SensitiveParameter]private string $password)
{
}
}

?>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Rector\Naming\VariableRenamer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Php80\Guard\MakePropertyPromotionGuard;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\Php80\NodeAnalyzer\PromotedPropertyCandidateResolver;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand Down Expand Up @@ -61,8 +60,7 @@ public function __construct(
private readonly VarTagRemover $varTagRemover,
private readonly ParamAnalyzer $paramAnalyzer,
private readonly PhpDocTypeChanger $phpDocTypeChanger,
private readonly MakePropertyPromotionGuard $makePropertyPromotionGuard,
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer
private readonly MakePropertyPromotionGuard $makePropertyPromotionGuard
) {
}

Expand Down Expand Up @@ -170,7 +168,7 @@ public function refactor(Node $node): ?Node

$param->flags = $property->flags;
// Copy over attributes of the "old" property
$param->attrGroups = $property->attrGroups;
$param->attrGroups = array_merge($param->attrGroups, $property->attrGroups);
$this->processNullableType($property, $param);

$this->phpDocTypeChanger->copyPropertyDocToParam($property, $param);
Expand Down Expand Up @@ -226,10 +224,6 @@ private function shouldSkipParam(Param $param): bool
return true;
}

if ($this->phpAttributeAnalyzer->hasPhpAttribute($param, 'SensitiveParameter')) {
return true;
}

if ($this->paramAnalyzer->isNullable($param)) {
/** @var NullableType $type */
$type = $param->type;
Expand Down

0 comments on commit 44ebace

Please sign in to comment.