From 0edee0651514f9877b9e37628e6228288ed665bf Mon Sep 17 00:00:00 2001 From: Kevin Kaniaburka Date: Fri, 23 Aug 2024 23:16:24 +0200 Subject: [PATCH] Fix all deprecations --- .gitignore | 1 + .phpunit.cache/test-results | 1 - composer.json | 2 + composer.lock | 96 +++++++++++++++++-- .../ApiResource/UserResource.php | 7 +- .../Processor/UserCreateProcessor.php | 2 +- .../Symfony/Package/api_platform.yaml | 2 + .../Symfony/Package/doctrine.yaml | 3 + .../Symfony/Package/framework.yaml | 4 + .../Package/stof_doctrine_extensions.yaml | 7 ++ .../Symfony/Route/annotations.yaml | 2 +- .../Configuration/Symfony/Service/gedmo.php | 17 ---- .../Configuration/Symfony/bundles.php | 1 + .../Configuration/Symfony/routes.yaml | 2 +- .../InResourceRepresentationNormalizer.php | 23 ++--- .../PortfolioChangeDefaultProcessor.php | 2 +- .../Processor/PortfolioCreateProcessor.php | 2 +- .../Processor/PortfolioUpdateProcessor.php | 2 +- .../ApiResource/ReportResource.php | 11 ++- .../InResourceRepresentationNormalizer.php | 60 ++++++++++++ .../Processor/ReportCreateProcessor.php | 2 +- .../Symfony/Service/serializer.php | 13 +++ .../Processor/TransactionCreateProcessor.php | 2 +- symfony.lock | 12 +++ 24 files changed, 221 insertions(+), 55 deletions(-) delete mode 100644 .phpunit.cache/test-results create mode 100644 src/Core/Infrastructure/Configuration/Symfony/Package/stof_doctrine_extensions.yaml delete mode 100644 src/Core/Infrastructure/Configuration/Symfony/Service/gedmo.php create mode 100644 src/Report/Infrastructure/ApiSerializer/InResourceRepresentationNormalizer.php create mode 100644 src/Report/Infrastructure/Configuration/Symfony/Service/serializer.php diff --git a/.gitignore b/.gitignore index dc5eb8c..2814cee 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /vendor/ /.php-cs-fixer.php /.php-cs-fixer.cache +/.phpunit.cache /phpunit.xml /.phpunit.result.cache /behat.yaml diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results deleted file mode 100644 index 18d0228..0000000 --- a/.phpunit.cache/test-results +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":[],"times":{"Panda\\Tests\\App\\Account\\Domain\\Factory\\UserFactoryTest::it_creates_user_with_hashed_password":0.01,"Panda\\Tests\\App\\Account\\Domain\\Factory\\UserFactoryTest::it_creates_user_without_password":0,"Panda\\Tests\\App\\Account\\Domain\\Model\\UserTest::it_compares_to_another_user_by_id":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Factory\\PortfolioFactoryTest::it_creates_portfolio":0.002,"Panda\\Tests\\App\\Portfolio\\Domain\\Factory\\PortfolioFactoryTest::it_creates_portfolio_with_user":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Factory\\PortfolioItemFactoryTest::it_creates_portfolio":0.001,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioItemTest::it_has_zero_quantity_at_first":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioItemTest::it_adds_and_removes_quantity":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioItemTest::it_can_have_quantity_reduced_to_zero":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioItemTest::it_throws_exception_if_negative_long_quantity_added":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioItemTest::it_throws_exception_if_negative_short_quantity_added":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioItemTest::it_throws_exception_if_negative_long_quantity_removed":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioItemTest::it_throws_exception_if_negative_short_quantity_removed":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioItemTest::it_throws_exception_if_total_long_quantity_is_negative":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioItemTest::it_throws_exception_if_total_short_quantity_is_negative":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioTest::it_adds_items":0.001,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioTest::it_adds_items_with_no_duplicates":0,"Panda\\Tests\\App\\Portfolio\\Domain\\Model\\PortfolioTest::it_removes_items":0.001,"Panda\\Tests\\App\\Report\\Domain\\Factory\\ReportFactoryTest::it_creates_report":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\AssetFactoryTest::it_creates_asset":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\AssetFactoryTest::it_creates_asset_without_name":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\AssetFactoryTest::it_creates_asset_with_owner":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\OperationFactoryTest::it_creates_operation":0.001,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\TransactionFactoryTest::it_creates_ask_transaction":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\TransactionFactoryTest::it_creates_bid_transaction":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\TransactionFactoryTest::it_creates_deposit_transaction":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\TransactionFactoryTest::it_creates_withdraw_transaction":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\TransactionFactoryTest::it_creates_fee_transaction":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\TransactionFactoryTest::it_creates_transaction_with_owner":0,"Panda\\Tests\\App\\Trade\\Domain\\Factory\\TransactionFactoryTest::it_does_not_require_adjustment_operations_for_all_transactions_except_fee_transaction":0}} \ No newline at end of file diff --git a/composer.json b/composer.json index 1514168..22d8952 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "lexik/jwt-authentication-bundle": "^2.18", "nelmio/cors-bundle": "^2.2", "phpstan/phpdoc-parser": "^1.16", + "stof/doctrine-extensions-bundle": "^1.12", "symfony/asset": "^6.4", "symfony/console": "^6.4", "symfony/dotenv": "^6.4", @@ -30,6 +31,7 @@ "symfony/runtime": "^6.4", "symfony/security-bundle": "^6.4", "symfony/serializer": "^6.4", + "symfony/string": "^6.4", "symfony/twig-bundle": "^6.4", "symfony/uid": "^6.4", "symfony/validator": "^6.4", diff --git a/composer.lock b/composer.lock index 1a46cf9..4755b73 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "02b31d768da43a72a8df649831e0f2cd", + "content-hash": "3013660e3b8debcc8fd25e68f85c8e41", "packages": [ { "name": "api-platform/core", @@ -3216,6 +3216,86 @@ }, "time": "2019-03-08T08:55:37+00:00" }, + { + "name": "stof/doctrine-extensions-bundle", + "version": "v1.12.0", + "source": { + "type": "git", + "url": "https://github.com/stof/StofDoctrineExtensionsBundle.git", + "reference": "473ae65598fa4160654c350e139e20ee75d9a91a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stof/StofDoctrineExtensionsBundle/zipball/473ae65598fa4160654c350e139e20ee75d9a91a", + "reference": "473ae65598fa4160654c350e139e20ee75d9a91a", + "shasum": "" + }, + "require": { + "gedmo/doctrine-extensions": "^3.15.0", + "php": "^7.4 || ^8.0", + "symfony/cache": "^5.4 || ^6.0 || ^7.0", + "symfony/config": "^5.4 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0", + "symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.0 || ^7.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-deprecation-rules": "^1.1", + "phpstan/phpstan-phpunit": "^1.3", + "phpstan/phpstan-strict-rules": "^1.5", + "phpstan/phpstan-symfony": "^1.3", + "symfony/mime": "^5.4 || ^6.0 || ^7.0", + "symfony/phpunit-bridge": "^v6.4.1 || ^7.0.1", + "symfony/security-core": "^5.4 || ^6.0 || ^7.0" + }, + "suggest": { + "doctrine/doctrine-bundle": "to use the ORM extensions", + "doctrine/mongodb-odm-bundle": "to use the MongoDB ODM extensions", + "symfony/mime": "To use the Mime component integration for Uploadable" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Stof\\DoctrineExtensionsBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christophe Coevoet", + "email": "stof@notk.org" + } + ], + "description": "Integration of the gedmo/doctrine-extensions with Symfony", + "homepage": "https://github.com/stof/StofDoctrineExtensionsBundle", + "keywords": [ + "behaviors", + "doctrine2", + "extensions", + "gedmo", + "loggable", + "nestedset", + "sluggable", + "sortable", + "timestampable", + "translatable", + "tree" + ], + "support": { + "issues": "https://github.com/stof/StofDoctrineExtensionsBundle/issues", + "source": "https://github.com/stof/StofDoctrineExtensionsBundle/tree/v1.12.0" + }, + "time": "2024-06-10T12:27:27+00:00" + }, { "name": "symfony/asset", "version": "v6.4.8", @@ -6730,16 +6810,16 @@ }, { "name": "symfony/string", - "version": "v6.4.9", + "version": "v6.4.10", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "76792dbd99690a5ebef8050d9206c60c59e681d7" + "reference": "ccf9b30251719567bfd46494138327522b9a9446" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/76792dbd99690a5ebef8050d9206c60c59e681d7", - "reference": "76792dbd99690a5ebef8050d9206c60c59e681d7", + "url": "https://api.github.com/repos/symfony/string/zipball/ccf9b30251719567bfd46494138327522b9a9446", + "reference": "ccf9b30251719567bfd46494138327522b9a9446", "shasum": "" }, "require": { @@ -6796,7 +6876,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.4.9" + "source": "https://github.com/symfony/string/tree/v6.4.10" }, "funding": [ { @@ -6812,7 +6892,7 @@ "type": "tidelift" } ], - "time": "2024-06-28T09:25:38+00:00" + "time": "2024-07-22T10:21:14+00:00" }, { "name": "symfony/translation-contracts", @@ -13699,5 +13779,5 @@ "ext-iconv": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Account/Infrastructure/ApiResource/UserResource.php b/src/Account/Infrastructure/ApiResource/UserResource.php index 1cc8918..8cea82a 100644 --- a/src/Account/Infrastructure/ApiResource/UserResource.php +++ b/src/Account/Infrastructure/ApiResource/UserResource.php @@ -8,6 +8,7 @@ use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation; use Panda\Account\Domain\Model\UserInterface; use Panda\Account\Infrastructure\ApiState\Processor\UserCreateProcessor; use Panda\Account\Infrastructure\ApiState\Provider\UserProvider; @@ -20,13 +21,13 @@ operations: [ new Get(provider: UserProvider::class), new Post( - openapiContext: [ - 'responses' => [ + openapi: new OpenApiOperation( + responses: [ '204' => ['description' => 'User created or already exists'], '400' => ['description' => 'Invalid input'], '422' => ['description' => 'Unprocessable entity'], ], - ], + ), validationContext: ['groups' => self::WRITABLE_GROUPS], output: false, processor: UserCreateProcessor::class, diff --git a/src/Account/Infrastructure/ApiState/Processor/UserCreateProcessor.php b/src/Account/Infrastructure/ApiState/Processor/UserCreateProcessor.php index 3eb17fb..00178b1 100644 --- a/src/Account/Infrastructure/ApiState/Processor/UserCreateProcessor.php +++ b/src/Account/Infrastructure/ApiState/Processor/UserCreateProcessor.php @@ -19,7 +19,7 @@ public function __construct( ) { } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []) + public function process($data, Operation $operation, array $uriVariables = [], array $context = []): UserResource { Assert::isInstanceOf($data, UserResource::class); diff --git a/src/Core/Infrastructure/Configuration/Symfony/Package/api_platform.yaml b/src/Core/Infrastructure/Configuration/Symfony/Package/api_platform.yaml index 4cbbdc7..58e0e0f 100644 --- a/src/Core/Infrastructure/Configuration/Symfony/Package/api_platform.yaml +++ b/src/Core/Infrastructure/Configuration/Symfony/Package/api_platform.yaml @@ -6,6 +6,8 @@ api_platform: title: PANDA API version: dev show_webby: false + use_symfony_listeners: false + keep_legacy_inflector: false patch_formats: json: ['application/merge-patch+json'] formats: diff --git a/src/Core/Infrastructure/Configuration/Symfony/Package/doctrine.yaml b/src/Core/Infrastructure/Configuration/Symfony/Package/doctrine.yaml index e6d3b52..031efad 100644 --- a/src/Core/Infrastructure/Configuration/Symfony/Package/doctrine.yaml +++ b/src/Core/Infrastructure/Configuration/Symfony/Package/doctrine.yaml @@ -12,5 +12,8 @@ doctrine: auto_generate_proxy_classes: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: true + enable_lazy_ghost_objects: true + controller_resolver: + auto_mapping: false resolve_target_entities: Panda\AccountOHS\Domain\Model\Owner\OwnerInterface: Panda\Account\Domain\Model\User diff --git a/src/Core/Infrastructure/Configuration/Symfony/Package/framework.yaml b/src/Core/Infrastructure/Configuration/Symfony/Package/framework.yaml index 9c07249..de38414 100644 --- a/src/Core/Infrastructure/Configuration/Symfony/Package/framework.yaml +++ b/src/Core/Infrastructure/Configuration/Symfony/Package/framework.yaml @@ -3,6 +3,7 @@ framework: secret: '%env(APP_SECRET)%' #csrf_protection: true http_method_override: false + handle_all_throwables: true trusted_proxies: '%env(TRUSTED_PROXIES)%' trusted_hosts: '%env(TRUSTED_HOSTS)%' # See https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#headers @@ -12,6 +13,9 @@ framework: #fragments: true php_errors: log: true + + annotations: + enabled: false when@test: framework: diff --git a/src/Core/Infrastructure/Configuration/Symfony/Package/stof_doctrine_extensions.yaml b/src/Core/Infrastructure/Configuration/Symfony/Package/stof_doctrine_extensions.yaml new file mode 100644 index 0000000..f3c4c86 --- /dev/null +++ b/src/Core/Infrastructure/Configuration/Symfony/Package/stof_doctrine_extensions.yaml @@ -0,0 +1,7 @@ +# Read the documentation: https://symfony.com/doc/current/bundles/StofDoctrineExtensionsBundle/index.html +# See the official DoctrineExtensions documentation for more details: https://github.com/doctrine-extensions/DoctrineExtensions/tree/main/doc +stof_doctrine_extensions: + default_locale: en_US + orm: + default: + timestampable: true diff --git a/src/Core/Infrastructure/Configuration/Symfony/Route/annotations.yaml b/src/Core/Infrastructure/Configuration/Symfony/Route/annotations.yaml index dc9fe31..ab7da43 100644 --- a/src/Core/Infrastructure/Configuration/Symfony/Route/annotations.yaml +++ b/src/Core/Infrastructure/Configuration/Symfony/Route/annotations.yaml @@ -1,3 +1,3 @@ kernel: resource: ../../../Symfony/Kernel.php - type: annotation + type: attribute diff --git a/src/Core/Infrastructure/Configuration/Symfony/Service/gedmo.php b/src/Core/Infrastructure/Configuration/Symfony/Service/gedmo.php deleted file mode 100644 index 42b38ab..0000000 --- a/src/Core/Infrastructure/Configuration/Symfony/Service/gedmo.php +++ /dev/null @@ -1,17 +0,0 @@ -services(); - - $services - ->set('gedmo.listener.timestampable') - ->class(TimestampableListener::class) - ->tag('doctrine.event_subscriber', ['connection' => 'default']) - ->call('setAnnotationReader', [service('annotation_reader')]); -}; diff --git a/src/Core/Infrastructure/Configuration/Symfony/bundles.php b/src/Core/Infrastructure/Configuration/Symfony/bundles.php index 4100fda..ed01f78 100644 --- a/src/Core/Infrastructure/Configuration/Symfony/bundles.php +++ b/src/Core/Infrastructure/Configuration/Symfony/bundles.php @@ -17,4 +17,5 @@ Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true], Hautelook\AliceBundle\HautelookAliceBundle::class => ['dev' => true, 'test' => true], FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true], + Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], ]; diff --git a/src/Core/Infrastructure/Configuration/Symfony/routes.yaml b/src/Core/Infrastructure/Configuration/Symfony/routes.yaml index 2da5d6e..6c82422 100644 --- a/src/Core/Infrastructure/Configuration/Symfony/routes.yaml +++ b/src/Core/Infrastructure/Configuration/Symfony/routes.yaml @@ -1,6 +1,6 @@ kernel: resource: ../../../../Core/Infrastructure/Symfony/Kernel.php - type: annotation + type: attribute app: resource: ../../../../*/Infrastructure/Configuration/Symfony/Route/* diff --git a/src/Portfolio/Infrastructure/ApiSerializer/InResourceRepresentationNormalizer.php b/src/Portfolio/Infrastructure/ApiSerializer/InResourceRepresentationNormalizer.php index cfe47dd..49834ad 100644 --- a/src/Portfolio/Infrastructure/ApiSerializer/InResourceRepresentationNormalizer.php +++ b/src/Portfolio/Infrastructure/ApiSerializer/InResourceRepresentationNormalizer.php @@ -6,8 +6,6 @@ use Panda\Portfolio\Infrastructure\ApiResource\QuantityRepresentation; use Panda\Portfolio\Infrastructure\ApiResource\ResourceRepresentation; -use Panda\Report\Infrastructure\ApiResource\ReportEntryRepresentation; -use Panda\Report\Infrastructure\ApiResource\ReportFileRepresentation; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -46,18 +44,17 @@ public function supportsNormalization(mixed $data, ?string $format = null, array return $data instanceof ResourceRepresentation || $data instanceof QuantityRepresentation - || $data instanceof ReportEntryRepresentation - || $data instanceof ReportFileRepresentation ; } - // public function getSupportedTypes(?string $format): array - // { - // return [ - // ResourceRepresentation::class => true, - // QuantityRepresentation::class => true, - // ReportEntryRepresentation::class => true, - // ReportFileRepresentation::class => true, - // ]; - // } + /** + * @return array + */ + public function getSupportedTypes(?string $format): array + { + return [ + ResourceRepresentation::class => false, + QuantityRepresentation::class => false, + ]; + } } diff --git a/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioChangeDefaultProcessor.php b/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioChangeDefaultProcessor.php index 66def0a..584a7c0 100644 --- a/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioChangeDefaultProcessor.php +++ b/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioChangeDefaultProcessor.php @@ -19,7 +19,7 @@ public function __construct(private CommandBusInterface $commandBus) { } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []) + public function process($data, Operation $operation, array $uriVariables = [], array $context = []): PortfolioResource { /** @var PortfolioResource $data */ Assert::isInstanceOf($data, PortfolioResource::class); diff --git a/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioCreateProcessor.php b/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioCreateProcessor.php index 8ff3e50..dfbcb36 100644 --- a/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioCreateProcessor.php +++ b/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioCreateProcessor.php @@ -18,7 +18,7 @@ public function __construct(private CommandBusInterface $commandBus) { } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []) + public function process($data, Operation $operation, array $uriVariables = [], array $context = []): PortfolioResource { /** @var PortfolioResource $data */ Assert::isInstanceOf($data, PortfolioResource::class); diff --git a/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioUpdateProcessor.php b/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioUpdateProcessor.php index 979f7e8..c1e4ecb 100644 --- a/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioUpdateProcessor.php +++ b/src/Portfolio/Infrastructure/ApiState/Processor/PortfolioUpdateProcessor.php @@ -19,7 +19,7 @@ public function __construct(private CommandBusInterface $commandBus) { } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []) + public function process($data, Operation $operation, array $uriVariables = [], array $context = []): PortfolioResource { /** @var PortfolioResource $data */ Assert::isInstanceOf($data, PortfolioResource::class); diff --git a/src/Report/Infrastructure/ApiResource/ReportResource.php b/src/Report/Infrastructure/ApiResource/ReportResource.php index 2dfd8e5..4fa8053 100644 --- a/src/Report/Infrastructure/ApiResource/ReportResource.php +++ b/src/Report/Infrastructure/ApiResource/ReportResource.php @@ -9,6 +9,7 @@ use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation; use Panda\Portfolio\Infrastructure\ApiResource\PortfolioResource; use Panda\Report\Application\Action\DownloadReportAction; use Panda\Report\Domain\Model\Report\ReportInterface; @@ -26,10 +27,8 @@ uriTemplate: '/reports/{id}/download', formats: ['csv' => ['text/csv']], controller: DownloadReportAction::class, - openapiContext: [ - 'summary' => 'Downloads a report.', - 'description' => 'Downloads a report.', - 'responses' => [ + openapi: new OpenApiOperation( + responses: [ '200' => [ 'description' => 'Report file', 'content' => [ @@ -42,7 +41,9 @@ ], ], ], - ], + summary: 'Downloads a report.', + description: 'Downloads a report.', + ), ), new Post( validationContext: ['groups' => ['create']], diff --git a/src/Report/Infrastructure/ApiSerializer/InResourceRepresentationNormalizer.php b/src/Report/Infrastructure/ApiSerializer/InResourceRepresentationNormalizer.php new file mode 100644 index 0000000..a6ff317 --- /dev/null +++ b/src/Report/Infrastructure/ApiSerializer/InResourceRepresentationNormalizer.php @@ -0,0 +1,60 @@ +normalizer->normalize($object, $format, $context); + + if (!is_array($normalized)) { + return $normalized; + } + + unset($normalized['@id']); + unset($normalized['@type']); + + return $normalized; + } + + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool + { + if (is_object($data) && isset($context[get_class($data).self::ALREADY_CALLED_SUFFIX])) { + return false; + } + + return + $data instanceof ReportEntryRepresentation + || $data instanceof ReportFileRepresentation + ; + } + + /** + * @return array + */ + public function getSupportedTypes(?string $format): array + { + return [ + ReportEntryRepresentation::class => false, + ReportFileRepresentation::class => false, + ]; + } +} diff --git a/src/Report/Infrastructure/ApiState/Processor/ReportCreateProcessor.php b/src/Report/Infrastructure/ApiState/Processor/ReportCreateProcessor.php index ce304ac..4ad8428 100644 --- a/src/Report/Infrastructure/ApiState/Processor/ReportCreateProcessor.php +++ b/src/Report/Infrastructure/ApiState/Processor/ReportCreateProcessor.php @@ -19,7 +19,7 @@ public function __construct(private CommandBusInterface $commandBus) { } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []) + public function process($data, Operation $operation, array $uriVariables = [], array $context = []): ReportResource { /** @var ReportResource $data */ Assert::isInstanceOf($data, ReportResource::class); diff --git a/src/Report/Infrastructure/Configuration/Symfony/Service/serializer.php b/src/Report/Infrastructure/Configuration/Symfony/Service/serializer.php new file mode 100644 index 0000000..4bab5ea --- /dev/null +++ b/src/Report/Infrastructure/Configuration/Symfony/Service/serializer.php @@ -0,0 +1,13 @@ +services(); + + $services->set(InResourceRepresentationNormalizer::class) + ->tag('serializer.normalizer', ['priority' => 64]); +}; diff --git a/src/Trade/Infrastructure/ApiState/Processor/TransactionCreateProcessor.php b/src/Trade/Infrastructure/ApiState/Processor/TransactionCreateProcessor.php index 0133960..094e8c0 100644 --- a/src/Trade/Infrastructure/ApiState/Processor/TransactionCreateProcessor.php +++ b/src/Trade/Infrastructure/ApiState/Processor/TransactionCreateProcessor.php @@ -28,7 +28,7 @@ public function __construct( ) { } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []) + public function process($data, Operation $operation, array $uriVariables = [], array $context = []): TransactionResource { /** @var TransactionResource $data */ Assert::isInstanceOf($data, TransactionResource::class); diff --git a/symfony.lock b/symfony.lock index e9bb5b7..11a34cb 100644 --- a/symfony.lock +++ b/symfony.lock @@ -150,6 +150,18 @@ "tests/bootstrap.php" ] }, + "stof/doctrine-extensions-bundle": { + "version": "1.12", + "recipe": { + "repo": "github.com/symfony/recipes-contrib", + "branch": "main", + "version": "1.2", + "ref": "e805aba9eff5372e2d149a9ff56566769e22819d" + }, + "files": [ + "config/packages/stof_doctrine_extensions.yaml" + ] + }, "symfony/console": { "version": "6.1", "recipe": {