Skip to content

Commit

Permalink
DevelopmentKit resource
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Jul 26, 2023
1 parent 3c6eada commit d55d238
Show file tree
Hide file tree
Showing 26 changed files with 485 additions and 52 deletions.
34 changes: 25 additions & 9 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,51 @@
$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,
'modernize_types_casting' => true,
'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)
;
;
2 changes: 1 addition & 1 deletion migrations/Version20230719165100.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function up(Schema $schema): void
$film['name'],
$film['type']->value,
$film['speed'],
)
),
);
}
}
Expand Down
36 changes: 36 additions & 0 deletions migrations/Version20230726230348.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20230726230348 extends AbstractMigration
{
public function getDescription(): string
{
return 'Rename development_kit table to film_developments';
}

public function up(Schema $schema): void
{
$this->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');
}
}
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
};
14 changes: 8 additions & 6 deletions src/ApiPlatform/CallbackCollectionPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace App\ApiPlatform;

use ApiPlatform\State\Pagination\PaginatorInterface;
use Closure;
use IteratorAggregate;
use Traversable;

/**
* @template TInput of object
Expand All @@ -14,15 +16,15 @@
* @implements PaginatorInterface<TOutput>
* @implements IteratorAggregate<TOutput>
*/
readonly class CallbackCollectionPaginator implements PaginatorInterface, \IteratorAggregate
readonly class CallbackCollectionPaginator implements PaginatorInterface, IteratorAggregate
{
/**
* @param PaginatorInterface<TInput>&\IteratorAggregate<TInput> $paginator
* @param \Closure(TInput):TOutput $callback
* @param PaginatorInterface<TInput>&IteratorAggregate<TInput> $paginator
* @param Closure(TInput):TOutput $callback
*/
public function __construct(
private PaginatorInterface&\IteratorAggregate $paginator,
private \Closure $callback,
private PaginatorInterface&IteratorAggregate $paginator,
private Closure $callback,
) {
}

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/ApiPlatform/PartialCollectionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function supportsNormalization($data, $format = null, array $context = []
/**
* @param PaginatorInterface<object> $object
*
* @return array<string, mixed>
*
* @throws ExceptionInterface
*
* @return array<string, mixed>
*/
public function normalize($object, $format = null, array $context = []): array
{
Expand Down
17 changes: 17 additions & 0 deletions src/Dto/Development/DevelopmentKitOutputDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Dto\Development;

class DevelopmentKitOutputDto
{
public function __construct(
public string $id,
public string $name,
public string $type,
public int $developmentsCount,
public DevelopmentTimesOutputDto $times,
) {
}
}
25 changes: 25 additions & 0 deletions src/Dto/Development/DevelopmentTimesOutputDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Dto\Development;

class DevelopmentTimesOutputDto
{
public ?float $firstDeveloperTime = null;
public ?float $firstDeveloperMultiplier = null;
public ?float $reversalTime = null;
public ?float $reversalMultiplier = null;
public ?float $colorDeveloperTime = null;
public ?float $colorDeveloperMultiplier = null;
public ?float $preBleachTime = null;
public ?float $preBleachMultiplier = null;
public ?float $bleachTime = null;
public ?float $bleachMultiplier = null;
public ?float $fixerTime = null;
public ?float $fixerMultiplier = null;
public ?float $clearingTime = null;
public ?float $clearingMultiplier = null;
public ?float $secondDeveloperTime = null;
public ?float $secondDeveloperMultiplier = null;
}
17 changes: 15 additions & 2 deletions src/Entity/Development/DevelopmentKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

namespace App\Entity\Development;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Dto\Development\DevelopmentKitOutputDto;
use App\Enum\DevelopmentType;
use App\State\Provider\Development\DevelopmentKit\DevelopmentKitCollectionProvider;
use App\State\Provider\Development\DevelopmentKit\DevelopmentKitProvider;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
Expand All @@ -17,7 +23,14 @@
use Symfony\Component\Validator\Constraints as Assert;

#[Entity]
#[Table(name: 'development_kit')]
#[Table(name: 'development_kits')]
#[ApiResource(
operations: [
new Get(provider: DevelopmentKitProvider::class),
new GetCollection(provider: DevelopmentKitCollectionProvider::class),
],
output: DevelopmentKitOutputDto::class,
)]
class DevelopmentKit
{
#[Id]
Expand Down Expand Up @@ -46,7 +59,7 @@ class DevelopmentKit
#[Assert\Valid]
private DevelopmentKitTimes $developmentTimes;

public function __construct(string $name, string $id = null)
public function __construct(string $name, ?string $id = null)
{
$this->name = $name;
$this->id = $id ?? UuidV6::generate();
Expand Down
Loading

0 comments on commit d55d238

Please sign in to comment.