Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed generalizing arrays in scope, simplified offset unset in Consta…
…ntArrayType
- Loading branch information
1 parent
0b9f1c0
commit 6173110
Showing
5 changed files
with
73 additions
and
19 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
41 changes: 41 additions & 0 deletions
41
tests/PHPStan/Analyser/data/prestashop-breakdowns-empty-array.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,41 @@ | ||
<?php | ||
|
||
namespace PrestashopBreakdownsEmptyArray; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param mixed[] $arrayMixed | ||
*/ | ||
public function getTaxBreakdown($mixed, $arrayMixed): void | ||
{ | ||
$breakdowns = [ | ||
'product_tax' => $mixed, | ||
'shipping_tax' => $arrayMixed, | ||
'ecotax_tax' => $arrayMixed, | ||
'wrapping_tax' => $arrayMixed, | ||
]; | ||
|
||
foreach ($breakdowns as $type => $bd) { | ||
if (empty($bd)) { | ||
assertType('array{product_tax?: mixed, shipping_tax?: array, ecotax_tax?: array, wrapping_tax?: array}', $breakdowns); | ||
unset($breakdowns[$type]); | ||
assertType('array{product_tax?: mixed, shipping_tax?: array, ecotax_tax?: array, wrapping_tax?: array}', $breakdowns); | ||
} | ||
} | ||
|
||
assertType('array{product_tax?: mixed, shipping_tax?: array, ecotax_tax?: array, wrapping_tax?: array}', $breakdowns); | ||
} | ||
|
||
public function doFoo(): void | ||
{ | ||
$a = ['foo' => 1, 'bar' => 2]; | ||
assertType('array{foo: 1, bar: 2}', $a); | ||
unset($a['foo']); | ||
assertType('array{bar: 2}', $a); | ||
} | ||
|
||
} |
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