Skip to content

Commit 884ab57

Browse files
committed
fix
1 parent 68266e7 commit 884ab57

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,11 @@ public function specifyTypesInCondition(
694694
&& in_array($expr->expr->name->toLowerString(), ['array_rand'], true)
695695
&& count($expr->expr->getArgs()) >= 1
696696
) {
697+
$numArg = null;
697698
$arrayArg = $expr->expr->getArgs()[0]->value;
698-
$numArg = $expr->expr->getArgs()[1]->value;
699+
if (count($expr->expr->getArgs()) > 1) {
700+
$numArg = $expr->expr->getArgs()[1]->value;
701+
}
699702
$one = new ConstantIntegerType(1);
700703
$arrayType = $scope->getType($arrayArg);
701704

src/Rules/Arrays/NonexistentOffsetInArrayDimFetchRule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,14 @@ public function processNode(Node $node, Scope $scope): array
136136
&& $node->dim->name->toLowerString() === 'array_rand'
137137
&& count($node->dim->getArgs()) >= 1
138138
) {
139+
$numArg = null;
139140
$arrayArg = $node->dim->getArgs()[0]->value;
140-
$numArg = $node->dim->getArgs()[1]->value;
141-
141+
if (count($node->dim->getArgs()) > 1) {
142+
$numArg = $node->dim->getArgs()[1]->value;
143+
}
142144
$one = new ConstantIntegerType(1);
143145
$arrayType = $scope->getType($arrayArg);
146+
144147
if (
145148
$arrayArg instanceof Node\Expr\Variable
146149
&& $node->var instanceof Node\Expr\Variable

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,16 +949,15 @@ public function testBug12981(): void
949949
$this->analyse([__DIR__ . '/data/bug-12981.php'], [
950950
[
951951
'Offset array<int, int|string> might not exist on non-empty-array<bool|float|int|string>.',
952-
31
952+
31,
953953
],
954954
[
955955
'Offset array<int, int|string> might not exist on non-empty-array<bool|float|int|string>.',
956-
33
956+
33,
957957
],
958958
]);
959959
}
960960

961-
962961
public function testBugObject(): void
963962
{
964963
$this->analyse([__DIR__ . '/data/bug-object.php'], [

0 commit comments

Comments
 (0)