From b0fb202d3d112c6df2a176791da06703065ac2ad Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Mon, 1 Jul 2024 20:58:27 +0200 Subject: [PATCH] IBX-8180: Applied review remarks --- composer.json | 3 ++- .../Input/Parser/AbstractDestinationLocationParser.php | 6 +++++- .../Input/Parser/SwapLocationInputValidatorBuilder.php | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 76292b5f..5724674d 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,8 @@ "symfony/routing": "^5.3", "symfony/security-bundle": "^5.3", "symfony/security-csrf": "^5.3", - "symfony/yaml": "^5.3" + "symfony/yaml": "^5.3", + "webmozart/assert": "^1.11" }, "require-dev": { "ibexa/ci-scripts": "^0.2@dev", diff --git a/src/lib/Server/Input/Parser/AbstractDestinationLocationParser.php b/src/lib/Server/Input/Parser/AbstractDestinationLocationParser.php index bce6fb5a..d5aa26c7 100644 --- a/src/lib/Server/Input/Parser/AbstractDestinationLocationParser.php +++ b/src/lib/Server/Input/Parser/AbstractDestinationLocationParser.php @@ -14,6 +14,7 @@ use Ibexa\Rest\Server\Exceptions\ValidationFailedException; use Ibexa\Rest\Server\Validation\Builder\Input\Parser\BaseInputParserValidatorBuilder; use Symfony\Component\Validator\Validator\ValidatorInterface; +use Webmozart\Assert\Assert; abstract class AbstractDestinationLocationParser extends BaseParser { @@ -56,8 +57,11 @@ private function getLocationByPath(string $path): Location private function extractLocationIdFromPath(string $path): int { $pathParts = explode('/', $path); + $lastPart = array_pop($pathParts); - return (int)array_pop($pathParts); + Assert::integerish($lastPart); + + return (int)$lastPart; } /** diff --git a/src/lib/Server/Validation/Builder/Input/Parser/SwapLocationInputValidatorBuilder.php b/src/lib/Server/Validation/Builder/Input/Parser/SwapLocationInputValidatorBuilder.php index 07548af7..b1225ba7 100644 --- a/src/lib/Server/Validation/Builder/Input/Parser/SwapLocationInputValidatorBuilder.php +++ b/src/lib/Server/Validation/Builder/Input/Parser/SwapLocationInputValidatorBuilder.php @@ -12,7 +12,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints as Assert; -class SwapLocationInputValidatorBuilder extends BaseInputParserValidatorBuilder +final class SwapLocationInputValidatorBuilder extends BaseInputParserValidatorBuilder { protected function buildConstraint(): Constraint {