diff --git a/bin/functionMetadata_original.php b/bin/functionMetadata_original.php index 17be4631a9..518986c6b1 100644 --- a/bin/functionMetadata_original.php +++ b/bin/functionMetadata_original.php @@ -28,6 +28,7 @@ 'array_key_last' => ['hasSideEffects' => false], 'array_key_exists' => ['hasSideEffects' => false], 'array_keys' => ['hasSideEffects' => false], + 'array_map' => ['hasSideEffects' => false], 'array_merge' => ['hasSideEffects' => false], 'array_merge_recursive' => ['hasSideEffects' => false], 'array_pad' => ['hasSideEffects' => false], diff --git a/resources/functionMetadata.php b/resources/functionMetadata.php index a01a7181a6..25ba9d8f87 100644 --- a/resources/functionMetadata.php +++ b/resources/functionMetadata.php @@ -737,6 +737,7 @@ 'array_key_last' => ['hasSideEffects' => false], 'array_keys' => ['hasSideEffects' => false], 'array_last' => ['hasSideEffects' => false], + 'array_map' => ['hasSideEffects' => false], 'array_merge' => ['hasSideEffects' => false], 'array_merge_recursive' => ['hasSideEffects' => false], 'array_pad' => ['hasSideEffects' => false], diff --git a/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php b/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php index 0aa586868e..22a040b3d8 100644 --- a/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php +++ b/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php @@ -279,6 +279,13 @@ public function testAllMethodsArePure(): void ]); } + #[RequiresPhp('>= 8.0')] + public function testBug11100(): void + { + $this->treatPhpDocTypesAsCertain = true; + $this->analyse([__DIR__ . '/data/bug-11100.php'], []); + } + public function testBug12382(): void { $this->treatPhpDocTypesAsCertain = true; diff --git a/tests/PHPStan/Rules/Pure/data/bug-11100.php b/tests/PHPStan/Rules/Pure/data/bug-11100.php new file mode 100644 index 0000000000..537c27b15a --- /dev/null +++ b/tests/PHPStan/Rules/Pure/data/bug-11100.php @@ -0,0 +1,32 @@ += 8.0 + +declare(strict_types = 1); + +namespace Bug11100; + +final class FooClass +{ + /** + * @param array $getParams + * + * @phpstan-pure + */ + public function build(array $getParams, string $trailingSlash, bool $useSlashSeparator): string + { + if ($getParams === []) { + return ''; + } + + if ($useSlashSeparator) { + return '/' . implode('/', array_map( + static function (string $key, string|int $value): string { + return rawurlencode($key) . '/' . rawurlencode((string) $value); + }, + array_keys($getParams), + $getParams + )) . $trailingSlash; + } + + return $trailingSlash . '?' . http_build_query($getParams); + } +}