Skip to content

Commit

Permalink
skip already promoted property
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 10, 2021
1 parent a48531e commit b66d096
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

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

final class SkipPromotedPropertyAndOneMore
{
/**
* @var string
*/
private $originalFile;

public function __construct(private string $fileContent)
{
$this->originalFile = $fileContent;
}

public function getOriginalFile(): string
{
return $this->originalFile;
}

public function getFileContent(): string
{
return $this->fileContent;
}
}
4 changes: 4 additions & 0 deletions rules/Php80/NodeResolver/PromotedPropertyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ private function matchPropertyPromotionCandidate(
continue;
}

if ($matchedParam->flags !== 0) {
continue;
}

// is param used above assign?
if ($this->isParamUsedBeforeAssign($assignedExpr, $firstParamAsVariable)) {
continue;
Expand Down

0 comments on commit b66d096

Please sign in to comment.