Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Regression tests for remembering function values
Closes phpstan/phpstan#4588 Closes phpstan/phpstan#4091 Closes phpstan/phpstan#3382 Closes phpstan/phpstan#4177 Closes phpstan/phpstan#2288 Closes phpstan/phpstan#1157
- Loading branch information
1 parent
bdc09a6
commit ebb5520
Showing
7 changed files
with
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Bug1157; | ||
|
||
use DateTimeInterface; | ||
use function PHPStan\Analyser\assertType; | ||
|
||
class HelloWorld | ||
{ | ||
private $a; | ||
|
||
/** | ||
* @return \DateTimeInterface|null | ||
*/ | ||
public function getA() | ||
{ | ||
return $this->a; | ||
} | ||
} | ||
|
||
function (HelloWorld $class): void { | ||
if ($class->getA()) { | ||
assertType(DateTimeInterface::class, $class->getA()); | ||
} | ||
}; |
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 Bug2288; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class One | ||
{ | ||
public function test() :?\DateTimeImmutable | ||
{ | ||
return rand(0,1) === 1 ? new \DateTimeImmutable(): null; | ||
} | ||
} | ||
|
||
class Two | ||
{ | ||
public function test(): void | ||
{ | ||
$test = new One(); | ||
if ($test->test()) { | ||
assertType(\DateTimeImmutable::class, $test->test()); | ||
} | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace Bug3382; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
if (ini_get('auto_prepend_file')) { | ||
assertType('string', ini_get('auto_prepend_file')); | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Bug4091; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
if (mt_rand(0,10) > 3) { | ||
echo 'Fizz'; | ||
assertType('int', mt_rand(0,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,32 @@ | ||
<?php | ||
|
||
namespace Bug4177; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class Dto | ||
{ | ||
private int $unixtimestamp = 12345678; | ||
|
||
public function getPeriodFrom(): ?int | ||
{ | ||
return rand(0,1) ? $this->unixtimestamp : null; | ||
} | ||
|
||
public function getPeriodTo(): ?int | ||
{ | ||
return rand(0,1) ? $this->unixtimestamp : null; | ||
} | ||
} | ||
|
||
function (Dto $request): void { | ||
if ($request->getPeriodFrom() || $request->getPeriodTo()) { | ||
if ($request->getPeriodFrom()) { | ||
assertType('int<min, -1>|int<1, max>', $request->getPeriodFrom()); | ||
} | ||
|
||
if ($request->getPeriodTo() !== null) { | ||
assertType('int', $request->getPeriodTo()); | ||
} | ||
} | ||
}; |
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,26 @@ | ||
<?php | ||
|
||
namespace Bug4588; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class c { | ||
private $b; | ||
public function __construct(?b $b ) { | ||
$this->b = $b; | ||
} | ||
public function getB(): ?b { | ||
|
||
return $this->b; | ||
} | ||
} | ||
|
||
class b{ | ||
public function callB():bool {return true;} | ||
} | ||
|
||
function (c $c): void { | ||
if ($c->getB()) { | ||
assertType(b::class, $c->getB()); | ||
} | ||
}; |