-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix in_array() for arrays with union value type
- Loading branch information
1 parent
b7b6655
commit 4321374
Showing
4 changed files
with
123 additions
and
16 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
80 changes: 80 additions & 0 deletions
80
tests/PHPStan/Rules/Comparison/data/in-array-date-format.php
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,80 @@ | ||
<?php | ||
|
||
namespace InArrayDateFormat; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo(array $a, \DateTimeImmutable $dt) | ||
{ | ||
$result = []; | ||
foreach ($a as $k => $v) { | ||
$result[$k] = $dt->format('d'); | ||
} | ||
|
||
$d = new \DateTimeImmutable(); | ||
if (in_array($d->format('d'), $result, true)) { | ||
|
||
} | ||
|
||
if (in_array('01', $result, true)) { | ||
|
||
} | ||
|
||
$day = $d->format('d'); | ||
if (rand(0, 1)) { | ||
$day = '32'; | ||
} | ||
|
||
if (in_array($day, $result, true)) { | ||
|
||
} | ||
} | ||
|
||
/** | ||
* @param non-empty-array<int, 'a'> $a | ||
*/ | ||
public function doBar(array $a, int $i) | ||
{ | ||
if (in_array('a', $a, true)) { | ||
|
||
} | ||
|
||
if (in_array('b', $a, true)) { | ||
|
||
} | ||
|
||
if (in_array($i, [], true)) { | ||
|
||
} | ||
} | ||
|
||
/** | ||
* @param array<int, string> $a | ||
*/ | ||
public function doBaz(array $a, int $i, string $s) | ||
{ | ||
if (in_array($s, $a, true)) { | ||
|
||
} | ||
|
||
if (in_array($i, $a, true)) { | ||
|
||
} | ||
} | ||
|
||
/** | ||
* @param non-empty-array<int, 'a'|'b'> $a | ||
*/ | ||
public function doLorem(array $a, int $i) | ||
{ | ||
if (in_array('a', $a, true)) { | ||
|
||
} | ||
|
||
if (in_array('b', $a, true)) { | ||
|
||
} | ||
} | ||
|
||
} |