55namespace SavinMikhail \AddNamedArgumentsRector ;
66
77use InvalidArgumentException ;
8- use PhpParser \Node ;
98use PhpParser \ConstExprEvaluator ;
9+ use PhpParser \Node ;
1010use PhpParser \Node \Arg ;
1111use PhpParser \Node \Expr \FuncCall ;
1212use PhpParser \Node \Expr \MethodCall ;
1515use PhpParser \Node \Identifier ;
1616use PHPStan \Reflection \ExtendedParameterReflection ;
1717use PHPStan \Reflection \ReflectionProvider ;
18+ use PHPStan \Type \ConstantScalarType ;
1819use Rector \Contract \Rector \ConfigurableRectorInterface ;
1920use Rector \NodeNameResolver \NodeNameResolver ;
2021use Rector \NodeTypeResolver \NodeTypeResolver ;
2122use Rector \Rector \AbstractRector ;
2223use Rector \ValueObject \PhpVersion ;
2324use Rector \VersionBonding \Contract \MinPhpVersionInterface ;
25+ use RuntimeException ;
2426use SavinMikhail \AddNamedArgumentsRector \Config \ConfigStrategy ;
2527use SavinMikhail \AddNamedArgumentsRector \Config \DefaultStrategy ;
2628use SavinMikhail \AddNamedArgumentsRector \Reflection \Reflection ;
2729use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
2830use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
31+ use Throwable ;
2932use Webmozart \Assert \Assert ;
3033
34+ use function constant ;
3135use function count ;
36+ use function defined ;
3237
3338/**
3439 * @see AddNamedArgumentsRectorTest
@@ -57,11 +62,11 @@ public function __construct(
5762 }
5863 $ this ->reflectionService = $ reflectionService ;
5964 $ this ->constExprEvaluator = $ constExprEvaluator ?? new ConstExprEvaluator (static function (string $ name ) {
60- if (\ defined ($ name )) {
61- return \ constant ($ name );
65+ if (defined ($ name )) {
66+ return constant ($ name );
6267 }
6368
64- throw new \ RuntimeException ("Undefined constant: {$ name }" );
69+ throw new RuntimeException ("Undefined constant: {$ name }" );
6570 });
6671 }
6772
@@ -107,6 +112,7 @@ private function addNamesToArgs(
107112 $ parameter = $ parameters [$ index ] ?? null ;
108113 if ($ parameter === null ) {
109114 $ namedArgs [] = $ arg ;
115+
110116 continue ;
111117 }
112118
@@ -125,19 +131,20 @@ private function shouldSkipArg(Arg $arg, ExtendedParameterReflection $parameter)
125131 {
126132 try {
127133 $ defaultValue = $ parameter ->getDefaultValue ();
128- } catch (\ Throwable ) {
134+ } catch (Throwable ) {
129135 return false ;
130136 }
131137
132138 try {
133139 $ argValue = $ this ->constExprEvaluator ->evaluateDirectly ($ arg ->value );
134- } catch (\ Throwable ) {
140+ } catch (Throwable ) {
135141 return false ;
136142 }
137143
138- if ($ defaultValue instanceof \ PHPStan \ Type \ ConstantScalarType) {
144+ if ($ defaultValue instanceof ConstantScalarType) {
139145 $ defaultValue = $ defaultValue ->getValue ();
140146 }
147+
141148 return $ argValue === $ defaultValue ;
142149 }
143150
0 commit comments