Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes phpstan/phpstan#5316 Closes phpstan/phpstan#5607 Closes phpstan/phpstan#3766 Closes phpstan/phpstan#3858 Closes phpstan/phpstan#3310 Closes phpstan/phpstan#3264 Closes phpstan/phpstan#2806 Closes phpstan/phpstan#5328 Closes phpstan/phpstan#3044
- Loading branch information
1 parent
12b6bf7
commit ebfe7cf
Showing
14 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Bug2806; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use function PHPStan\Testing\assertVariableCertainty; | ||
|
||
function (): void { | ||
for (;;) { | ||
$a = "hello"; | ||
break; | ||
} | ||
|
||
assertVariableCertainty(TrinaryLogic::createYes(), $a); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Bug3044; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class HelloWorld | ||
{ | ||
/** | ||
* @return array<int, array<int, float>> | ||
*/ | ||
private function getIntArrayFloatArray(): array | ||
{ | ||
return [ | ||
0 => [1.1, 2.2, 3.3], | ||
1 => [1.1, 2.2, 3.3], | ||
2 => [1.1, 2.2, 3.3], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<int, array<int, float>> | ||
*/ | ||
public function invalidType(): void | ||
{ | ||
$X = $this->getIntArrayFloatArray(); | ||
$L = $this->getIntArrayFloatArray(); | ||
|
||
$n = 3; | ||
$m = 3; | ||
|
||
for ($k = 0; $k < $m; ++$k) { | ||
for ($j = 0; $j < $n; ++$j) { | ||
for ($i = 0; $i < $k; ++$i) { | ||
$X[$k][$j] -= $X[$i][$j] * $L[$k][$i]; | ||
} | ||
} | ||
} | ||
|
||
assertType('array<int, array<int, float>>', $X); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Bug3858; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use function PHPStan\Testing\assertVariableCertainty; | ||
|
||
class BinarySearch | ||
{ | ||
/** | ||
* @param mixed[] $items | ||
*/ | ||
public function __invoke(array $items): void | ||
{ | ||
for ($start = 0, $end = count($items); | ||
$i = $start + (int) (($end - $start) / 2), $i < $end; | ||
) { | ||
// do something here, then break at some point | ||
break; | ||
} | ||
|
||
// $i is always defined here, even with an empty array | ||
assertVariableCertainty(TrinaryLogic::createYes(), $i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Bug5316; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function (): void { | ||
$map = [ | ||
1 => 'foo', | ||
2 => 'foo', | ||
3 => 'bar', | ||
]; | ||
$names = ['foo', 'bar', 'baz']; | ||
$array = ['foo' => [], 'bar' => [], 'baz' => []]; | ||
|
||
foreach ($map as $value => $name) { | ||
$array[$name][] = $value; | ||
} | ||
|
||
|
||
foreach ($array as $name => $elements) { | ||
assertType('bool', count($elements) > 0); | ||
assertType('array<int, 1|2|3>', $elements); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Bug5328; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
function produceIntOrNull(): ?int | ||
{ | ||
return rand(0, 2) === 0 ? null : 0; | ||
} | ||
|
||
function doBar() | ||
{ | ||
$int = $this->produceIntOrNull(); | ||
for ($i = 0; $i < 5 && !is_int($int) ; $i++) { | ||
$int = $this->produceIntOrNull(); | ||
} | ||
|
||
assertType('int|null', $int); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Bug3264; | ||
|
||
function (): void { | ||
$totalShops = 40; | ||
$predefinedShops = 10; | ||
|
||
for ($i = 0; $i < $predefinedShops; $i++) | ||
{ | ||
echo "Do something $i...\n"; | ||
} | ||
for (;$i < $totalShops; $i++) | ||
{ | ||
echo "Do something else $i...\n"; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Bug3310; | ||
|
||
function explain(int $bitField): void | ||
{ | ||
for ($i = 0; $i < 5; ++$i) { | ||
} | ||
for (; $i < 15; ++$i) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Bug3766; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
function get_foo(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function doFoo(): void | ||
{ | ||
$foo = $this->get_foo(); | ||
for ($i = 0; $i < \count($foo); $i++) { | ||
if (\array_key_exists($i + 1, $foo) | ||
&& \array_key_exists($i + 2, $foo) | ||
) { | ||
echo $i; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Bug5607; | ||
|
||
class A {} | ||
|
||
class Cl | ||
{ | ||
/** @var A|null */ | ||
public $u = [A::class, 'ui' => 'basic segment']; | ||
|
||
/** | ||
* @param array<int|string, class-string|string> $x | ||
*/ | ||
public function mm($x): void | ||
{ | ||
throw new \Exception(); | ||
} | ||
} |