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#5893 Closes phpstan/phpstan#6070 Closes phpstan/phpstan#5869 Closes phpstan/phpstan#6212 Closes phpstan/phpstan#6262 Closes phpstan/phpstan#6266 Closes phpstan/phpstan#6023 Closes phpstan/phpstan#6108 Closes phpstan/phpstan#6020 Closes phpstan/phpstan#1746 Closes phpstan/phpstan#1516 Closes phpstan/phpstan#6174 Closes phpstan/phpstan#6112 Closes phpstan/phpstan#5749 Closes phpstan/phpstan#5969 Closes phpstan/phpstan#5295 Closes phpstan/phpstan#5675 Closes phpstan/phpstan#5369 Closes phpstan/phpstan#6699 Closes phpstan/phpstan#6505
- Loading branch information
1 parent
0dd3d0c
commit 86fd620
Showing
33 changed files
with
918 additions
and
2 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
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,37 @@ | ||
<?php | ||
|
||
namespace Bug1516; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class FlowNodeManager | ||
{ | ||
public function _test() : void | ||
{ | ||
$out = []; | ||
$a = | ||
[ | ||
'foof' => 'barr', | ||
'ftt' => [] | ||
]; | ||
|
||
foreach ($a as $k => $b) { | ||
$str = 'toto'; | ||
assertType('\'toto\'|array{}', $out[$k]); | ||
|
||
if (is_array($b)) { | ||
// $out[$k] is redefined there before the array_merge | ||
assertType('\'toto\'|array{}', $out[$k]); | ||
$out[$k] = []; | ||
assertType('array{}', $out[$k]); | ||
$out[$k] = array_merge($out[$k], []); | ||
assertType('array{}', $out[$k]); | ||
|
||
} else { | ||
// I think phpstan takes this definition as a string and takes no account of the foreach | ||
$out[$k] = $str; | ||
assertType('\'toto\'', $out[$k]); | ||
} | ||
} | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
namespace Bug5675; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Bar {} | ||
|
||
/** | ||
* @template T | ||
*/ | ||
class Hello | ||
{ | ||
/** | ||
* @param (\Closure(Hello<T>): void)|array<array-key, int>|Bar $column | ||
*/ | ||
public function foo($column): void | ||
{ | ||
// ... | ||
} | ||
|
||
public function bar() | ||
{ | ||
/** @var Hello<string> */ | ||
$a = new Hello; | ||
|
||
$a->foo(function (Hello $h) : void { | ||
assertType('Bug5675\Hello<string>', $h); | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* @template T | ||
*/ | ||
class Hello2 | ||
{ | ||
/** | ||
* @param (\Closure(static<T>): void)|array<array-key, int>|Bar $column | ||
*/ | ||
public function foo($column): void | ||
{ | ||
// ... | ||
} | ||
|
||
public function bar() | ||
{ | ||
/** @var Hello2<string> */ | ||
$a = new Hello2; | ||
|
||
$a->foo(function (Hello2 $h) : void { | ||
\PHPStan\Testing\assertType('Bug5675\Hello2<string>', $h); | ||
}); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Bug6070; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class HelloWorld | ||
{ | ||
/** | ||
* @return non-empty-array | ||
*/ | ||
public function getNonEmptyArray(): array { | ||
$nonEmptyArray = [rand()]; | ||
|
||
for ($i = 0; $i < 2; $i++) { | ||
$nonEmptyArray[] = 1; | ||
} | ||
|
||
assertType('non-empty-array<int, int<0, max>>', $nonEmptyArray); | ||
|
||
return $nonEmptyArray; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Bug6108; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
|
||
/** | ||
* @return array{ | ||
* a: int[], | ||
* b: int[], | ||
* c: bool | ||
* } | ||
*/ | ||
function doFoo(): array { | ||
return [ | ||
'a' => [1, 2], | ||
'b' => [3, 4, 5], | ||
'c' => true, | ||
]; | ||
} | ||
|
||
function doBar() | ||
{ | ||
$x = $this->doFoo(); | ||
$test = ['a' => true, 'b' => false]; | ||
foreach ($test as $key => $value) { | ||
if ($value) { | ||
assertType('\'a\'|\'b\'', $key); // could be just 'a' | ||
assertType('array<int>', $x[$key]); | ||
} | ||
} | ||
} | ||
|
||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Bug6174; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class HelloWorld | ||
{ | ||
private const DEFAULT_VALUE = 10; | ||
|
||
public function __construct() | ||
{ | ||
$tempValue = (int) ($this->returnValue() ?? self::DEFAULT_VALUE); | ||
assertType('-1|int<1, max>', $tempValue === -1 || $tempValue > 0 ? $tempValue : self::DEFAULT_VALUE); | ||
} | ||
|
||
public function returnValue(): ?string | ||
{ | ||
return null; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Bug6212; | ||
|
||
class HelloWorld | ||
{ | ||
public function sayHello(\DateTimeImmutable $date): void | ||
{ | ||
for ($i = 1; $i <= 1e18; $i *= 10) { | ||
|
||
} | ||
} | ||
} |
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,139 @@ | ||
<?php // lint >= 8.0 | ||
|
||
namespace Bug6505; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
/** @template T */ | ||
interface Type | ||
{ | ||
/** | ||
* @param T $val | ||
* @return T | ||
*/ | ||
public function validate($val); | ||
} | ||
|
||
/** | ||
* @template T | ||
* @implements Type<class-string<T>> | ||
*/ | ||
final class ClassStringType implements Type | ||
{ | ||
/** @param class-string<T> $classString */ | ||
public function __construct(public string $classString) | ||
{ | ||
} | ||
|
||
public function validate($val) { | ||
return $val; | ||
} | ||
} | ||
|
||
/** | ||
* @implements Type<class-string<\stdClass>> | ||
*/ | ||
final class StdClassType implements Type | ||
{ | ||
public function validate($val) { | ||
return $val; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @template T | ||
* @implements Type<T[]> | ||
*/ | ||
final class TypeCollection implements Type | ||
{ | ||
/** @param Type<T> $type */ | ||
public function __construct(public Type $type) | ||
{ | ||
} | ||
public function validate($val) { | ||
return $val; | ||
} | ||
} | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo() | ||
{ | ||
$c = new TypeCollection(new ClassStringType(\stdClass::class)); | ||
assertType('c', $c->validate([\stdClass::class])); | ||
$c2 = new TypeCollection(new StdClassType()); | ||
assertType('c', $c2->validate([\stdClass::class])); | ||
} | ||
|
||
/** | ||
* @template T | ||
* @param T $t | ||
* @return T | ||
*/ | ||
function unbounded($t) { | ||
return $t; | ||
} | ||
|
||
/** | ||
* @template T of string | ||
* @param T $t | ||
* @return T | ||
*/ | ||
function bounded1($t) { | ||
return $t; | ||
} | ||
|
||
/** | ||
* @template T of object|class-string | ||
* @param T $t | ||
* @return T | ||
*/ | ||
function bounded2($t) { | ||
return $t; | ||
} | ||
|
||
/** @param class-string<\stdClass> $p */ | ||
function test($p): void { | ||
assertType('c', $this->unbounded($p)); | ||
assertType('c', $this->bounded1($p)); | ||
assertType('c', $this->bounded2($p)); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @template TKey of array-key | ||
* @template TValue | ||
*/ | ||
class Collection | ||
{ | ||
/** | ||
* @var array<TKey, TValue> | ||
*/ | ||
protected array $items; | ||
|
||
/** | ||
* Create a new collection. | ||
* | ||
* @param array<TKey, TValue>|null $items | ||
* @return void | ||
*/ | ||
public function __construct(?array $items = []) | ||
{ | ||
$this->items = $items ?? []; | ||
} | ||
} | ||
|
||
class Example | ||
{ | ||
/** @var array<string, list<class-string>> */ | ||
private array $factories = []; | ||
|
||
public function getFactories(): void | ||
{ | ||
assertType('c', new Collection($this->factories)); | ||
} | ||
} | ||
|
Oops, something went wrong.