Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,13 @@ public function testBug4532(): void
]);
}

public function testBug12115(): void
{
$this->reportPossiblyNonexistentGeneralArrayOffset = true;

$this->analyse([__DIR__ . '/data/bug-12115.php'], []);
}

public function testBug10492(): void
{
$this->analyse([__DIR__ . '/data/bug-10492.php'], [
Expand All @@ -1000,6 +1007,20 @@ public function testBug10492(): void
]);
}

public function testBug12574a(): void
{
$this->reportPossiblyNonexistentGeneralArrayOffset = true;

$this->analyse([__DIR__ . '/data/bug-12574a.php'], []);
}

public function testBug12574b(): void
{
$this->reportPossiblyNonexistentGeneralArrayOffset = true;

$this->analyse([__DIR__ . '/data/bug-12574b.php'], []);
}

public function testBug12926(): void
{
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
Expand Down
27 changes: 27 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/bug-12115.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);

namespace Bug12115;

class HelloWorld
{
public function testMe(): void
{
$indexes = [1, 2, 3, 4, 5];
$loopArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$counterArray = [];


foreach ($indexes as $index) {
// Check if the index is not set in the counter array
if (!isset($counterArray[$index])) {
$counterArray[$index] = ['string_index_1' => 0, 'string_index_2' => 0];
}

foreach ($loopArray as $loop) {
$stringIndex = $loop % 2 === 0 ? 'string_index_1' : 'string_index_2';
$counterArray[$index][$stringIndex]++;
}
}

}
}
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/bug-12574a.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace Bug12574a;

function doFoo() {
$i = 10;
$x = [];
while ($i-- > 0) {
$r = rand(1, 10);
if (!isset($x[$r])) {
$x[$r] = 1;
}
var_dump($x[$r]);
}
}
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/bug-12574b.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types = 1);

namespace Bug12574b;

class HelloWorld
{
public function sayHello2(string $a): void
{
$b = [];

$b[$a] = 'abc';

echo $b[$a];
}
}
Loading