-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TypeSpecifier - understand Equal operator for the same types on both …
…sides
- Loading branch information
1 parent
cbb7963
commit e40eff0
Showing
5 changed files
with
87 additions
and
38 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,68 @@ | ||
<?php | ||
|
||
namespace TypeSpecifierEqual; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo(string $s): void | ||
{ | ||
assertType("string", $s); | ||
if ($s == 'one') { | ||
assertType("'one'", $s); | ||
} else { | ||
assertType("string", $s); | ||
} | ||
assertType("string", $s); | ||
} | ||
|
||
/** @param 'one'|'two' $s */ | ||
public function doBar(string $s): void | ||
{ | ||
assertType("'one'|'two'", $s); | ||
if ($s == 'one') { | ||
assertType("'one'", $s); | ||
} else { | ||
assertType("'two'", $s); | ||
} | ||
assertType("'one'|'two'", $s); | ||
} | ||
|
||
/** @param int<1, 3>|int<8, 13> $i */ | ||
public function doBaz(int $i): void | ||
{ | ||
assertType('int<1, 3>|int<8, 13>', $i); | ||
if ($i == 3) { | ||
assertType('3', $i); | ||
} else { | ||
assertType('int<1, 2>|int<8, 13>', $i); | ||
} | ||
assertType('int<1, 3>|int<8, 13>', $i); | ||
} | ||
|
||
public function doLorem(float $f): void | ||
{ | ||
assertType('float', $f); | ||
if ($f == 3.5) { | ||
assertType('3.5', $f); | ||
} else { | ||
assertType('float', $f); | ||
} | ||
|
||
assertType('float', $f); | ||
} | ||
|
||
public function doIpsum(array $a): void | ||
{ | ||
assertType('array', $a); | ||
if ($a == []) { | ||
assertType('array{}', $a); | ||
} else { | ||
assertType('non-empty-array', $a); | ||
} | ||
assertType('array', $a); | ||
} | ||
|
||
} |