rector/rules/Php80/NodeResolver/RequireOptionalParamResolver.php
Tomas Votruba 0b3c5d9bcc Updated Rector to commit f22ddc8f18ef345d5e9c99cbb667548c3c854d7d
f22ddc8f18 Add not null compare to FlipTypeControlToUseExclusiveTypeRector (#3513)
2023-03-23 23:21:34 +00:00

28 lines
884 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Php80\NodeResolver;
use PHPStan\Reflection\ParameterReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Type\Type;
final class RequireOptionalParamResolver
{
/**
* @return ParameterReflection[]
*/
public function resolveFromParametersAcceptor(ParametersAcceptor $parametersAcceptor) : array
{
$optionalParams = [];
$requireParams = [];
foreach ($parametersAcceptor->getParameters() as $position => $parameterReflection) {
if (!$parameterReflection->getDefaultValue() instanceof Type && !$parameterReflection->isVariadic()) {
$requireParams[$position] = $parameterReflection;
} else {
$optionalParams[$position] = $parameterReflection;
}
}
return $requireParams + $optionalParams;
}
}