Skip to content

Commit 6b43b8d

Browse files
phpstan-botclaude
authored andcommitted
Add test coverage for array_rand and count()-1 property access patterns
Addresses review feedback: the ExprPrinter changes for array_rand and count()-1 special cases were not covered by tests. Adds test cases for property access with array_rand() and count()-1 on non-empty arrays. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 80c9526 commit 6b43b8d

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

tests/PHPStan/Rules/Arrays/data/bug-14390.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,43 @@ public function arrayKeyLast(
5252
echo $sample->fields[array_key_last($sample->fields)];
5353
}
5454
}
55+
56+
public function arrayRand(
57+
Sample $sample,
58+
): void {
59+
if ($sample->fields !== []) {
60+
echo $sample->fields[array_rand($sample->fields)];
61+
}
62+
}
63+
64+
/**
65+
* @param non-empty-list<string> $list
66+
*/
67+
public function countMinus1(
68+
array $list,
69+
): void {
70+
echo $list[count($list) - 1];
71+
}
72+
}
73+
74+
readonly class SampleList
75+
{
76+
/**
77+
* @param list<string> $items
78+
*/
79+
public function __construct(
80+
public array $items = [],
81+
) {
82+
}
83+
}
84+
85+
class Bar
86+
{
87+
public function countMinus1Property(
88+
SampleList $sample,
89+
): void {
90+
if ($sample->items !== []) {
91+
echo $sample->items[count($sample->items) - 1];
92+
}
93+
}
5594
}

0 commit comments

Comments
 (0)