From e1410bde584483faf5bdb59fccc18db48db929c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 9 Oct 2018 18:07:47 +0100 Subject: [PATCH] Fix: Return early when json_decode()'ed data is not an object --- src/Normalizer/BinNormalizer.php | 5 ++++- src/Normalizer/ConfigHashNormalizer.php | 4 ++++ src/Normalizer/PackageHashNormalizer.php | 4 ++++ src/Normalizer/VersionConstraintNormalizer.php | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Normalizer/BinNormalizer.php b/src/Normalizer/BinNormalizer.php index fbcf593b..2293644e 100644 --- a/src/Normalizer/BinNormalizer.php +++ b/src/Normalizer/BinNormalizer.php @@ -28,7 +28,10 @@ public function normalize(string $json): string )); } - if (!\property_exists($decoded, 'bin') || !\is_array($decoded->bin)) { + if (!$decoded instanceof \stdClass + || !\property_exists($decoded, 'bin') + || !\is_array($decoded->bin) + ) { return $json; } diff --git a/src/Normalizer/ConfigHashNormalizer.php b/src/Normalizer/ConfigHashNormalizer.php index cf99505f..4813ba84 100644 --- a/src/Normalizer/ConfigHashNormalizer.php +++ b/src/Normalizer/ConfigHashNormalizer.php @@ -36,6 +36,10 @@ public function normalize(string $json): string )); } + if (!$decoded instanceof \stdClass) { + return $json; + } + $objectProperties = \array_intersect_key( \get_object_vars($decoded), \array_flip(self::$properties) diff --git a/src/Normalizer/PackageHashNormalizer.php b/src/Normalizer/PackageHashNormalizer.php index de1b8c87..f0abec28 100644 --- a/src/Normalizer/PackageHashNormalizer.php +++ b/src/Normalizer/PackageHashNormalizer.php @@ -41,6 +41,10 @@ public function normalize(string $json): string )); } + if (!$decoded instanceof \stdClass) { + return $json; + } + $objectProperties = \array_intersect_key( \get_object_vars($decoded), \array_flip(self::$properties) diff --git a/src/Normalizer/VersionConstraintNormalizer.php b/src/Normalizer/VersionConstraintNormalizer.php index 6fa9a3d8..95031215 100644 --- a/src/Normalizer/VersionConstraintNormalizer.php +++ b/src/Normalizer/VersionConstraintNormalizer.php @@ -57,6 +57,10 @@ public function normalize(string $json): string )); } + if (!$decoded instanceof \stdClass) { + return $json; + } + $objectProperties = \array_intersect_key( \get_object_vars($decoded), \array_flip(self::$properties)