From 1e9210f7b1fc66984a891ea58f13c8c5d2dff81d Mon Sep 17 00:00:00 2001 From: Fabien Villepinte Date: Sat, 4 Jun 2022 15:20:58 +0200 Subject: [PATCH] Fix TypeError when a JSON file can not be read (#10818) --- phpstan/baseline.neon | 5 ----- src/Composer/Json/JsonFile.php | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index ac39f66e8..c335349c5 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -4365,11 +4365,6 @@ parameters: count: 1 path: ../src/Composer/Json/JsonFile.php - - - message: "#^Parameter \\#1 \\$json of static method Composer\\\\Json\\\\JsonFile\\:\\:parseJson\\(\\) expects string\\|null, string\\|false\\|null given\\.$#" - count: 1 - path: ../src/Composer/Json/JsonFile.php - - message: "#^Parameter \\#1 \\$json of static method Composer\\\\Json\\\\JsonFile\\:\\:validateSyntax\\(\\) expects string, string\\|false given\\.$#" count: 1 diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 2202530d9..bbcd24206 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -110,6 +110,10 @@ class JsonFile throw new \RuntimeException('Could not read '.$this->path."\n\n".$e->getMessage()); } + if ($json === false) { + throw new \RuntimeException('Could not read '.$this->path); + } + return static::parseJson($json, $this->path); }