Skip to content

Commit 5528d1c

Browse files
committed
fix
1 parent 73cdb39 commit 5528d1c

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

src/Analyser/ArgumentsNormalizer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ public static function reorderNewArguments(
182182
}
183183

184184
/**
185-
* @param Arg[] $callArgs
186-
* @return ?array<int, Arg>
185+
* @param list<Arg> $callArgs
186+
* @return ?list<Arg>
187187
*/
188188
public static function reorderArgs(ParametersAcceptor $parametersAcceptor, array $callArgs): ?array
189189
{
@@ -322,6 +322,10 @@ public static function reorderArgs(ParametersAcceptor $parametersAcceptor, array
322322
$reorderedArgs[] = $arg;
323323
}
324324

325+
if (!array_is_list($reorderedArgs)) {
326+
throw new ShouldNotHappenException();
327+
}
328+
325329
return $reorderedArgs;
326330
}
327331

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4455,7 +4455,7 @@ private function getMethodThrowPoint(MethodReflection $methodReflection, Paramet
44554455
}
44564456

44574457
/**
4458-
* @param Node\Arg[] $args
4458+
* @param list<Node\Arg> $args
44594459
*/
44604460
private function getConstructorThrowPoint(MethodReflection $constructorReflection, ParametersAcceptor $parametersAcceptor, ClassReflection $classReflection, New_ $new, Name $className, array $args, MutatingScope $scope): ?ThrowPoint
44614461
{

src/Reflection/ParametersAcceptorSelector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ public static function selectFromArgs(
471471
$parameters = null;
472472
$singleParametersAcceptor = null;
473473
if (count($parametersAcceptors) === 1) {
474+
if (!array_is_list($args)) {
475+
throw new ShouldNotHappenException('args is expected to be a list');
476+
}
474477
$reorderedArgs = ArgumentsNormalizer::reorderArgs($parametersAcceptors[0], $args);
475478
$singleParametersAcceptor = $parametersAcceptors[0];
476479
}

src/Rules/Functions/RandomIntParametersRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function processNode(Node $node, Scope $scope): array
4949
return [];
5050
}
5151

52-
$args = array_values($node->getArgs());
52+
$args = $node->getArgs();
5353
if (count($args) < 2) {
5454
return [];
5555
}

tests/PHPStan/Analyser/ArgumentsNormalizerLegacyTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ public function testArgumentReorderAllNamed(): void
4949
$reorderedArgs = $funcCall->getArgs();
5050
$this->assertCount(2, $reorderedArgs);
5151

52-
$this->assertArrayHasKey(0, $reorderedArgs);
5352
$this->assertNull($reorderedArgs[0]->name, 'named-arg turned into regular numeric arg');
5453
$this->assertInstanceOf(String_::class, $reorderedArgs[0]->value, 'value-arg at the right position');
5554

56-
$this->assertArrayHasKey(1, $reorderedArgs);
5755
$this->assertNull($reorderedArgs[1]->name, 'named-arg turned into regular numeric arg');
5856
$this->assertInstanceOf(LNumber::class, $reorderedArgs[1]->value, 'flags-arg at the right position');
5957
$this->assertSame(0, $reorderedArgs[1]->value->value);
@@ -90,17 +88,14 @@ public function testArgumentReorderAllNamedWithSkipped(): void
9088
$reorderedArgs = $funcCall->getArgs();
9189
$this->assertCount(3, $reorderedArgs);
9290

93-
$this->assertArrayHasKey(0, $reorderedArgs);
9491
$this->assertNull($reorderedArgs[0]->name, 'named-arg turned into regular numeric arg');
9592
$this->assertInstanceOf(String_::class, $reorderedArgs[0]->value, 'value-arg at the right position');
9693

97-
$this->assertArrayHasKey(1, $reorderedArgs);
9894
$this->assertNull($reorderedArgs[1]->name, 'named-arg turned into regular numeric arg');
9995
$this->assertInstanceOf(TypeExpr::class, $reorderedArgs[1]->value, 'flags-arg at the right position');
10096
$this->assertInstanceOf(ConstantIntegerType::class, $reorderedArgs[1]->value->getExprType());
10197
$this->assertSame(0, $reorderedArgs[1]->value->getExprType()->getValue(), 'flags-arg with default value');
10298

103-
$this->assertArrayHasKey(2, $reorderedArgs);
10499
$this->assertNull($reorderedArgs[2]->name, 'named-arg turned into regular numeric arg');
105100
$this->assertInstanceOf(LNumber::class, $reorderedArgs[2]->value, 'depth-arg at the right position');
106101
$this->assertSame(128, $reorderedArgs[2]->value->value);
@@ -153,10 +148,7 @@ public function testLeaveRegularCallAsIs(): void
153148
$reorderedArgs = $funcCall->getArgs();
154149
$this->assertCount(2, $reorderedArgs);
155150

156-
$this->assertArrayHasKey(0, $reorderedArgs);
157151
$this->assertInstanceOf(String_::class, $reorderedArgs[0]->value, 'value-arg at unchanged position');
158-
159-
$this->assertArrayHasKey(1, $reorderedArgs);
160152
$this->assertInstanceOf(LNumber::class, $reorderedArgs[1]->value, 'flags-arg at unchanged position');
161153
$this->assertSame(0, $reorderedArgs[1]->value->value);
162154
}

0 commit comments

Comments
 (0)