rector/rules/Php80/NodeAnalyzer/PromotedPropertyResolver.php
Tomas Votruba 7e46eb8267 Updated Rector to commit a2d6da8b4e5f3058dd95b4db2d173682b250896e
a2d6da8b4e Back to php-scoper 0.14 with scoping from php 8.0 (#2370)
2022-05-27 11:51:31 +00:00

31 lines
873 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\Core\ValueObject\MethodName;
final class PromotedPropertyResolver
{
/**
* @return Param[]
*/
public function resolveFromClass(\PhpParser\Node\Stmt\Class_ $class) : array
{
$constructClassMethod = $class->getMethod(\Rector\Core\ValueObject\MethodName::CONSTRUCT);
if (!$constructClassMethod instanceof \PhpParser\Node\Stmt\ClassMethod) {
return [];
}
$promotedPropertyParams = [];
foreach ($constructClassMethod->getParams() as $param) {
if ($param->flags === 0) {
continue;
}
$promotedPropertyParams[] = $param;
}
return $promotedPropertyParams;
}
}