Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix various things around isset() and ArrayDimFetch
* add regression tests for phpstan/phpstan#7000 * specify expression even it doesn't change types * skip UnionType offset because it's hard to solve in some cases * skip specified expressions in NonexistentOffsetInArrayDimFetchRule * fix tests * add regression tests * fix useless call in foreach * fix issue-7190 too * Avoided duplicate namespace Co-authored-by: Ondřej Mirtes <ondrej@mirtes.cz>
- Loading branch information
1 parent
dbbced9
commit 21164d6
Showing
10 changed files
with
130 additions
and
18 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,20 @@ | ||
<?php | ||
|
||
namespace Bug7000Analyser; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
public function doBar(): void | ||
{ | ||
/** @var array{require?: array<string, string>, require-dev?: array<string, string>} $composer */ | ||
$composer = array(); | ||
foreach (array('require', 'require-dev') as $linkType) { | ||
if (isset($composer[$linkType])) { | ||
assertType('array{require?: array<string, string>, require-dev?: array<string, string>}', $composer); | ||
foreach ($composer[$linkType] as $x) {} | ||
} | ||
} | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Bug6508; | ||
|
||
class Foo | ||
{ | ||
/** | ||
* @param array{ | ||
* type1?: array{bool: bool}, | ||
* type2?: array{bool: bool} | ||
* } $types | ||
* @param 'type1'|'type2' $type | ||
*/ | ||
function test(array $types, string $type): void | ||
{ | ||
if (isset($types[$type]) && $types[$type]['bool']) {} | ||
} | ||
} |
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,20 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug7000; | ||
|
||
class Foo | ||
{ | ||
public function doBar(): void | ||
{ | ||
/** @var array{require?: array<string, string>, require-dev?: array<string, string>} $composer */ | ||
$composer = array(); | ||
/** @var 'require'|'require-dev' $foo */ | ||
$foo = ''; | ||
foreach (array('require', 'require-dev') as $linkType) { | ||
if (isset($composer[$linkType])) { | ||
foreach ($composer[$linkType] as $x) {} // should not report error | ||
foreach ($composer[$foo] as $x) {} // should report error. It can be $linkType = 'require', $foo = 'require-dev' | ||
} | ||
} | ||
} | ||
} |
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,22 @@ | ||
<?php declare(strict_types = 1); // lint >= 7.4 | ||
|
||
namespace Bug7190; | ||
|
||
interface MyObject { | ||
public function getId(): int; | ||
} | ||
|
||
class HelloWorld | ||
{ | ||
/** | ||
* @param array<int, int> $array | ||
*/ | ||
public function sayHello(array $array, MyObject $object): int | ||
{ | ||
if (!isset($array[$object->getId()])) { | ||
return 1; | ||
} | ||
|
||
return $array[$object->getId()] ?? 2; | ||
} | ||
} |
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