Skip to content

Commit

Permalink
Fix: Return early when json_decode()'ed data is not an object
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Oct 9, 2018
1 parent feecf0b commit e1410bd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Normalizer/BinNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Normalizer/ConfigHashNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/Normalizer/PackageHashNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/Normalizer/VersionConstraintNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e1410bd

Please sign in to comment.