-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e8b69d
commit 66b09e2
Showing
4 changed files
with
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Bug10088; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use stdClass; | ||
use function PHPStan\Testing\assertVariableCertainty; | ||
|
||
class Foo | ||
{ | ||
|
||
function doFoo(): void { | ||
if (rand(0,1)) { | ||
$shortcut_id = 1; | ||
assertVariableCertainty(TrinaryLogic::createYes(), $shortcut_id); | ||
} | ||
|
||
assertVariableCertainty(TrinaryLogic::createMaybe(), $shortcut_id); | ||
|
||
$link_mode = isset($shortcut_id) ? "remove" : "add"; | ||
if ($link_mode === "add") { | ||
assertVariableCertainty(TrinaryLogic::createNo(), $shortcut_id); | ||
} else { | ||
assertVariableCertainty(TrinaryLogic::createYes(), $shortcut_id); | ||
} | ||
|
||
assertVariableCertainty(TrinaryLogic::createMaybe(), $shortcut_id); | ||
} | ||
|
||
/** | ||
* @param mixed[] $period | ||
*/ | ||
public function testCarbon(array $period): void | ||
{ | ||
foreach ($period as $date) { | ||
break; | ||
} | ||
|
||
assertVariableCertainty(TrinaryLogic::createMaybe(), $date); | ||
$this->assertInstanceOfStdClass($date ?? null); | ||
assertVariableCertainty(TrinaryLogic::createYes(), $date); | ||
} | ||
|
||
/** | ||
* @param mixed $m | ||
* @phpstan-assert stdClass $m | ||
*/ | ||
private function assertInstanceOfStdClass($m): void | ||
{ | ||
if (!$m instanceof stdClass) { | ||
throw new \Exception(); | ||
} | ||
} | ||
|
||
/** | ||
* @param mixed[] $period | ||
*/ | ||
public function testCarbon2(array $period): void | ||
{ | ||
foreach ($period as $date) { | ||
break; | ||
} | ||
|
||
assertVariableCertainty(TrinaryLogic::createMaybe(), $date); | ||
assert(($date ?? null) instanceof stdClass); | ||
assertVariableCertainty(TrinaryLogic::createYes(), $date); | ||
} | ||
|
||
} |
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