From 0e6f8e2e67d53055806e390d0460380d4c12f491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 14 Aug 2023 14:25:36 +0200 Subject: [PATCH] Added PHPStan --- phpstan-baseline.neon | 80 ---------------------------- src/contracts/Input/Parser.php | 2 +- tests/bundle/Functional/ViewTest.php | 27 +++++++--- 3 files changed, 22 insertions(+), 87 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 90264ca2..75fd68ba 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -285,11 +285,6 @@ parameters: count: 1 path: src/contracts/Input/Handler.php - - - message: "#^Method Ibexa\\\\Contracts\\\\Rest\\\\Input\\\\Parser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/contracts/Input/Parser.php - - message: "#^Cannot access offset mixed on Ibexa\\\\Contracts\\\\Rest\\\\Input\\\\Parser\\.$#" count: 2 @@ -2165,31 +2160,16 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Aggregation/AbstractRangeAggregationParser.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractRangeAggregationParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Aggregation/AbstractRangeAggregationParser.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractRangeAggregationParser\\:\\:parseAggregation\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 path: src/lib/Server/Input/Parser/Aggregation/AbstractRangeAggregationParser.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractStatsAggregationParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Aggregation/AbstractStatsAggregationParser.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractStatsAggregationParser\\:\\:parseAggregation\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 path: src/lib/Server/Input/Parser/Aggregation/AbstractStatsAggregationParser.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractTermAggregationParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Aggregation/AbstractTermAggregationParser.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractTermAggregationParser\\:\\:parseAggregation\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -2290,11 +2270,6 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Aggregation/ObjectStateTermAggregationParser.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\Range\\\\AbstractRangeParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Aggregation/Range/AbstractRangeParser.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\Range\\\\AbstractRangeParser\\:\\:visitRangeValue\\(\\) has no return type specified\\.$#" count: 1 @@ -2465,16 +2440,6 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Criterion/FullText.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\IsUserBased\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/IsUserBased.php - - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\IsUserEnabled\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/IsUserEnabled.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\LanguageCode\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -2545,11 +2510,6 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Criterion/ObjectStateId.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\ObjectStateIdentifier\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/ObjectStateIdentifier.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\Operator\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -2575,41 +2535,16 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Criterion/SectionId.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\SectionIdentifier\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/SectionIdentifier.php - - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\Sibling\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/Sibling.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\Subtree\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 path: src/lib/Server/Input/Parser/Criterion/Subtree.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserEmail\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/UserEmail.php - - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserId\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/UserId.php - - message: "#^Parameter \\#1 \\$value of class Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Query\\\\Criterion\\\\UserId constructor expects array\\\\|int, array\\ given\\.$#" count: 1 path: src/lib/Server/Input/Parser/Criterion/UserId.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserLogin\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/UserLogin.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserMetadata\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -2680,11 +2615,6 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/FieldDefinitionUpdate.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\JWTInput\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/JWTInput.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Limitation\\\\PathStringRouteBasedLimitationParser\\:\\:parseIdFromHref\\(\\) has parameter \\$limitationValue with no type specified\\.$#" count: 1 @@ -6675,16 +6605,6 @@ parameters: count: 2 path: tests/bundle/Functional/UserTest.php - - - message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\ViewTest\\:\\:testViewRequestWithAndStatement\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/bundle/Functional/ViewTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\ViewTest\\:\\:testViewRequestWithOrStatement\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/bundle/Functional/ViewTest.php - - message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\RequestParser\\\\RouterTest\\:\\:getRouterMock\\(\\) should return PHPUnit\\\\Framework\\\\MockObject\\\\MockObject&Symfony\\\\Component\\\\Routing\\\\RouterInterface but returns Symfony\\\\Component\\\\Routing\\\\RouterInterface\\.$#" count: 1 diff --git a/src/contracts/Input/Parser.php b/src/contracts/Input/Parser.php index 657d6d8a..d640afe3 100644 --- a/src/contracts/Input/Parser.php +++ b/src/contracts/Input/Parser.php @@ -14,7 +14,7 @@ abstract class Parser /** * Parse input structure. * - * @param array $data + * @param array $data * @param \Ibexa\Contracts\Rest\Input\ParsingDispatcher $parsingDispatcher * * @return \Ibexa\Contracts\Core\Repository\Values\ValueObject|object diff --git a/tests/bundle/Functional/ViewTest.php b/tests/bundle/Functional/ViewTest.php index 2d73b448..85199e5d 100644 --- a/tests/bundle/Functional/ViewTest.php +++ b/tests/bundle/Functional/ViewTest.php @@ -95,36 +95,51 @@ public function provideForViewTest(): iterable ); yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_EQUALITY, self::FORMAT_XML) => [ - file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.xml'), + $this->loadFile(__DIR__ . '/_input/search/LocationDepth.eq.xml'), self::FORMAT_XML, ]; yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_EQUALITY, self::FORMAT_JSON) => [ - file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.json'), + $this->loadFile(__DIR__ . '/_input/search/LocationDepth.eq.json'), self::FORMAT_JSON, ]; yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_IN, self::FORMAT_XML) => [ - file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.xml'), + $this->loadFile(__DIR__ . '/_input/search/LocationDepth.in.xml'), self::FORMAT_XML, ]; yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_IN, self::FORMAT_JSON) => [ - file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.json'), + $this->loadFile(__DIR__ . '/_input/search/LocationDepth.in.json'), self::FORMAT_JSON, ]; yield $template(self::CRITERION_IS_MAIN_LOCATION, self::OPERATOR_EQUALITY, self::FORMAT_XML) => [ - file_get_contents(__DIR__ . '/_input/search/IsMainLocation.xml'), + $this->loadFile(__DIR__ . '/_input/search/IsMainLocation.xml'), self::FORMAT_XML, ]; yield $template(self::CRITERION_IS_MAIN_LOCATION, self::OPERATOR_EQUALITY, self::FORMAT_JSON) => [ - file_get_contents(__DIR__ . '/_input/search/IsMainLocation.json'), + $this->loadFile(__DIR__ . '/_input/search/IsMainLocation.json'), self::FORMAT_JSON, ]; } + private function loadFile(string $filepath): string + { + $data = file_get_contents($filepath); + + if ($data === false) { + throw new \RuntimeException(sprintf( + 'Unable to get contents for file: "%s". Ensure it exists and is readable.', + $filepath, + )); + } + + return $data; + } + + /** * Covers POST /views. *