From 8d6d59dee5fad508e5cc1f9b19268aea24aa3f01 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 5 May 2022 15:25:13 +0200 Subject: [PATCH] Fix issue reported by PHPStan --- phpstan-baseline.neon | 5 ----- src/Twig/SourceCodeExtension.php | 4 +++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f9333d935..3b055a5ea 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -345,11 +345,6 @@ parameters: count: 1 path: src/Twig/SourceCodeExtension.php - - - message: "#^Parameter \\#1 \\$array of function array_slice expects array, array\\\\|false given\\.$#" - count: 1 - path: src/Twig/SourceCodeExtension.php - - message: "#^Parameter \\#1 \\$filename of function file expects string, string\\|false given\\.$#" count: 1 diff --git a/src/Twig/SourceCodeExtension.php b/src/Twig/SourceCodeExtension.php index ff2145a5d..e3a4b2028 100644 --- a/src/Twig/SourceCodeExtension.php +++ b/src/Twig/SourceCodeExtension.php @@ -65,7 +65,9 @@ private function getController(): ?array $method = $this->getCallableReflector($this->controller); - $classCode = file($method->getFileName()); + if (false === $classCode = file($method->getFileName())) { + throw new \LogicException(sprintf('There was an error while trying to read the contents of the "%s" file.', $method->getFileName())); + } $startLine = $method->getStartLine() - 1; $endLine = $method->getEndLine();