Skip to content

Commit

Permalink
feat(MOS-854): Added support for PHP 8.2 (#13)
Browse files Browse the repository at this point in the history
* chore(MOS-854): Added support for PHP 8.2

* chore(MOS-854): Update php-devtools

---------

Co-authored-by: Bart van Raaij <[email protected]>
  • Loading branch information
fred-jan and bartvanraaij authored Aug 14, 2023
1 parent 7203474 commit 8028810
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
4 changes: 2 additions & 2 deletions src/Symfony/HttpKernel/Exception/JsonApiProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
20 changes: 12 additions & 8 deletions src/Symfony/Request/ParamConverter/ValinorParamConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions tests/Symfony/Request/ParamConverter/StubId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}

0 comments on commit 8028810

Please sign in to comment.