Skip to content

Commit 74ba8c2

Browse files
committed
Bleeding edge - enforce @no-named-arguments
1 parent f3810d9 commit 74ba8c2

File tree

50 files changed

+392
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+392
-9
lines changed

src/Analyser/ArgumentsNormalizer.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class ArgumentsNormalizer
2727
public const ORIGINAL_ARG_ATTRIBUTE = 'originalArg';
2828

2929
/**
30-
* @return array{ParametersAcceptor, FuncCall}|null
30+
* @return array{ParametersAcceptor, FuncCall, bool}|null
3131
*/
3232
public static function reorderCallUserFuncArguments(
3333
FuncCall $callUserFuncCall,
@@ -65,18 +65,24 @@ public static function reorderCallUserFuncArguments(
6565
return null;
6666
}
6767

68+
$callableParametersAcceptors = $calledOnType->getCallableParametersAcceptors($scope);
6869
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs(
6970
$scope,
7071
$passThruArgs,
71-
$calledOnType->getCallableParametersAcceptors($scope),
72+
$callableParametersAcceptors,
7273
null,
7374
);
7475

76+
$acceptsNamedArguments = true;
77+
foreach ($callableParametersAcceptors as $callableParametersAcceptor) {
78+
$acceptsNamedArguments = $acceptsNamedArguments && $callableParametersAcceptor->acceptsNamedArguments();
79+
}
80+
7581
return [$parametersAcceptor, new FuncCall(
7682
$callbackArg->value,
7783
$passThruArgs,
7884
$callUserFuncCall->getAttributes(),
79-
)];
85+
), $acceptsNamedArguments];
8086
}
8187

8288
public static function reorderFuncArguments(

src/Analyser/MutatingScope.php

+7
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
13611361
$cachedClosureData['impurePoints'],
13621362
$cachedClosureData['invalidateExpressions'],
13631363
$cachedClosureData['usedVariables'],
1364+
true,
13641365
);
13651366
}
13661367
if (self::$resolveClosureTypeDepth >= 2) {
@@ -1575,6 +1576,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
15751576
$impurePointsForClosureType,
15761577
$invalidateExpressions,
15771578
$usedVariables,
1579+
true,
15781580
);
15791581
} elseif ($node instanceof New_) {
15801582
if ($node->class instanceof Name) {
@@ -2523,9 +2525,11 @@ private function createFirstClassCallable(
25232525

25242526
$throwPoints = [];
25252527
$impurePoints = [];
2528+
$acceptsNamedArguments = true;
25262529
if ($variant instanceof CallableParametersAcceptor) {
25272530
$throwPoints = $variant->getThrowPoints();
25282531
$impurePoints = $variant->getImpurePoints();
2532+
$acceptsNamedArguments = $variant->acceptsNamedArguments();
25292533
} elseif ($function !== null) {
25302534
$returnTypeForThrow = $variant->getReturnType();
25312535
$throwType = $function->getThrowType();
@@ -2549,6 +2553,8 @@ private function createFirstClassCallable(
25492553
if ($impurePoint !== null) {
25502554
$impurePoints[] = $impurePoint;
25512555
}
2556+
2557+
$acceptsNamedArguments = $function->acceptsNamedArguments();
25522558
}
25532559

25542560
$parameters = $variant->getParameters();
@@ -2564,6 +2570,7 @@ private function createFirstClassCallable(
25642570
$impurePoints,
25652571
[],
25662572
[],
2573+
$acceptsNamedArguments,
25672574
);
25682575
}
25692576

src/PhpDoc/TypeNodeResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ function (CallableTypeParameterNode $parameterNode) use ($nameScope, &$isVariadi
961961
),
962962
]);
963963
} elseif ($mainType instanceof ClosureType) {
964-
$closure = new ClosureType($parameters, $returnType, $isVariadic, $templateTypeMap, null, null, $templateTags, [], $mainType->getImpurePoints());
964+
$closure = new ClosureType($parameters, $returnType, $isVariadic, $templateTypeMap, null, null, $templateTags, [], $mainType->getImpurePoints(), $mainType->getInvalidateExpressions(), $mainType->getUsedVariables(), $mainType->acceptsNamedArguments());
965965
if ($closure->isPure()->yes() && $returnType->isVoid()->yes()) {
966966
return new ErrorType();
967967
}

src/Reflection/Annotations/AnnotationMethodReflection.php

+5
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ public function getAsserts(): Assertions
141141
return Assertions::createEmpty();
142142
}
143143

144+
public function acceptsNamedArguments(): bool
145+
{
146+
return $this->declaringClass->acceptsNamedArguments();
147+
}
148+
144149
public function getSelfOutType(): ?Type
145150
{
146151
return null;

src/Reflection/BetterReflection/BetterReflectionProvider.php

+3
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ private function getCustomFunction(string $functionName): PhpFunctionReflection
280280
$isFinal = false;
281281
$isPure = null;
282282
$asserts = Assertions::createEmpty();
283+
$acceptsNamedArguments = true;
283284
$phpDocComment = null;
284285
$phpDocParameterOutTags = [];
285286
$phpDocParameterImmediatelyInvokedCallable = [];
@@ -305,6 +306,7 @@ private function getCustomFunction(string $functionName): PhpFunctionReflection
305306
if ($resolvedPhpDoc->hasPhpDocString()) {
306307
$phpDocComment = $resolvedPhpDoc->getPhpDocString();
307308
}
309+
$acceptsNamedArguments = $resolvedPhpDoc->acceptsNamedArguments();
308310
$phpDocParameterOutTags = $resolvedPhpDoc->getParamOutTags();
309311
$phpDocParameterImmediatelyInvokedCallable = $resolvedPhpDoc->getParamsImmediatelyInvokedCallable();
310312
$phpDocParameterClosureThisTypeTags = $resolvedPhpDoc->getParamClosureThisTags();
@@ -323,6 +325,7 @@ private function getCustomFunction(string $functionName): PhpFunctionReflection
323325
$reflectionFunction->getFileName() !== false ? $reflectionFunction->getFileName() : null,
324326
$isPure,
325327
$asserts,
328+
$acceptsNamedArguments,
326329
$phpDocComment,
327330
array_map(static fn (ParamOutTag $paramOutTag): Type => $paramOutTag->getType(), $phpDocParameterOutTags),
328331
$phpDocParameterImmediatelyInvokedCallable,

src/Reflection/CallableFunctionVariantWithPhpDocs.php

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct(
3535
private array $impurePoints,
3636
private array $invalidateExpressions,
3737
private array $usedVariables,
38+
private bool $acceptsNamedArguments,
3839
)
3940
{
4041
parent::__construct(
@@ -74,4 +75,9 @@ public function getUsedVariables(): array
7475
return $this->usedVariables;
7576
}
7677

78+
public function acceptsNamedArguments(): bool
79+
{
80+
return $this->acceptsNamedArguments;
81+
}
82+
7783
}

src/Reflection/Callables/CallableParametersAcceptor.php

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function getThrowPoints(): array;
1919

2020
public function isPure(): TrinaryLogic;
2121

22+
public function acceptsNamedArguments(): bool;
23+
2224
/**
2325
* @return SimpleImpurePoint[]
2426
*/

src/Reflection/Callables/FunctionCallableVariant.php

+5
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,9 @@ public function getUsedVariables(): array
163163
return [];
164164
}
165165

166+
public function acceptsNamedArguments(): bool
167+
{
168+
return $this->function->acceptsNamedArguments();
169+
}
170+
166171
}

src/Reflection/Dummy/ChangedTypeMethodReflection.php

+5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public function getAsserts(): Assertions
107107
return $this->reflection->getAsserts();
108108
}
109109

110+
public function acceptsNamedArguments(): bool
111+
{
112+
return $this->reflection->acceptsNamedArguments();
113+
}
114+
110115
public function getSelfOutType(): ?Type
111116
{
112117
return $this->reflection->getSelfOutType();

src/Reflection/Dummy/DummyConstructorReflection.php

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public function getAsserts(): Assertions
111111
return Assertions::createEmpty();
112112
}
113113

114+
public function acceptsNamedArguments(): bool
115+
{
116+
return $this->declaringClass->acceptsNamedArguments();
117+
}
118+
114119
public function getSelfOutType(): ?Type
115120
{
116121
return null;

src/Reflection/Dummy/DummyMethodReflection.php

+5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public function getAsserts(): Assertions
108108
return Assertions::createEmpty();
109109
}
110110

111+
public function acceptsNamedArguments(): bool
112+
{
113+
return true;
114+
}
115+
111116
public function getSelfOutType(): ?Type
112117
{
113118
return null;

src/Reflection/ExtendedMethodReflection.php

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function getVariants(): array;
3232
*/
3333
public function getNamedArgumentsVariants(): ?array;
3434

35+
public function acceptsNamedArguments(): bool;
36+
3537
public function getAsserts(): Assertions;
3638

3739
public function getSelfOutType(): ?Type;

src/Reflection/FunctionReflection.php

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function getVariants(): array;
2323
*/
2424
public function getNamedArgumentsVariants(): ?array;
2525

26+
public function acceptsNamedArguments(): bool;
27+
2628
public function isDeprecated(): TrinaryLogic;
2729

2830
public function getDeprecatedDescription(): ?string;

src/Reflection/FunctionReflectionFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function create(
2929
?string $filename,
3030
?bool $isPure,
3131
Assertions $asserts,
32+
bool $acceptsNamedArguments,
3233
?string $phpDocComment,
3334
array $phpDocParameterOutTypes,
3435
array $phpDocParameterImmediatelyInvokedCallable,

src/Reflection/GenericParametersAcceptorResolver.php

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public static function resolve(array $argTypes, ParametersAcceptor $parametersAc
126126
$originalParametersAcceptor->getImpurePoints(),
127127
$originalParametersAcceptor->getInvalidateExpressions(),
128128
$originalParametersAcceptor->getUsedVariables(),
129+
$originalParametersAcceptor->acceptsNamedArguments(),
129130
);
130131
}
131132

src/Reflection/InaccessibleMethod.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
final class InaccessibleMethod implements CallableParametersAcceptor
1414
{
1515

16-
public function __construct(private MethodReflection $methodReflection)
16+
public function __construct(private ExtendedMethodReflection $methodReflection)
1717
{
1818
}
1919

20-
public function getMethod(): MethodReflection
20+
public function getMethod(): ExtendedMethodReflection
2121
{
2222
return $this->methodReflection;
2323
}
@@ -86,4 +86,9 @@ public function getUsedVariables(): array
8686
return [];
8787
}
8888

89+
public function acceptsNamedArguments(): bool
90+
{
91+
return $this->methodReflection->acceptsNamedArguments();
92+
}
93+
8994
}

src/Reflection/Native/NativeFunctionReflection.php

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct(
2929
?Assertions $assertions = null,
3030
private ?string $phpDocComment = null,
3131
?TrinaryLogic $returnsByReference = null,
32+
private bool $acceptsNamedArguments = true,
3233
)
3334
{
3435
$this->assertions = $assertions ?? Assertions::createEmpty();
@@ -132,4 +133,9 @@ public function returnsByReference(): TrinaryLogic
132133
return $this->returnsByReference;
133134
}
134135

136+
public function acceptsNamedArguments(): bool
137+
{
138+
return $this->acceptsNamedArguments;
139+
}
140+
135141
}

src/Reflection/Native/NativeMethodReflection.php

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function __construct(
3232
private TrinaryLogic $hasSideEffects,
3333
private ?Type $throwType,
3434
private Assertions $assertions,
35+
private bool $acceptsNamedArguments,
3536
private ?Type $selfOutType,
3637
private ?string $phpDocComment,
3738
)
@@ -187,6 +188,11 @@ public function getAsserts(): Assertions
187188
return $this->assertions;
188189
}
189190

191+
public function acceptsNamedArguments(): bool
192+
{
193+
return $this->declaringClass->acceptsNamedArguments() && $this->acceptsNamedArguments;
194+
}
195+
190196
public function getSelfOutType(): ?Type
191197
{
192198
return $this->selfOutType;

src/Reflection/ParametersAcceptorSelector.php

+4
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ public static function combineAcceptors(array $acceptors): ParametersAcceptorWit
606606
$impurePoints = [];
607607
$invalidateExpressions = [];
608608
$usedVariables = [];
609+
$acceptsNamedArguments = false;
609610

610611
foreach ($acceptors as $acceptor) {
611612
$returnTypes[] = $acceptor->getReturnType();
@@ -621,6 +622,7 @@ public static function combineAcceptors(array $acceptors): ParametersAcceptorWit
621622
$impurePoints = array_merge($impurePoints, $acceptor->getImpurePoints());
622623
$invalidateExpressions = array_merge($invalidateExpressions, $acceptor->getInvalidateExpressions());
623624
$usedVariables = array_merge($usedVariables, $acceptor->getUsedVariables());
625+
$acceptsNamedArguments = $acceptsNamedArguments || $acceptor->acceptsNamedArguments();
624626
}
625627
$isVariadic = $isVariadic || $acceptor->isVariadic();
626628

@@ -722,6 +724,7 @@ public static function combineAcceptors(array $acceptors): ParametersAcceptorWit
722724
$impurePoints,
723725
$invalidateExpressions,
724726
$usedVariables,
727+
$acceptsNamedArguments,
725728
);
726729
}
727730

@@ -757,6 +760,7 @@ private static function wrapAcceptor(ParametersAcceptor $acceptor): ParametersAc
757760
$acceptor->getImpurePoints(),
758761
$acceptor->getInvalidateExpressions(),
759762
$acceptor->getUsedVariables(),
763+
$acceptor->acceptsNamedArguments(),
760764
);
761765
}
762766

src/Reflection/Php/ClosureCallMethodReflection.php

+5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public function getAsserts(): Assertions
150150
return $this->nativeMethodReflection->getAsserts();
151151
}
152152

153+
public function acceptsNamedArguments(): bool
154+
{
155+
return $this->nativeMethodReflection->acceptsNamedArguments();
156+
}
157+
153158
public function getSelfOutType(): ?Type
154159
{
155160
return $this->nativeMethodReflection->getSelfOutType();

src/Reflection/Php/EnumCasesMethodReflection.php

+5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ public function getAsserts(): Assertions
120120
return Assertions::createEmpty();
121121
}
122122

123+
public function acceptsNamedArguments(): bool
124+
{
125+
return $this->declaringClass->acceptsNamedArguments();
126+
}
127+
123128
public function getSelfOutType(): ?Type
124129
{
125130
return null;

src/Reflection/Php/PhpClassReflectionExtension.php

+6
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ private function createMethod(
477477
$reflectionMethod = null;
478478
$throwType = null;
479479
$asserts = Assertions::createEmpty();
480+
$acceptsNamedArguments = true;
480481
$selfOutType = null;
481482
$phpDocComment = null;
482483
if ($classReflection->getNativeReflection()->hasMethod($methodReflection->getName())) {
@@ -539,6 +540,7 @@ private function createMethod(
539540
}
540541

541542
$asserts = Assertions::createFromResolvedPhpDocBlock($stubPhpDoc);
543+
$acceptsNamedArguments = $stubPhpDoc->acceptsNamedArguments();
542544

543545
$selfOutTypeTag = $stubPhpDoc->getSelfOutTag();
544546
if ($selfOutTypeTag !== null) {
@@ -583,6 +585,7 @@ private function createMethod(
583585
$phpDocParameterTypes[$name] = $paramTag->getType();
584586
}
585587
$asserts = Assertions::createFromResolvedPhpDocBlock($phpDocBlock);
588+
$acceptsNamedArguments = $phpDocBlock->acceptsNamedArguments();
586589

587590
$selfOutTypeTag = $phpDocBlock->getSelfOutTag();
588591
if ($selfOutTypeTag !== null) {
@@ -625,6 +628,7 @@ private function createMethod(
625628
$hasSideEffects,
626629
$throwType,
627630
$asserts,
631+
$acceptsNamedArguments,
628632
$selfOutType,
629633
$phpDocComment,
630634
);
@@ -773,6 +777,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
773777
$isFinal = $resolvedPhpDoc->isFinal();
774778
$isPure = $resolvedPhpDoc->isPure();
775779
$asserts = Assertions::createFromResolvedPhpDocBlock($resolvedPhpDoc);
780+
$acceptsNamedArguments = $resolvedPhpDoc->acceptsNamedArguments();
776781
$selfOutType = $resolvedPhpDoc->getSelfOutTag() !== null ? $resolvedPhpDoc->getSelfOutTag()->getType() : null;
777782
$phpDocComment = null;
778783
if ($resolvedPhpDoc->hasPhpDocString()) {
@@ -793,6 +798,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
793798
$isFinal,
794799
$isPure,
795800
$asserts,
801+
$acceptsNamedArguments,
796802
$selfOutType,
797803
$phpDocComment,
798804
$phpDocParameterOutTypes,

0 commit comments

Comments
 (0)