2021-01-18 14:09:48 +01:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\Php80\NodeAnalyzer;
|
2021-01-18 14:09:48 +01:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use PhpParser\Node\Param;
|
|
|
|
use PhpParser\Node\Stmt\Class_;
|
|
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
2024-01-02 02:40:38 +00:00
|
|
|
use Rector\ValueObject\MethodName;
|
2021-01-18 14:09:48 +01:00
|
|
|
final class PromotedPropertyResolver
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return Param[]
|
|
|
|
*/
|
2022-06-07 08:22:29 +00:00
|
|
|
public function resolveFromClass(Class_ $class) : array
|
2021-01-18 14:09:48 +01:00
|
|
|
{
|
2022-06-07 08:22:29 +00:00
|
|
|
$constructClassMethod = $class->getMethod(MethodName::CONSTRUCT);
|
|
|
|
if (!$constructClassMethod instanceof ClassMethod) {
|
2021-01-18 14:09:48 +01:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
$promotedPropertyParams = [];
|
|
|
|
foreach ($constructClassMethod->getParams() as $param) {
|
2025-01-05 04:12:03 +00:00
|
|
|
if (!$param->isPromoted()) {
|
2021-01-18 14:09:48 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$promotedPropertyParams[] = $param;
|
|
|
|
}
|
|
|
|
return $promotedPropertyParams;
|
|
|
|
}
|
|
|
|
}
|