From d55d2383a47f27bbac35967489e3d3950d28caf6 Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Thu, 27 Jul 2023 01:12:53 +0200 Subject: [PATCH] DevelopmentKit resource --- .php-cs-fixer.dist.php | 34 ++- migrations/Version20230719165100.php | 2 +- migrations/Version20230726230348.php | 36 ++++ public/index.php | 2 +- .../CallbackCollectionPaginator.php | 14 +- .../PartialCollectionNormalizer.php | 4 +- .../Development/DevelopmentKitOutputDto.php | 17 ++ .../Development/DevelopmentTimesOutputDto.php | 25 +++ src/Entity/Development/DevelopmentKit.php | 17 +- .../Development/DevelopmentKitTimes.php | 194 +++++++++++++++++- src/Entity/Development/FilmDevelopment.php | 2 +- src/Entity/Film/Film.php | 2 +- src/Entity/User/Role.php | 2 +- src/Entity/User/User.php | 8 +- .../Development/DevelopmentKitMapper.php | 55 +++++ src/Mapper/Film/FilmMapper.php | 2 +- src/Mapper/UserMapper.php | 2 +- src/Security/AuthUserProvider.php | 5 +- src/Security/JWTCreatedListener.php | 10 +- .../DevelopmentKitCollectionProvider.php | 42 ++++ .../DevelopmentKit/DevelopmentKitProvider.php | 31 +++ .../Provider/Film/FilmCollectionProvider.php | 5 +- src/State/Provider/UserCollectionProvider.php | 3 +- .../Migrations/AbstractRoleMigration.php | 10 +- tests/extensions/SlowTestsExtension.php | 4 +- .../api/AuthenticatedWebTestCase.php | 9 +- 26 files changed, 485 insertions(+), 52 deletions(-) create mode 100644 migrations/Version20230726230348.php create mode 100644 src/Dto/Development/DevelopmentKitOutputDto.php create mode 100644 src/Dto/Development/DevelopmentTimesOutputDto.php create mode 100644 src/Mapper/Development/DevelopmentKitMapper.php create mode 100644 src/State/Provider/Development/DevelopmentKit/DevelopmentKitCollectionProvider.php create mode 100644 src/State/Provider/Development/DevelopmentKit/DevelopmentKitProvider.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 60c620f..e195981 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -3,18 +3,28 @@ $finder = (new PhpCsFixer\Finder()) ->in(__DIR__) ->exclude('var') + ->exclude('build') + ->exclude('vendor') ; return (new PhpCsFixer\Config()) ->setRules([ '@DoctrineAnnotation' => true, - '@PHP80Migration' => true, + '@PHP81Migration' => true, '@Symfony' => true, - 'array_syntax' => ['syntax' => 'short'], + 'align_multiline_comment' => true, 'array_indentation' => true, + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'return', 'throw', 'yield'], + ], 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, 'concat_space' => ['spacing' => 'one'], - 'function_to_constant' => true, + 'control_structure_continuation_position' => true, + 'declare_equal_normalize' => true, + 'declare_strict_types' => true, + 'function_declaration' => ['closure_function_spacing' => 'none'], + 'global_namespace_import' => true, 'implode_call' => true, 'is_null' => true, 'method_chaining_indentation' => true, @@ -22,16 +32,22 @@ 'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'], 'no_superfluous_elseif' => true, 'no_useless_else' => true, + 'no_useless_return' => true, + 'nullable_type_declaration_for_default_null_value' => true, + 'operator_linebreak' => true, 'phpdoc_align' => ['align' => 'left'], - 'phpdoc_separation' => false, - 'phpdoc_to_comment' => false, + 'phpdoc_line_span' => ['property' => 'single'], + 'phpdoc_order' => true, 'phpdoc_summary' => false, + 'phpdoc_to_comment' => false, 'psr_autoloading' => true, 'return_assignment' => true, - 'yoda_style' => false, - 'no_superfluous_phpdoc_tags' => false, + 'simplified_if_return' => true, + 'simplified_null_return' => true, 'single_line_throw' => false, - 'declare_strict_types' => true, + 'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arrays', 'arguments', 'parameters']], + 'yoda_style' => false, ]) + ->setRiskyAllowed(true) ->setFinder($finder) -; + ; diff --git a/migrations/Version20230719165100.php b/migrations/Version20230719165100.php index e73b323..498e3d4 100644 --- a/migrations/Version20230719165100.php +++ b/migrations/Version20230719165100.php @@ -53,7 +53,7 @@ public function up(Schema $schema): void $film['name'], $film['type']->value, $film['speed'], - ) + ), ); } } diff --git a/migrations/Version20230726230348.php b/migrations/Version20230726230348.php new file mode 100644 index 0000000..1112c01 --- /dev/null +++ b/migrations/Version20230726230348.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE film_developments DROP CONSTRAINT fk_50b275403a8e60ef'); + $this->addSql('CREATE TABLE development_kits (id VARCHAR(36) NOT NULL, name VARCHAR(128) NOT NULL, type VARCHAR(255) NOT NULL, untracked_developments INT DEFAULT 0 NOT NULL, development_times__first_developer_time DOUBLE PRECISION NOT NULL, development_times__first_developer_multiplier DOUBLE PRECISION NOT NULL, development_times__reversal_time DOUBLE PRECISION NOT NULL, development_times__reversal_multiplier DOUBLE PRECISION NOT NULL, development_times__color_developer_time DOUBLE PRECISION NOT NULL, development_times__color_developer_multiplier DOUBLE PRECISION NOT NULL, development_times__pre_bleach_time DOUBLE PRECISION NOT NULL, development_times__pre_bleach_multiplier DOUBLE PRECISION NOT NULL, development_times__bleach_time DOUBLE PRECISION NOT NULL, development_times__bleach_multiplier DOUBLE PRECISION NOT NULL, development_times__fixer_time DOUBLE PRECISION NOT NULL, development_times__fixer_multiplier DOUBLE PRECISION NOT NULL, development_times__clearing_time DOUBLE PRECISION NOT NULL, development_times__clearing_multiplier DOUBLE PRECISION NOT NULL, development_times__second_developer_time DOUBLE PRECISION NOT NULL, development_times__second_developer_multiplier DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_841ED2EC5E237E06 ON development_kits (name)'); + $this->addSql('DROP TABLE development_kit'); + $this->addSql('ALTER TABLE film_developments DROP CONSTRAINT FK_50B275403A8E60EF'); + $this->addSql('ALTER TABLE film_developments ADD CONSTRAINT FK_50B275403A8E60EF FOREIGN KEY (kit_id) REFERENCES development_kits (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE film_developments DROP CONSTRAINT FK_50B275403A8E60EF'); + $this->addSql('CREATE TABLE development_kit (id VARCHAR(36) NOT NULL, name VARCHAR(128) NOT NULL, type VARCHAR(255) NOT NULL, untracked_developments INT DEFAULT 0 NOT NULL, development_times__first_developer_time DOUBLE PRECISION NOT NULL, development_times__first_developer_multiplier DOUBLE PRECISION NOT NULL, development_times__reversal DOUBLE PRECISION NOT NULL, development_times__reversal_multiplier DOUBLE PRECISION NOT NULL, development_times__color_developer_time DOUBLE PRECISION NOT NULL, development_times__color_developer_multiplier DOUBLE PRECISION NOT NULL, development_times__pre_bleach_time DOUBLE PRECISION NOT NULL, development_times__pre_bleach_multiplier DOUBLE PRECISION NOT NULL, development_times__bleach_time DOUBLE PRECISION NOT NULL, development_times__bleach_multiplier DOUBLE PRECISION NOT NULL, development_times__fixer_time DOUBLE PRECISION NOT NULL, development_times__fixer_multiplier DOUBLE PRECISION NOT NULL, development_times__clearing_time DOUBLE PRECISION NOT NULL, development_times__clearing_multiplier DOUBLE PRECISION NOT NULL, development_times__second_developer_time DOUBLE PRECISION NOT NULL, development_times__second_developer_multiplier DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX uniq_aff942465e237e06 ON development_kit (name)'); + $this->addSql('DROP TABLE development_kits'); + $this->addSql('ALTER TABLE film_developments DROP CONSTRAINT fk_50b275403a8e60ef'); + $this->addSql('ALTER TABLE film_developments ADD CONSTRAINT fk_50b275403a8e60ef FOREIGN KEY (kit_id) REFERENCES development_kit (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } +} diff --git a/public/index.php b/public/index.php index c1e51e5..6566907 100644 --- a/public/index.php +++ b/public/index.php @@ -6,6 +6,6 @@ require_once dirname(__DIR__) . '/vendor/autoload_runtime.php'; -return function (array $context) { +return function(array $context) { return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); }; diff --git a/src/ApiPlatform/CallbackCollectionPaginator.php b/src/ApiPlatform/CallbackCollectionPaginator.php index 9a43f3d..e625ea5 100644 --- a/src/ApiPlatform/CallbackCollectionPaginator.php +++ b/src/ApiPlatform/CallbackCollectionPaginator.php @@ -5,7 +5,9 @@ namespace App\ApiPlatform; use ApiPlatform\State\Pagination\PaginatorInterface; +use Closure; use IteratorAggregate; +use Traversable; /** * @template TInput of object @@ -14,15 +16,15 @@ * @implements PaginatorInterface * @implements IteratorAggregate */ -readonly class CallbackCollectionPaginator implements PaginatorInterface, \IteratorAggregate +readonly class CallbackCollectionPaginator implements PaginatorInterface, IteratorAggregate { /** - * @param PaginatorInterface&\IteratorAggregate $paginator - * @param \Closure(TInput):TOutput $callback + * @param PaginatorInterface&IteratorAggregate $paginator + * @param Closure(TInput):TOutput $callback */ public function __construct( - private PaginatorInterface&\IteratorAggregate $paginator, - private \Closure $callback, + private PaginatorInterface&IteratorAggregate $paginator, + private Closure $callback, ) { } @@ -51,7 +53,7 @@ public function getItemsPerPage(): float return $this->paginator->getItemsPerPage(); } - public function getIterator(): \Traversable + public function getIterator(): Traversable { $fn = $this->callback; foreach ($this->paginator->getIterator() as $key => $outputItem) { diff --git a/src/ApiPlatform/PartialCollectionNormalizer.php b/src/ApiPlatform/PartialCollectionNormalizer.php index c73f4cd..7acc683 100644 --- a/src/ApiPlatform/PartialCollectionNormalizer.php +++ b/src/ApiPlatform/PartialCollectionNormalizer.php @@ -29,9 +29,9 @@ public function supportsNormalization($data, $format = null, array $context = [] /** * @param PaginatorInterface $object * - * @return array - * * @throws ExceptionInterface + * + * @return array */ public function normalize($object, $format = null, array $context = []): array { diff --git a/src/Dto/Development/DevelopmentKitOutputDto.php b/src/Dto/Development/DevelopmentKitOutputDto.php new file mode 100644 index 0000000..55a4afb --- /dev/null +++ b/src/Dto/Development/DevelopmentKitOutputDto.php @@ -0,0 +1,17 @@ +name = $name; $this->id = $id ?? UuidV6::generate(); diff --git a/src/Entity/Development/DevelopmentKitTimes.php b/src/Entity/Development/DevelopmentKitTimes.php index 92c0642..0cee230 100644 --- a/src/Entity/Development/DevelopmentKitTimes.php +++ b/src/Entity/Development/DevelopmentKitTimes.php @@ -20,7 +20,7 @@ class DevelopmentKitTimes #[Assert\PositiveOrZero] #[Column(scale: 2)] - private ?float $reversal = null; + private ?float $reversalTime = null; #[Assert\PositiveOrZero] #[Column(scale: 2)] private ?float $reversalMultiplier = null; @@ -66,4 +66,196 @@ class DevelopmentKitTimes #[Assert\PositiveOrZero] #[Column(scale: 2)] private ?float $secondDeveloperMultiplier = null; + + public function getFirstDeveloperTime(): ?float + { + return $this->firstDeveloperTime; + } + + public function setFirstDeveloperTime(?float $firstDeveloperTime): self + { + $this->firstDeveloperTime = $firstDeveloperTime; + + return $this; + } + + public function getFirstDeveloperMultiplier(): ?float + { + return $this->firstDeveloperMultiplier; + } + + public function setFirstDeveloperMultiplier(?float $firstDeveloperMultiplier): self + { + $this->firstDeveloperMultiplier = $firstDeveloperMultiplier; + + return $this; + } + + public function getReversalTime(): ?float + { + return $this->reversalTime; + } + + public function setReversalTime(?float $reversalTime): self + { + $this->reversalTime = $reversalTime; + + return $this; + } + + public function getReversalMultiplier(): ?float + { + return $this->reversalMultiplier; + } + + public function setReversalMultiplier(?float $reversalMultiplier): self + { + $this->reversalMultiplier = $reversalMultiplier; + + return $this; + } + + public function getColorDeveloperTime(): ?float + { + return $this->colorDeveloperTime; + } + + public function setColorDeveloperTime(?float $colorDeveloperTime): self + { + $this->colorDeveloperTime = $colorDeveloperTime; + + return $this; + } + + public function getColorDeveloperMultiplier(): ?float + { + return $this->colorDeveloperMultiplier; + } + + public function setColorDeveloperMultiplier(?float $colorDeveloperMultiplier): self + { + $this->colorDeveloperMultiplier = $colorDeveloperMultiplier; + + return $this; + } + + public function getPreBleachTime(): ?float + { + return $this->preBleachTime; + } + + public function setPreBleachTime(?float $preBleachTime): self + { + $this->preBleachTime = $preBleachTime; + + return $this; + } + + public function getPreBleachMultiplier(): ?float + { + return $this->preBleachMultiplier; + } + + public function setPreBleachMultiplier(?float $preBleachMultiplier): self + { + $this->preBleachMultiplier = $preBleachMultiplier; + + return $this; + } + + public function getBleachTime(): ?float + { + return $this->bleachTime; + } + + public function setBleachTime(?float $bleachTime): self + { + $this->bleachTime = $bleachTime; + + return $this; + } + + public function getBleachMultiplier(): ?float + { + return $this->bleachMultiplier; + } + + public function setBleachMultiplier(?float $bleachMultiplier): self + { + $this->bleachMultiplier = $bleachMultiplier; + + return $this; + } + + public function getFixerTime(): ?float + { + return $this->fixerTime; + } + + public function setFixerTime(?float $fixerTime): self + { + $this->fixerTime = $fixerTime; + + return $this; + } + + public function getFixerMultiplier(): ?float + { + return $this->fixerMultiplier; + } + + public function setFixerMultiplier(?float $fixerMultiplier): self + { + $this->fixerMultiplier = $fixerMultiplier; + + return $this; + } + + public function getClearingTime(): ?float + { + return $this->clearingTime; + } + + public function setClearingTime(?float $clearingTime): self + { + $this->clearingTime = $clearingTime; + + return $this; + } + + public function getClearingMultiplier(): ?float + { + return $this->clearingMultiplier; + } + + public function setClearingMultiplier(?float $clearingMultiplier): self + { + $this->clearingMultiplier = $clearingMultiplier; + + return $this; + } + + public function getSecondDeveloperTime(): ?float + { + return $this->secondDeveloperTime; + } + + public function setSecondDeveloperTime(?float $secondDeveloperTime): self + { + $this->secondDeveloperTime = $secondDeveloperTime; + + return $this; + } + + public function getSecondDeveloperMultiplier(): ?float + { + return $this->secondDeveloperMultiplier; + } + + public function setSecondDeveloperMultiplier(?float $secondDeveloperMultiplier): self + { + $this->secondDeveloperMultiplier = $secondDeveloperMultiplier; + + return $this; + } } diff --git a/src/Entity/Development/FilmDevelopment.php b/src/Entity/Development/FilmDevelopment.php index 7faa893..ef67e80 100644 --- a/src/Entity/Development/FilmDevelopment.php +++ b/src/Entity/Development/FilmDevelopment.php @@ -34,7 +34,7 @@ class FilmDevelopment #[ManyToOne] private Film $film; - public function __construct(string $id = null) + public function __construct(?string $id = null) { $this->id = $id ?? UuidV6::generate(); } diff --git a/src/Entity/Film/Film.php b/src/Entity/Film/Film.php index e1e0ffa..f3a150b 100644 --- a/src/Entity/Film/Film.php +++ b/src/Entity/Film/Film.php @@ -51,7 +51,7 @@ class Film #[Assert\Positive] private int $speed; - public function __construct(string $id = null) + public function __construct(?string $id = null) { $this->id = $id ?? UuidV6::generate(); } diff --git a/src/Entity/User/Role.php b/src/Entity/User/Role.php index ea86650..0a3ce96 100644 --- a/src/Entity/User/Role.php +++ b/src/Entity/User/Role.php @@ -30,7 +30,7 @@ class Role #[Assert\Length(max: 255)] private string $description; - public function __construct(string $name, string $description, string $id = null) + public function __construct(string $name, string $description, ?string $id = null) { $this->id = $id ?? UuidV6::generate(); $this->name = $name; diff --git a/src/Entity/User/User.php b/src/Entity/User/User.php index 30eacbd..9e70a3c 100644 --- a/src/Entity/User/User.php +++ b/src/Entity/User/User.php @@ -31,7 +31,7 @@ new Get(security: "is_granted('ROLE_DISPLAY_USERS')", provider: UserItemProvider::class), new GetCollection(security: "is_granted('ROLE_DISPLAY_USERS')", provider: UserCollectionProvider::class), ], - output: UserOutputDto::class + output: UserOutputDto::class, )] #[Entity] #[Table(name: 'users')] @@ -41,13 +41,13 @@ 'email' => 'ipartial', 'username' => 'ipartial', 'roles.name' => 'ipartial', - ] + ], )] #[ApiFilter( BooleanFilter::class, properties: [ 'systemUser', - ] + ], )] #[Index(columns: ['username'])] class User implements UserInterface, PasswordAuthenticatedUserInterface @@ -81,7 +81,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ManyToMany(targetEntity: Role::class)] private Collection $roles; - public function __construct(string $email, string $username, string $password, string $id = null) + public function __construct(string $email, string $username, string $password, ?string $id = null) { $this->id = $id ?? UuidV6::generate(); $this->email = $email; diff --git a/src/Mapper/Development/DevelopmentKitMapper.php b/src/Mapper/Development/DevelopmentKitMapper.php new file mode 100644 index 0000000..8b0f3e9 --- /dev/null +++ b/src/Mapper/Development/DevelopmentKitMapper.php @@ -0,0 +1,55 @@ +getId(), + $kit->getName(), + $kit->getType()->value, + $kit->getUntrackedDevelopments() + $kit->getDevelopments()->count(), // TODO: move to service or provider of some sort + $this->mapDevelopmentKitTimesToOutputDto($kit->getDevelopmentTimes()), + ); + } + + public function mapDevelopmentKitTimesToOutputDto(DevelopmentKitTimes $times): DevelopmentTimesOutputDto + { + $dto = new DevelopmentTimesOutputDto(); + + $dto->firstDeveloperTime = $times->getFirstDeveloperTime(); + $dto->firstDeveloperMultiplier = $times->getFirstDeveloperMultiplier(); + + $dto->reversalTime = $times->getReversalTime(); + $dto->reversalMultiplier = $times->getReversalMultiplier(); + + $dto->colorDeveloperTime = $times->getColorDeveloperTime(); + $dto->colorDeveloperMultiplier = $times->getColorDeveloperMultiplier(); + + $dto->preBleachTime = $times->getPreBleachTime(); + $dto->preBleachMultiplier = $times->getPreBleachMultiplier(); + + $dto->bleachTime = $times->getBleachTime(); + $dto->bleachMultiplier = $times->getBleachMultiplier(); + + $dto->fixerTime = $times->getFixerTime(); + $dto->fixerMultiplier = $times->getFixerMultiplier(); + + $dto->clearingTime = $times->getClearingTime(); + $dto->clearingMultiplier = $times->getClearingMultiplier(); + + $dto->secondDeveloperTime = $times->getSecondDeveloperTime(); + $dto->secondDeveloperMultiplier = $times->getSecondDeveloperMultiplier(); + + return $dto; + } +} diff --git a/src/Mapper/Film/FilmMapper.php b/src/Mapper/Film/FilmMapper.php index df77d86..953faff 100644 --- a/src/Mapper/Film/FilmMapper.php +++ b/src/Mapper/Film/FilmMapper.php @@ -15,7 +15,7 @@ public function mapFilmToOutputDto(Film $film): FilmOutputDto $film->getId(), $film->getName(), $film->getType()->value, - $film->getSpeed() + $film->getSpeed(), ); } } diff --git a/src/Mapper/UserMapper.php b/src/Mapper/UserMapper.php index 84a4622..e1615a1 100644 --- a/src/Mapper/UserMapper.php +++ b/src/Mapper/UserMapper.php @@ -24,7 +24,7 @@ public function mapUserToOutputDto(User $user): UserOutputDto $dto->email = $user->getEmail(); $dto->systemUser = $user->isSystemUser(); $dto->roles = $user->getRoleObjects()->map( - fn (Role $role) => $this->userRoleMapper->mapRoleToOutputDto($role) + fn (Role $role) => $this->userRoleMapper->mapRoleToOutputDto($role), )->toArray(); return $dto; diff --git a/src/Security/AuthUserProvider.php b/src/Security/AuthUserProvider.php index f618c47..19aaa89 100644 --- a/src/Security/AuthUserProvider.php +++ b/src/Security/AuthUserProvider.php @@ -7,6 +7,7 @@ use App\Entity\User\User; use App\Exception\UserNotFoundException; use App\Repository\UserRepository; +use Exception; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; @@ -17,7 +18,7 @@ public function __construct(private readonly UserRepository $userRepository) } /** - * @throws \Exception + * @throws Exception */ public function refreshUser(UserInterface $user): UserInterface { @@ -30,7 +31,7 @@ public function supportsClass(string $class): bool } /** - * @throws \Exception + * @throws Exception */ public function loadUserByIdentifier(string $identifier): UserInterface { diff --git a/src/Security/JWTCreatedListener.php b/src/Security/JWTCreatedListener.php index 9136c5d..f0874f7 100644 --- a/src/Security/JWTCreatedListener.php +++ b/src/Security/JWTCreatedListener.php @@ -5,6 +5,8 @@ namespace App\Security; use App\Entity\User\User; +use DateInterval; +use DateTime; use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent; class JWTCreatedListener @@ -17,17 +19,17 @@ public function onJWTCreated(JWTCreatedEvent $event): void } $event->setData( - array_merge($event->getData(), $this->getPayloadData($user)) + array_merge($event->getData(), $this->getPayloadData($user)), ); } private function getPayloadData(User $user): array { - $expiration = new \DateTime('now'); + $expiration = new DateTime('now'); if ($user->isSystemUser()) { - $expiration->add(new \DateInterval('PT1Y')); + $expiration->add(new DateInterval('PT1Y')); } else { - $expiration->add(new \DateInterval('PT10M')); + $expiration->add(new DateInterval('PT10M')); } return [ diff --git a/src/State/Provider/Development/DevelopmentKit/DevelopmentKitCollectionProvider.php b/src/State/Provider/Development/DevelopmentKit/DevelopmentKitCollectionProvider.php new file mode 100644 index 0000000..46e2b38 --- /dev/null +++ b/src/State/Provider/Development/DevelopmentKit/DevelopmentKitCollectionProvider.php @@ -0,0 +1,42 @@ + $uriVariables + * @param array> $context + * + * @return CallbackCollectionPaginator + */ + public function provide(Operation $operation, array $uriVariables = [], array $context = []): PartialPaginatorInterface + { + /** @var PaginatorInterface&IteratorAggregate $result */ + $result = $this->collectionProvider->provide($operation, $uriVariables, $context); + + return new CallbackCollectionPaginator( + $result, + fn (DevelopmentKit $kit) => $this->mapper->mapDevelopmentKitToOutputDto($kit), + ); + } +} diff --git a/src/State/Provider/Development/DevelopmentKit/DevelopmentKitProvider.php b/src/State/Provider/Development/DevelopmentKit/DevelopmentKitProvider.php new file mode 100644 index 0000000..b2bc5f3 --- /dev/null +++ b/src/State/Provider/Development/DevelopmentKit/DevelopmentKitProvider.php @@ -0,0 +1,31 @@ +itemProvider->provide($operation, $uriVariables, $context); + if ($kit === null) { + return null; + } + + return $this->userDtoMapper->mapDevelopmentKitToOutputDto($kit); + } +} diff --git a/src/State/Provider/Film/FilmCollectionProvider.php b/src/State/Provider/Film/FilmCollectionProvider.php index 46ec509..2784aa8 100644 --- a/src/State/Provider/Film/FilmCollectionProvider.php +++ b/src/State/Provider/Film/FilmCollectionProvider.php @@ -13,6 +13,7 @@ use App\Dto\Film\FilmOutputDto; use App\Entity\Film\Film; use App\Mapper\Film\FilmMapper; +use IteratorAggregate; class FilmCollectionProvider implements ProviderInterface { @@ -30,12 +31,12 @@ public function __construct( */ public function provide(Operation $operation, array $uriVariables = [], array $context = []): PartialPaginatorInterface { - /** @var PaginatorInterface&\IteratorAggregate $result */ + /** @var PaginatorInterface&IteratorAggregate $result */ $result = $this->collectionProvider->provide($operation, $uriVariables, $context); return new CallbackCollectionPaginator( $result, - fn (Film $productionOrder) => $this->mapper->mapFilmToOutputDto($productionOrder), + fn (Film $film) => $this->mapper->mapFilmToOutputDto($film), ); } } diff --git a/src/State/Provider/UserCollectionProvider.php b/src/State/Provider/UserCollectionProvider.php index 3dfc380..544f577 100644 --- a/src/State/Provider/UserCollectionProvider.php +++ b/src/State/Provider/UserCollectionProvider.php @@ -13,6 +13,7 @@ use App\Dto\UserOutputDto; use App\Entity\User\User; use App\Mapper\UserMapper; +use IteratorAggregate; class UserCollectionProvider implements ProviderInterface { @@ -30,7 +31,7 @@ public function __construct( */ public function provide(Operation $operation, array $uriVariables = [], array $context = []): PartialPaginatorInterface { - /** @var PaginatorInterface&\IteratorAggregate $result */ + /** @var PaginatorInterface&IteratorAggregate $result */ $result = $this->collectionProvider->provide($operation, $uriVariables, $context); return new CallbackCollectionPaginator( diff --git a/src/Utils/Migrations/AbstractRoleMigration.php b/src/Utils/Migrations/AbstractRoleMigration.php index 5996b94..55e86dd 100644 --- a/src/Utils/Migrations/AbstractRoleMigration.php +++ b/src/Utils/Migrations/AbstractRoleMigration.php @@ -32,7 +32,7 @@ public function up(Schema $schema): void PredefinedRoles::ROLE_IDS[$role], $role, PredefinedRoles::ROLE_DESCRIPTIONS[$role], - ) + ), ); } @@ -43,7 +43,7 @@ public function up(Schema $schema): void "INSERT INTO user_role(user_id, role_id) VALUES ((SELECT id FROM users WHERE username = '%s'), '%s')", $user, PredefinedRoles::ROLE_IDS[$role], - ) + ), ); } } @@ -58,7 +58,7 @@ public function down(Schema $schema): void "REMOVE FROM user_role WHERE user_id = (SELECT id FROM users WHERE email = '%s') AND role_id = %s", $user, PredefinedRoles::ROLE_IDS[$role], - ) + ), ); } } @@ -67,8 +67,8 @@ public function down(Schema $schema): void $this->addSql( sprintf( "REMOVE FROM user_roles WHERE id = '%s'", - PredefinedRoles::ROLE_IDS[$role] - ) + PredefinedRoles::ROLE_IDS[$role], + ), ); } } diff --git a/tests/extensions/SlowTestsExtension.php b/tests/extensions/SlowTestsExtension.php index 702e775..110aa47 100644 --- a/tests/extensions/SlowTestsExtension.php +++ b/tests/extensions/SlowTestsExtension.php @@ -9,9 +9,7 @@ class SlowTestsExtension implements AfterTestHook, AfterLastTestHook { - /** - * @var array - */ + /** @var array */ private array $slow = []; public function __construct(private readonly int $slowThreshold = 500, private readonly int $reportLength = 10) diff --git a/tests/functional/api/AuthenticatedWebTestCase.php b/tests/functional/api/AuthenticatedWebTestCase.php index eee482e..4b610e3 100644 --- a/tests/functional/api/AuthenticatedWebTestCase.php +++ b/tests/functional/api/AuthenticatedWebTestCase.php @@ -6,6 +6,7 @@ use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use ApiPlatform\Symfony\Bundle\Test\Response as ApiPlatformResponse; +use Exception; use Lexik\Bundle\JWTAuthenticationBundle\Security\User\JWTUser; use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; @@ -21,7 +22,7 @@ abstract class AuthenticatedWebTestCase extends ApiTestCase /** * @param string[] $roles * - * @throws \Exception + * @throws Exception */ protected function createClientWithRoles(array $roles): HttpClientInterface { @@ -36,7 +37,7 @@ private function createTokenClient(string $token): HttpClientInterface 'auth_bearer' => $token, 'base_uri' => 'https://localhost', 'headers' => self::GET_JSON_HEADERS, - ] + ], ); $client->disableReboot(); @@ -46,7 +47,7 @@ private function createTokenClient(string $token): HttpClientInterface /** * @param string[] $roles * - * @throws \Exception + * @throws Exception */ private static function createTokenWithRoles(array $roles): string { @@ -60,7 +61,7 @@ private static function createTokenWithRoles(array $roles): string 'id' => $user->getUserIdentifier(), 'roles' => $user->getRoles(), 'username' => 'admin', - ] + ], ); }