diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 35e8f5a..cc42ace 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.2 coverage: none - uses: ramsey/composer-install@v2 - id: set-php-versions diff --git a/composer.json b/composer.json index a14c082..8ce79d5 100644 --- a/composer.json +++ b/composer.json @@ -22,18 +22,18 @@ }, "require": { "php": "^8.0", - "cuyz/valinor": "^0.13", + "cuyz/valinor": "^1.5", "sensio/framework-extra-bundle": "^6.2", "symfony/event-dispatcher": "^5.4 || ^6.0", "symfony/http-kernel": "^5.4 || ^6.0" }, "require-dev": { "myonlinestore/coding-standard": "^3.1", - "myonlinestore/php-devtools": "^0.3.0", + "myonlinestore/php-devtools": "^0.4", "phpunit/phpunit": "^9.5", "psalm/plugin-phpunit": "^0.16.1", - "psalm/plugin-symfony": "^3.1", + "psalm/plugin-symfony": "^4.0", "roave/infection-static-analysis-plugin": "^1.18", - "vimeo/psalm": "^4.23" + "vimeo/psalm": "^4.30" } } diff --git a/src/Symfony/HttpKernel/Exception/JsonApiProblem.php b/src/Symfony/HttpKernel/Exception/JsonApiProblem.php index c38ef95..dc5a1f4 100644 --- a/src/Symfony/HttpKernel/Exception/JsonApiProblem.php +++ b/src/Symfony/HttpKernel/Exception/JsonApiProblem.php @@ -4,7 +4,7 @@ namespace MyOnlineStore\ApiTools\Symfony\HttpKernel\Exception; use CuyZ\Valinor\Mapper\MappingError; -use CuyZ\Valinor\Mapper\Tree\Message\MessagesFlattener; +use CuyZ\Valinor\Mapper\Tree\Message\Messages; use Symfony\Component\HttpKernel\Exception\HttpException; final class JsonApiProblem extends HttpException @@ -47,7 +47,7 @@ public static function fromValinorMappingError( int $statusCode = 422 ): self { $errors = []; - $flattenedMessages = (new MessagesFlattener($mappingError->node()))->errors(); + $flattenedMessages = Messages::flattenFromNode($mappingError->node()); foreach ($flattenedMessages as $message) { $node = $message->node(); diff --git a/src/Symfony/Request/ParamConverter/ValinorParamConverter.php b/src/Symfony/Request/ParamConverter/ValinorParamConverter.php index 7edadb4..62e7366 100644 --- a/src/Symfony/Request/ParamConverter/ValinorParamConverter.php +++ b/src/Symfony/Request/ParamConverter/ValinorParamConverter.php @@ -5,7 +5,7 @@ use CuyZ\Valinor\Cache\FileSystemCache; use CuyZ\Valinor\Mapper\MappingError; -use CuyZ\Valinor\Mapper\Tree\Message\ThrowableMessage; +use CuyZ\Valinor\Mapper\Tree\Message\MessageBuilder; use CuyZ\Valinor\MapperBuilder; use MyOnlineStore\ApiTools\Symfony\HttpKernel\Exception\JsonApiProblem; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; @@ -28,7 +28,7 @@ public function apply(Request $request, ParamConverter $configuration): bool $configuration->getName(), $this->getMapperBuilder() ->mapper() - ->map($this->getClass(), $this->getData($request, $configuration)) + ->map($this->getClass(), $this->getData($request, $configuration)), ); } catch (MappingError $mappingError) { throw JsonApiProblem::fromValinorMappingError('Invalid Request', 'Invalid data provided.', $mappingError); @@ -58,13 +58,17 @@ abstract protected function getData(Request $request, ParamConverter $configurat protected function getMapperBuilder(): MapperBuilder { $mapperBuilder = (new MapperBuilder()) - ->filterExceptions(static function (\Throwable $exception) { - if ($exception instanceof InvalidArgumentException) { - return ThrowableMessage::from($exception); - } + ->filterExceptions( + /** @psalm-pure */ + static function (\Throwable $exception) { + if ($exception instanceof InvalidArgumentException) { + /** @psalm-suppress ImpureMethodCall */ + return MessageBuilder::from($exception); + } - throw $exception; - }); + throw $exception; + }, + ); if (null !== $this->valinorCacheDir) { $mapperBuilder = $mapperBuilder->withCache(new FileSystemCache($this->valinorCacheDir)); diff --git a/tests/Symfony/Request/ParamConverter/StubId.php b/tests/Symfony/Request/ParamConverter/StubId.php index 5b0c09b..65f7a3c 100644 --- a/tests/Symfony/Request/ParamConverter/StubId.php +++ b/tests/Symfony/Request/ParamConverter/StubId.php @@ -7,11 +7,13 @@ final class StubId { + /** @psalm-pure */ private function __construct( private string $id, ) { } + /** @psalm-pure */ public static function fromString(string $id): self { Assert::stringNotEmpty($id); diff --git a/tests/Symfony/Request/ParamConverter/StubValinorBodyJsonConverter.php b/tests/Symfony/Request/ParamConverter/StubValinorBodyJsonConverter.php index e942a5b..9747766 100644 --- a/tests/Symfony/Request/ParamConverter/StubValinorBodyJsonConverter.php +++ b/tests/Symfony/Request/ParamConverter/StubValinorBodyJsonConverter.php @@ -24,6 +24,9 @@ protected function getData(Request $request, ParamConverter $configuration): Jso protected function getMapperBuilder(): MapperBuilder { return parent::getMapperBuilder() - ->registerConstructor(static fn (string $id): StubId => StubId::fromString($id)); + ->registerConstructor( + /** @psalm-pure */ + static fn (string $id): StubId => StubId::fromString($id) + ); } }