-
Notifications
You must be signed in to change notification settings - Fork 473
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
990ba51
commit 31fcad6
Showing
12 changed files
with
410 additions
and
11 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,27 @@ | ||
<?php | ||
|
||
namespace Bug1283; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use function PHPStan\Analyser\assertType; | ||
use function PHPStan\Analyser\assertVariableCertainty; | ||
|
||
function (array $levels): void { | ||
foreach ($levels as $level) { | ||
switch ($level) { | ||
case 'all': | ||
continue 2; | ||
case 'some': | ||
$allowedElements = array(1, 3); | ||
break; | ||
case 'one': | ||
$allowedElements = array(1); | ||
break; | ||
default: | ||
throw new \UnexpectedValueException(sprintf('Unsupported level `%s`', $level)); | ||
} | ||
|
||
assertType('array(0 => 1, ?1 => 3)', $allowedElements); | ||
assertVariableCertainty(TrinaryLogic::createYes(), $allowedElements); | ||
} | ||
}; |
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,106 @@ | ||
<?php | ||
|
||
namespace Bug1945; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use function PHPStan\Analyser\assertType; | ||
use function PHPStan\Analyser\assertVariableCertainty; | ||
|
||
function (): void { | ||
foreach (["a", "b", "c"] as $letter) { | ||
switch ($letter) { | ||
case "b": | ||
$foo = 1; | ||
break; | ||
case "c": | ||
$foo = 2; | ||
break; | ||
default: | ||
continue 2; | ||
} | ||
|
||
assertType('1|2', $foo); | ||
assertVariableCertainty(TrinaryLogic::createYes(), $foo); | ||
} | ||
}; | ||
|
||
function (): void { | ||
foreach (["a", "b", "c"] as $letter) { | ||
switch ($letter) { | ||
case "a": | ||
if (rand(0, 10) === 1) { | ||
continue 2; | ||
} | ||
$foo = 1; | ||
break; | ||
case "b": | ||
if (rand(0, 10) === 1) { | ||
continue 2; | ||
} | ||
$foo = 2; | ||
break; | ||
default: | ||
continue 2; | ||
} | ||
|
||
assertType('1|2', $foo); | ||
assertVariableCertainty(TrinaryLogic::createYes(), $foo); | ||
} | ||
}; | ||
|
||
function (array $docs): void { | ||
foreach ($docs as $doc) { | ||
switch (true) { | ||
case 'bar': | ||
continue 2; | ||
break; | ||
default: | ||
$foo = $doc; | ||
break; | ||
} | ||
|
||
assertVariableCertainty(TrinaryLogic::createYes(), $foo); | ||
if (!$foo) { | ||
return; | ||
} | ||
} | ||
}; | ||
|
||
function (array $docs): void { | ||
foreach ($docs as $doc) { | ||
switch (true) { | ||
case 'bar': | ||
continue 2; | ||
default: | ||
$foo = $doc; | ||
break; | ||
} | ||
|
||
assertVariableCertainty(TrinaryLogic::createYes(), $foo); | ||
if (!$foo) { | ||
return; | ||
} | ||
} | ||
}; | ||
|
||
function (array $items): string { | ||
foreach ($items as $item) { | ||
switch ($item) { | ||
case 1: | ||
$string = 'a'; | ||
break; | ||
case 2: | ||
$string = 'b'; | ||
break; | ||
default: | ||
continue 2; | ||
} | ||
|
||
assertType('\'a\'|\'b\'', $string); | ||
assertVariableCertainty(TrinaryLogic::createYes(), $string); | ||
|
||
return 'result: ' . $string; | ||
} | ||
|
||
return 'ok'; | ||
}; |
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 declare(strict_types=1); | ||
|
||
namespace Bug2003; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use function PHPStan\Analyser\assertType; | ||
use function PHPStan\Analyser\assertVariableCertainty; | ||
|
||
function (array $list): void { | ||
foreach ($list as $part) { | ||
switch (true) { | ||
case isset($list['magic']): | ||
$key = 'to-success'; | ||
break; | ||
|
||
default: | ||
continue 2; | ||
} | ||
|
||
assertType('\'to-success\'', $key); | ||
assertVariableCertainty(TrinaryLogic::createYes(), $key); | ||
|
||
echo $key; | ||
} | ||
}; |
Oops, something went wrong.