-
Notifications
You must be signed in to change notification settings - Fork 461
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#2231 Closes phpstan/phpstan#3558 Closes phpstan/phpstan#4671 Closes phpstan/phpstan#3351 Closes phpstan/phpstan#4648 Closes phpstan/phpstan#4213 Closes phpstan/phpstan#3523 Closes phpstan/phpstan#3120 Closes phpstan/phpstan#1652 Closes phpstan/phpstan#1843
- Loading branch information
1 parent
adacab8
commit d01431c
Showing
20 changed files
with
427 additions
and
31 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
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,24 @@ | ||
<?php | ||
|
||
namespace Bug1843; | ||
|
||
class HelloWorld | ||
{ | ||
const W = '1'; | ||
|
||
const P = [ | ||
self::W => [ | ||
'A' => '2', | ||
'B' => '3', | ||
'C' => '4', | ||
'D' => '5', | ||
'E' => '6', | ||
'F' => '7', | ||
], | ||
]; | ||
|
||
public function sayHello(): void | ||
{ | ||
echo self::P[self::W]['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,39 @@ | ||
<?php | ||
|
||
namespace Bug2231; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo(?Foo $x): void | ||
{ | ||
if ($x !== null && !($x instanceof static)) { | ||
throw new \TypeError('custom error'); | ||
} | ||
|
||
assertType('static(Bug2231\Foo)|null', $x); | ||
} | ||
|
||
public function doBar(?Foo $x): void | ||
{ | ||
if ($x !== null && !($x instanceof self)) { | ||
throw new \TypeError('custom error'); | ||
} | ||
|
||
assertType('Bug2231\Foo|null', $x); | ||
} | ||
|
||
public function doBaz($x): void | ||
{ | ||
if ($x instanceof self) { | ||
assertType('Bug2231\Foo', $x); | ||
} | ||
|
||
if ($x instanceof static) { | ||
assertType('static(Bug2231\Foo)', $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,30 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class HelloWorld | ||
{ | ||
public function sayHello(): void | ||
{ | ||
$a = ['a', 'b', 'c']; | ||
$b = [1, 2, 3]; | ||
|
||
$c = $this->combine($a, $b); | ||
assertType('array<string, int>|false', $c); | ||
|
||
assertType('array(\'a\' => 1, \'b\' => 2, \'c\' => 3)', array_combine($a, $b)); | ||
} | ||
|
||
/** | ||
* @template TKey | ||
* @template TValue | ||
* @param array<TKey> $keys | ||
* @param array<TValue> $values | ||
* | ||
* @return array<TKey, TValue>|false | ||
*/ | ||
private function combine(array $keys, array $values) | ||
{ | ||
return array_combine($keys, $values); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Bug3558; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
function (): void { | ||
$idGroups = []; | ||
|
||
if(time() > 3){ | ||
$idGroups[] = [1,2]; | ||
$idGroups[] = [1,2]; | ||
$idGroups[] = [1,2]; | ||
} | ||
|
||
if(count($idGroups) > 0){ | ||
assertType('array(array(1, 2), array(1, 2), array(1, 2))', $idGroups); | ||
} | ||
}; | ||
|
||
function (): void { | ||
$idGroups = [1]; | ||
|
||
if(time() > 3){ | ||
$idGroups[] = [1,2]; | ||
$idGroups[] = [1,2]; | ||
$idGroups[] = [1,2]; | ||
} | ||
|
||
if(count($idGroups) > 1){ | ||
assertType('array(0 => 1, ?1 => array(1, 2), ?2 => array(1, 2), ?3 => array(1, 2))', $idGroups); | ||
} | ||
}; |
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,64 @@ | ||
<?php | ||
|
||
namespace Bug4213; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
abstract class BaseEnum | ||
{ | ||
private string $value; | ||
|
||
final private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
/** | ||
* @return static | ||
*/ | ||
public static function get(string $value): self { | ||
return new static($value); | ||
} | ||
} | ||
|
||
final class Enum extends BaseEnum | ||
{ | ||
} | ||
|
||
final class Entity { | ||
public function setEnums(Enum ...$enums): void { | ||
} | ||
/** | ||
* @param Enum[] $enums | ||
*/ | ||
public function setEnumsWithoutSplat(array $enums): void { | ||
} | ||
} | ||
|
||
function (): void { | ||
assertType('Bug4213\Enum', Enum::get('test')); | ||
assertType('array(Bug4213\Enum)', array_map([Enum::class, 'get'], ['test'])); | ||
}; | ||
|
||
|
||
class Foo | ||
{ | ||
/** | ||
* @return static | ||
*/ | ||
public static function create() : Foo | ||
{ | ||
return new static(); | ||
} | ||
} | ||
|
||
|
||
class Bar extends Foo | ||
{ | ||
} | ||
|
||
function (): void { | ||
$cbFoo = [Foo::class, 'create']; | ||
$cbBar = [Bar::class, 'create']; | ||
assertType('Bug4213\Foo', $cbFoo()); | ||
assertType('Bug4213\Bar', $cbBar()); | ||
}; |
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
<?php | ||
|
||
namespace Bug3120; | ||
|
||
class A { | ||
/** @return static */ | ||
public static function getInstance() { | ||
$class = static::class; | ||
return new $class(); | ||
} | ||
} | ||
|
||
final class AChild extends A { | ||
public static function getInstance() { | ||
return new AChild(); | ||
} | ||
} | ||
|
||
class Test | ||
{ | ||
final public function __construct() | ||
{} | ||
|
||
/** | ||
* @return static | ||
*/ | ||
public function foo(): self | ||
{ | ||
return self::bar(new static()); | ||
} | ||
|
||
/** | ||
* @phpstan-template T of Test | ||
* @phpstan-param T $object | ||
* @phpstan-return T | ||
*/ | ||
public function bar(Test $object): self | ||
{ | ||
return $object; | ||
} | ||
|
||
} |
Oops, something went wrong.