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

Lines changed: 9 additions & 3 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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;

0 commit comments

Comments
 (0)