mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 05:18:18 +01:00
934bc262ff
8ed98c1768
[DX] Use Param->isPromoted() over param->flags !== 0 check on promotion property check (#6646)
31 lines
803 B
PHP
31 lines
803 B
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Php80\NodeAnalyzer;
|
|
|
|
use PhpParser\Node\Param;
|
|
use PhpParser\Node\Stmt\Class_;
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use Rector\ValueObject\MethodName;
|
|
final class PromotedPropertyResolver
|
|
{
|
|
/**
|
|
* @return Param[]
|
|
*/
|
|
public function resolveFromClass(Class_ $class) : array
|
|
{
|
|
$constructClassMethod = $class->getMethod(MethodName::CONSTRUCT);
|
|
if (!$constructClassMethod instanceof ClassMethod) {
|
|
return [];
|
|
}
|
|
$promotedPropertyParams = [];
|
|
foreach ($constructClassMethod->getParams() as $param) {
|
|
if (!$param->isPromoted()) {
|
|
continue;
|
|
}
|
|
$promotedPropertyParams[] = $param;
|
|
}
|
|
return $promotedPropertyParams;
|
|
}
|
|
}
|