Skip to content

Commit

Permalink
Do not apply property promotion to parameters with the SensitiveParam…
Browse files Browse the repository at this point in the history
…eter attribute (#3165)

Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
Fixes rectorphp/rector#7644
  • Loading branch information
mbabker committed Dec 7, 2022
1 parent 7636b88 commit b8aff08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

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

final class SkipPropertyPromotionWithSensitiveParameterAttribute
{
private string $password;

public function __construct(#[\SensitiveParameter] string $password)
{
$this->password = $password;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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 @@ -60,7 +61,8 @@ public function __construct(
private readonly VarTagRemover $varTagRemover,
private readonly ParamAnalyzer $paramAnalyzer,
private readonly PhpDocTypeChanger $phpDocTypeChanger,
private readonly MakePropertyPromotionGuard $makePropertyPromotionGuard
private readonly MakePropertyPromotionGuard $makePropertyPromotionGuard,
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer
) {
}

Expand Down Expand Up @@ -224,6 +226,10 @@ 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 b8aff08

Please sign in to comment.