Skip to content

Commit

Permalink
[CLEANUP] Remove an impossible throw (#1315)
Browse files Browse the repository at this point in the history
PHPStan is able to determine that `array_combine` when passed the results of
`array_keys` and `array_values` for the same array can never fail (in the sense
of returning `false`), because the two passed arrays will always be the same
length.

Psalm could not, which was why the return value check and `throw` was originally
put in.
  • Loading branch information
JakeQZ committed Sep 17, 2024
1 parent 178d3ef commit c05b168
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,3 @@ parameters:
message: "#^Variable \\$classAttributeMatches in PHPDoc tag @var does not match any variable in the foreach loop\\: \\$classAttributeValue$#"
count: 1
path: tests/Unit/HtmlProcessor/HtmlPrunerTest.php

-
message: "#^Strict comparison using \\=\\=\\= between array\\<string, T\\> and false will always evaluate to false\\.$#"
count: 1
path: tests/Unit/Support/Constraint/IsEquivalentCssTest.php

-
message: "#^Strict comparison using \\=\\=\\= between array\\<string, T\\> and false will always evaluate to false\\.$#"
count: 1
path: tests/Unit/Support/Constraint/StringContainsCssCountTest.php

-
message: "#^Strict comparison using \\=\\=\\= between array\\<string, T\\> and false will always evaluate to false\\.$#"
count: 1
path: tests/Unit/Support/Constraint/StringContainsCssTest.php
10 changes: 1 addition & 9 deletions tests/Support/Traits/CssDataProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,9 @@ private static function crossDatasetWithItself(array $dataset): array
* @param array<string, T> $array
*
* @return array<string, T>
*
* @throws \RuntimeException
*/
private static function arrayMapKeys(callable $callback, array $array): array
{
$result = \array_combine(\array_map($callback, \array_keys($array)), \array_values($array));

if ($result === false) {
throw new \RuntimeException('`array_keys` and `array_values` did not give equal-length arrays', 1619201107);
}

return $result;
return \array_combine(\array_map($callback, \array_keys($array)), \array_values($array));
}
}

0 comments on commit c05b168

Please sign in to comment.