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
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Arrays/DeadForeachRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public function testBug8056(): void
$this->analyse([__DIR__ . '/data/bug-8056.php'], []);
}

public function testBug15147(): void
{
$this->analyse([__DIR__ . '/data/bug-15147.php'], []);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public function testBug5655b(): void
$this->analyse([__DIR__ . '/data/bug-5655b.php'], []);
}

public function testBug10783(): void
{
$this->analyse([__DIR__ . '/../Variables/data/bug-10783.php'], []);
}

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

namespace Bug15147Rule;

use ArrayObject;
use function PHPStan\dumpType;
use function PHPStan\Testing\assertType;

class Test
{
/**
* @param ArrayObject<array-key, array<mixed>|mixed> $alias
*/
public function populate(ArrayObject $alias): void
{
if (rand(1, 10) > 5) {
// Append an example array
$alias->append(['item', 13]);
} else {
$alias->append('void');
}
}

public function test(): void
{
$alias = new ArrayObject();
$this->populate($alias);
$alias = $alias->getArrayCopy();

foreach ($alias as $k => $v) {
if (!is_array($v)) {
$alias[$k] = [];
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -1301,4 +1301,9 @@ public function testBug6211(): void
]);
}

public function testBug15147(): void
{
$this->analyse([__DIR__ . '/../Arrays/data/bug-15147.php'], []);
}

}
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1415,4 +1415,9 @@ public function testBug12984(): void
$this->analyse([__DIR__ . '/data/bug-12984.php'], []);
}

public function testBug13325(): void
{
$this->analyse([__DIR__ . '/data/bug-13325.php'], []);
}

}
19 changes: 19 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-13325.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Bug13325;

use Iterator;
use RegexIterator;
use Traversable;

final class Foo
{
/** @return RegexIterator<mixed, mixed, Traversable<mixed, mixed>> */
public function __invoke(Iterator $iterator): RegexIterator
{
return new RegexIterator($iterator, 'string');
}
}

7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Variables/EmptyRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,11 @@ public function testInTrait(): void
]);
}

public function testBug10783(): void
{
$this->treatPhpDocTypesAsCertain = true;

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

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

namespace Bug10783;

use ArrayObject;

class HelloWorld
{
public function sayHello(): bool
{
$a = new ArrayObject([]);
$a[] = 'test';
return empty($a->getArrayCopy());
}
}
Loading