diff --git a/src/Controller/BrandController.php b/src/Controller/BrandController.php index 9832b7d..80b2016 100644 --- a/src/Controller/BrandController.php +++ b/src/Controller/BrandController.php @@ -1,4 +1,4 @@ -itemListView('brands', [ - 'name' => 'asc' - ]); + return $this->itemListView('brands', [ + 'name' => 'asc', + ]); } #[Route('/new', name: 'brand_new', methods: ['GET', 'POST'])] public function new(Request $request): Response { - return $this->itemCreate($request, 'brand'); + return $this->itemCreate($request, 'brand'); } #[Route('/{id}', name: 'brand_show', methods: ['GET'])] public function show(Brand $brand): Response { - return $this->itemView($brand, 'brand'); + return $this->itemView($brand, 'brand'); } #[Route('/{id}/edit', name: 'brand_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Brand $brand): Response { - return $this->itemUpdate($request, $brand, 'brand'); -// -// $form = $this->createForm(BrandType::class, $brand); -// $form->handleRequest($request); -// -// if ($form->isSubmitted() && $form->isValid()) { -// $entityManager->flush(); -// -// return $this->redirectToRoute('brand_index', [], Response::HTTP_SEE_OTHER); -// } -// -// return $this->renderForm('brand/edit.html.twig', [ -// 'brand' => $brand, -// 'form' => $form, -// ]); + return $this->itemUpdate($request, $brand, 'brand'); } #[Route('/{id}', name: 'brand_delete', methods: ['POST'])] public function delete(Request $request, Brand $brand): Response { - return $this->deleteCSRF($request, $brand); + return $this->deleteCSRF($request, $brand); } } diff --git a/src/Controller/CameraController.php b/src/Controller/CameraController.php index 8c5d8f9..e4722c9 100644 --- a/src/Controller/CameraController.php +++ b/src/Controller/CameraController.php @@ -4,10 +4,8 @@ namespace App\Controller; use App\Entity\Camera; use App\Form\CameraType; -use App\Traits\DeleteFormTrait; -use App\Traits\FormControllerTrait; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\ORMInvalidArgumentException; +use App\Traits\{DeleteFormTrait, FormControllerTrait}; +use Doctrine\ORM\{EntityManagerInterface, ORMInvalidArgumentException}; use LogicException; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\FormInterface; @@ -21,12 +19,12 @@ use Symfony\Component\Routing\Annotation\Route; class CameraController extends AbstractController { use FormControllerTrait; - use DeleteFormTrait; + use DeleteFormTrait; - protected const ENTITY = Camera::class; - protected const TEMPLATE_PATH = 'camera/'; - protected const ROUTE_PREFIX = 'camera_'; - protected const FORM = CameraType::class; + protected const ENTITY = Camera::class; + protected const TEMPLATE_PATH = 'camera/'; + protected const ROUTE_PREFIX = 'camera_'; + protected const FORM = CameraType::class; public function __construct(private readonly EntityManagerInterface $entityManager) { @@ -69,7 +67,7 @@ class CameraController extends AbstractController #[Route(path: '/new', name: 'camera_new', methods: ['GET', 'POST'])] public function newAction(Request $request): RedirectResponse|Response { - return $this->itemCreate($request,'camera'); + return $this->itemCreate($request, 'camera'); } /** @@ -78,7 +76,7 @@ class CameraController extends AbstractController #[Route(path: '/{id}', name: 'camera_show', methods: ['GET'])] public function showAction(Camera $camera): Response { - return $this->itemView($camera,'camera'); + return $this->itemView($camera, 'camera'); } /** @@ -89,7 +87,7 @@ class CameraController extends AbstractController #[Route(path: '/{id}/edit', name: 'camera_edit', methods: ['GET', 'POST'])] public function editAction(Request $request, Camera $camera): RedirectResponse|Response { - return $this->itemUpdate($request, $camera,'camera'); + return $this->itemUpdate($request, $camera, 'camera'); } /** @@ -97,7 +95,7 @@ class CameraController extends AbstractController * * @throws LogicException */ - #[Route(path: '/{id}', name: 'camera_delete', methods: ['POST','DELETE'])] + #[Route(path: '/{id}', name: 'camera_delete', methods: ['POST', 'DELETE'])] public function deleteAction(Request $request, Camera $camera): RedirectResponse { return $this->itemDelete($request, $camera); diff --git a/src/Controller/CameraTypeController.php b/src/Controller/CameraTypeController.php index 64b1aec..e15ba0a 100644 --- a/src/Controller/CameraTypeController.php +++ b/src/Controller/CameraTypeController.php @@ -4,8 +4,7 @@ namespace App\Controller; use App\Entity\CameraType; use App\Form\CameraTypeType; -use App\Traits\DeleteFormTrait; -use App\Traits\FormControllerTrait; +use App\Traits\{DeleteFormTrait, FormControllerTrait}; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response}; @@ -15,12 +14,12 @@ use Symfony\Component\Routing\Annotation\Route; class CameraTypeController extends AbstractController { use FormControllerTrait; - use DeleteFormTrait; + use DeleteFormTrait; - protected const ENTITY = CameraType::class; - protected const TEMPLATE_PATH = 'cameratype/'; - protected const ROUTE_PREFIX = 'camera-type_'; - protected const FORM = CameraTypeType::class; + protected const ENTITY = CameraType::class; + protected const TEMPLATE_PATH = 'cameratype/'; + protected const ROUTE_PREFIX = 'camera-type_'; + protected const FORM = CameraTypeType::class; public function __construct(private readonly EntityManagerInterface $entityManager) { @@ -43,7 +42,7 @@ class CameraTypeController extends AbstractController #[Route(path: '/new', name: 'camera-type_new', methods: ['GET', 'POST'])] public function newAction(Request $request): Response { - return $this->itemCreate($request, 'cameraType'); + return $this->itemCreate($request, 'cameraType'); } /** @@ -52,7 +51,7 @@ class CameraTypeController extends AbstractController #[Route(path: '/{id}', name: 'camera-type_show', methods: ['GET'])] public function showAction(CameraType $cameraType): Response { - return $this->itemView($cameraType, 'cameraType'); + return $this->itemView($cameraType, 'cameraType'); } /** diff --git a/src/Controller/FilmController.php b/src/Controller/FilmController.php index e0fc9a5..1100285 100644 --- a/src/Controller/FilmController.php +++ b/src/Controller/FilmController.php @@ -4,8 +4,7 @@ namespace App\Controller; use App\Entity\Film; use App\Form\FilmType; -use App\Traits\DeleteFormTrait; -use App\Traits\FormControllerTrait; +use App\Traits\{DeleteFormTrait, FormControllerTrait}; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\EntityManagerInterface; use LogicException; @@ -20,12 +19,12 @@ use Symfony\Component\Routing\Annotation\Route; class FilmController extends AbstractController { use FormControllerTrait; - use DeleteFormTrait; + use DeleteFormTrait; - protected const ENTITY = Film::class; - protected const TEMPLATE_PATH = 'film/'; - protected const ROUTE_PREFIX = 'film_'; - protected const FORM = FilmType::class; + protected const ENTITY = Film::class; + protected const TEMPLATE_PATH = 'film/'; + protected const ROUTE_PREFIX = 'film_'; + protected const FORM = FilmType::class; public function __construct(private readonly EntityManagerInterface $entityManager) { @@ -95,7 +94,7 @@ class FilmController extends AbstractController * * @throws LogicException */ - #[Route(path: '/{id}', name: 'film_delete', methods: ['POST','DELETE'])] + #[Route(path: '/{id}', name: 'film_delete', methods: ['POST', 'DELETE'])] public function deleteAction(Request $request, Film $film): RedirectResponse { return $this->itemDelete($request, $film); diff --git a/src/Controller/FlashController.php b/src/Controller/FlashController.php index bca9e77..d9beaec 100644 --- a/src/Controller/FlashController.php +++ b/src/Controller/FlashController.php @@ -4,11 +4,9 @@ namespace App\Controller; use App\Entity\Flash; use App\Form\FlashType; -use App\Traits\DeleteFormTrait; -use App\Traits\FormControllerTrait; +use App\Traits\{DeleteFormTrait, FormControllerTrait}; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response}; use Symfony\Component\Routing\Annotation\Route; @@ -19,12 +17,12 @@ use Symfony\Component\Routing\Annotation\Route; class FlashController extends AbstractController { use FormControllerTrait; - use DeleteFormTrait; + use DeleteFormTrait; - protected const ENTITY = Flash::class; - protected const TEMPLATE_PATH = 'flash/'; - protected const ROUTE_PREFIX = 'flash_'; - protected const FORM = FlashType::class; + protected const ENTITY = Flash::class; + protected const TEMPLATE_PATH = 'flash/'; + protected const ROUTE_PREFIX = 'flash_'; + protected const FORM = FlashType::class; public function __construct(private readonly EntityManagerInterface $entityManager) { @@ -45,7 +43,7 @@ class FlashController extends AbstractController #[Route(path: '/new', name: 'flash_new', methods: ['GET', 'POST'])] public function newAction(Request $request): RedirectResponse|Response { - return $this->itemCreate($request,'flash'); + return $this->itemCreate($request, 'flash'); } /** @@ -54,7 +52,7 @@ class FlashController extends AbstractController #[Route(path: '/{id}', name: 'flash_show', methods: ['GET'])] public function showAction(Flash $flash): Response { - return $this->itemView($flash,'flash'); + return $this->itemView($flash, 'flash'); } /** diff --git a/src/Controller/GpuCoreController.php b/src/Controller/GpuCoreController.php index 2bc370c..c96d0ab 100644 --- a/src/Controller/GpuCoreController.php +++ b/src/Controller/GpuCoreController.php @@ -1,4 +1,4 @@ -indexView('gpu_cores', [ - 'brand' => 'asc', - 'architecture' => 'asc', - 'name' => 'asc', - 'variant' => 'asc', - ]); + return $this->indexView('gpu_cores', [ + 'brand' => 'asc', + 'architecture' => 'asc', + 'name' => 'asc', + 'variant' => 'asc', + ]); } #[Route('/new', name: 'gpu-core_new', methods: ['GET', 'POST'])] public function new(Request $request): Response { - return $this->itemCreate($request, 'gpu_core'); + return $this->itemCreate($request, 'gpu_core'); } #[Route('/{id}', name: 'gpu-core_show', methods: ['GET'])] public function show(GpuCore $gPUCore): Response { - return $this->itemView($gPUCore, 'gpu_core'); + return $this->itemView($gPUCore, 'gpu_core'); } #[Route('/{id}/edit', name: 'gpu-core_edit', methods: ['GET', 'POST'])] public function edit(Request $request, GpuCore $gPUCore): Response { - return $this->itemUpdate($request, $gPUCore, 'gpu_core'); + return $this->itemUpdate($request, $gPUCore, 'gpu_core'); } #[Route('/{id}', name: 'gpu-core_delete', methods: ['POST'])] public function delete(Request $request, GpuCore $gPUCore, EntityManagerInterface $entityManager): Response { - if ($this->isCsrfTokenValid('delete'.$gPUCore->getId(), $request->request->get('_token'))) { + if ($this->isCsrfTokenValid('delete' . $gPUCore->getId(), $request->request->get('_token'))) { $entityManager->remove($gPUCore); $entityManager->flush(); } diff --git a/src/Controller/LensesController.php b/src/Controller/LensesController.php index 856869f..6e8ea13 100644 --- a/src/Controller/LensesController.php +++ b/src/Controller/LensesController.php @@ -4,8 +4,7 @@ namespace App\Controller; use App\Entity\Lenses; use App\Form\LensesType; -use App\Traits\DeleteFormTrait; -use App\Traits\FormControllerTrait; +use App\Traits\{DeleteFormTrait, FormControllerTrait}; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\FormInterface; @@ -19,12 +18,12 @@ use Symfony\Component\Routing\Annotation\Route; class LensesController extends AbstractController { use FormControllerTrait; - use DeleteFormTrait; + use DeleteFormTrait; - protected const ENTITY = Lenses::class; - protected const TEMPLATE_PATH = 'lenses/'; - protected const ROUTE_PREFIX = 'lens_'; - protected const FORM = LensesType::class; + protected const ENTITY = Lenses::class; + protected const TEMPLATE_PATH = 'lenses/'; + protected const ROUTE_PREFIX = 'lens_'; + protected const FORM = LensesType::class; public function __construct(private readonly EntityManagerInterface $entityManager) { @@ -67,7 +66,7 @@ class LensesController extends AbstractController #[Route(path: '/new', name: 'lens_new', methods: ['GET', 'POST'])] public function newAction(Request $request): RedirectResponse|Response { - return $this->itemCreate($request,'lense'); + return $this->itemCreate($request, 'lense'); } /** @@ -104,7 +103,7 @@ class LensesController extends AbstractController /** * Deletes a lens entity. */ - #[Route(path: '/{id}', name: 'lens_delete', methods: ['POST','DELETE'])] + #[Route(path: '/{id}', name: 'lens_delete', methods: ['POST', 'DELETE'])] public function deleteAction(Request $request, Lenses $lens): RedirectResponse { return $this->itemDelete($request, $lens); diff --git a/src/Controller/PreviouslyOwnedCameraController.php b/src/Controller/PreviouslyOwnedCameraController.php index e5d0023..2e5cdab 100644 --- a/src/Controller/PreviouslyOwnedCameraController.php +++ b/src/Controller/PreviouslyOwnedCameraController.php @@ -5,8 +5,7 @@ namespace App\Controller; use App\Entity\PreviouslyOwnedCamera; use App\Form\PreviouslyOwnedCameraType; use App\Traits\FormControllerTrait; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\ORMInvalidArgumentException; +use Doctrine\ORM\{EntityManagerInterface, ORMInvalidArgumentException}; use LogicException; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\FormInterface; @@ -22,10 +21,10 @@ class PreviouslyOwnedCameraController extends AbstractController { use FormControllerTrait; - protected const ENTITY = PreviouslyOwnedCamera::class; - protected const TEMPLATE_PATH = 'previouslyownedcamera/'; - protected const ROUTE_PREFIX = 'previously-owned-camera_'; - protected const FORM = PreviouslyOwnedCameraType::class; + protected const ENTITY = PreviouslyOwnedCamera::class; + protected const TEMPLATE_PATH = 'previouslyownedcamera/'; + protected const ROUTE_PREFIX = 'previously-owned-camera_'; + protected const FORM = PreviouslyOwnedCameraType::class; public function __construct(private readonly EntityManagerInterface $entityManager) { @@ -39,7 +38,7 @@ class PreviouslyOwnedCameraController extends AbstractController #[Route(path: '/', name: 'previously-owned-camera_index', methods: ['GET'])] public function indexAction(): Response { - return $this->itemListView( 'previouslyOwnedCameras', [ + return $this->itemListView('previouslyOwnedCameras', [ 'brand' => 'ASC', 'mount' => 'ASC', 'model' => 'ASC', diff --git a/src/Controller/PreviouslyOwnedFlashController.php b/src/Controller/PreviouslyOwnedFlashController.php index 6000a3a..23890ca 100644 --- a/src/Controller/PreviouslyOwnedFlashController.php +++ b/src/Controller/PreviouslyOwnedFlashController.php @@ -18,10 +18,10 @@ class PreviouslyOwnedFlashController extends AbstractController { use FormControllerTrait; - protected const ENTITY = PreviouslyOwnedFlash::class; - protected const ROUTE_PREFIX = 'previously-owned-flash_'; - protected const TEMPLATE_PATH = 'previouslyownedflash/'; - protected const FORM = PreviouslyOwnedFlashType::class; + protected const ENTITY = PreviouslyOwnedFlash::class; + protected const ROUTE_PREFIX = 'previously-owned-flash_'; + protected const TEMPLATE_PATH = 'previouslyownedflash/'; + protected const FORM = PreviouslyOwnedFlashType::class; public function __construct(private readonly EntityManagerInterface $entityManager) { @@ -33,7 +33,7 @@ class PreviouslyOwnedFlashController extends AbstractController #[Route(path: '/', name: 'previously-owned-flash_index', methods: ['GET'])] public function indexAction(): Response { - return $this->itemListView( 'previouslyOwnedFlashes'); + return $this->itemListView('previouslyOwnedFlashes'); } /** diff --git a/src/Controller/PreviouslyOwnedLensesController.php b/src/Controller/PreviouslyOwnedLensesController.php index 3dc17e3..46c024f 100644 --- a/src/Controller/PreviouslyOwnedLensesController.php +++ b/src/Controller/PreviouslyOwnedLensesController.php @@ -15,10 +15,10 @@ class PreviouslyOwnedLensesController extends AbstractController { use FormControllerTrait; - protected const ENTITY = PreviouslyOwnedLenses::class; - protected const TEMPLATE_PATH = 'previouslyownedlenses/'; - protected const ROUTE_PREFIX = 'previously-owned-lens_'; - protected const FORM = PreviouslyOwnedLensesType::class; + protected const ENTITY = PreviouslyOwnedLenses::class; + protected const TEMPLATE_PATH = 'previouslyownedlenses/'; + protected const ROUTE_PREFIX = 'previously-owned-lens_'; + protected const FORM = PreviouslyOwnedLensesType::class; public function __construct(private readonly EntityManagerInterface $entityManager) { diff --git a/src/Entity/Brand.php b/src/Entity/Brand.php index 3952a53..7d6b555 100644 --- a/src/Entity/Brand.php +++ b/src/Entity/Brand.php @@ -8,21 +8,21 @@ use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] class Brand { - use GetSetTrait; + use GetSetTrait; - #[ORM\Column(name: 'id', type: 'integer', nullable: FALSE)] - #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'IDENTITY')] - #[ORM\SequenceGenerator(sequenceName: 'brand_id_seq', allocationSize: 1, initialValue: 1)] - private int $id; + #[ORM\Column(name: 'id', type: 'integer', nullable: FALSE)] + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] + #[ORM\SequenceGenerator(sequenceName: 'brand_id_seq', allocationSize: 1, initialValue: 1)] + private int $id; - #[ORM\Column(name: 'name', unique: true, nullable: FALSE)] - private string $name; + #[ORM\Column(name: 'name', unique: TRUE, nullable: FALSE)] + private string $name; - public function __toString(): string - { - return $this->name; - } + public function __toString(): string + { + return $this->name; + } public function getId(): ?int { diff --git a/src/Entity/CameraType.php b/src/Entity/CameraType.php index 71d73dc..91763fd 100644 --- a/src/Entity/CameraType.php +++ b/src/Entity/CameraType.php @@ -2,7 +2,6 @@ namespace App\Entity; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Stringable; diff --git a/src/Entity/Film.php b/src/Entity/Film.php index c3bb132..4a80482 100644 --- a/src/Entity/Film.php +++ b/src/Entity/Film.php @@ -2,7 +2,6 @@ namespace App\Entity; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; /** diff --git a/src/Entity/GetSetTrait.php b/src/Entity/GetSetTrait.php index 2d131ac..55d27f4 100644 --- a/src/Entity/GetSetTrait.php +++ b/src/Entity/GetSetTrait.php @@ -2,32 +2,31 @@ namespace App\Entity; -trait GetSetTrait { - public function __call(string $name, array $arguments): mixed - { - if (method_exists($this, $name)) - { - return $this->$name(...$arguments); - } +use InvalidArgumentException; - // Apparently Doctrine first tries the method with the same - // name as the property, instead of with the get prefix - if (property_exists($this, $name) && empty($arguments)) - { - return $this->$name; - } +trait GetSetTrait +{ + public function __call(string $name, array $arguments): mixed + { + if (method_exists($this, $name)) { + return $this->{$name}(...$arguments); + } - if (str_starts_with('set', $name)) - { - $var = lcfirst(str_replace('set', '', $name)); - if (property_exists($this, $var)) - { - $this->$name = $arguments[0]; - } + // Apparently Doctrine first tries the method with the same + // name as the property, instead of with the get prefix + if (property_exists($this, $name) && empty($arguments)) { + return $this->{$name}; + } - return $this; - } + if (str_starts_with('set', $name)) { + $var = lcfirst(str_replace('set', '', $name)); + if (property_exists($this, $var)) { + $this->{$name} = $arguments[0]; + } - throw new \InvalidArgumentException("Undefined method: {$name}"); - } + return $this; + } + + throw new InvalidArgumentException("Undefined method: {$name}"); + } } diff --git a/src/Entity/Gpu.php b/src/Entity/Gpu.php index d140e9f..5a09ac4 100644 --- a/src/Entity/Gpu.php +++ b/src/Entity/Gpu.php @@ -2,43 +2,42 @@ namespace App\Entity; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Table(name: 'gpu', schema: 'collection')] #[ORM\Entity] class Gpu { - use GetSetTrait; + use GetSetTrait; - #[ORM\Column(name: 'id', type: 'integer', nullable: FALSE)] - #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'IDENTITY')] - private int $id; + #[ORM\Column(name: 'id', type: 'integer', nullable: FALSE)] + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] + private int $id; - #[ORM\ManyToOne(targetEntity: 'Brand')] - #[ORM\JoinColumn(name: 'board_brand_id', referencedColumnName: 'id', nullable: TRUE)] - private readonly Brand $boardBrand; + #[ORM\ManyToOne(targetEntity: 'Brand')] + #[ORM\JoinColumn(name: 'board_brand_id', referencedColumnName: 'id', nullable: TRUE)] + private readonly Brand $boardBrand; - #[ORM\ManyToOne(targetEntity: 'Brand')] - #[ORM\JoinColumn(name: 'gpu_brand_id', referencedColumnName: 'id', nullable: FALSE)] - private readonly Brand $gpuBrand; + #[ORM\ManyToOne(targetEntity: 'Brand')] + #[ORM\JoinColumn(name: 'gpu_brand_id', referencedColumnName: 'id', nullable: FALSE)] + private readonly Brand $gpuBrand; - #[ORM\ManyToOne(targetEntity: 'GpuCore')] - #[ORM\JoinColumn(name: 'gpu_core_id', referencedColumnName: 'id', nullable: TRUE)] - private readonly GpuCore $gpuCore; + #[ORM\ManyToOne(targetEntity: 'GpuCore')] + #[ORM\JoinColumn(name: 'gpu_core_id', referencedColumnName: 'id', nullable: TRUE)] + private readonly GpuCore $gpuCore; - #[ORM\Column(name: 'reference_model_name', nullable: FALSE)] - private readonly string $modelName; + #[ORM\Column(name: 'reference_model_name', nullable: FALSE)] + private readonly string $modelName; - #[ORM\Column(name: 'alternate_model_name', nullable: TRUE)] - private readonly string $alternateModelName; + #[ORM\Column(name: 'alternate_model_name', nullable: TRUE)] + private readonly string $alternateModelName; - #[ORM\Column(name: 'count', nullable: FALSE)] - private readonly int $count; + #[ORM\Column(name: 'count', nullable: FALSE)] + private readonly int $count; - #[ORM\Column(name: 'notes', type: 'text', nullable: TRUE)] - private readonly string $notes; + #[ORM\Column(name: 'notes', type: 'text', nullable: TRUE)] + private readonly string $notes; public function getId(): ?int { diff --git a/src/Entity/GpuCore.php b/src/Entity/GpuCore.php index eb9ea4b..fc37192 100644 --- a/src/Entity/GpuCore.php +++ b/src/Entity/GpuCore.php @@ -2,134 +2,132 @@ namespace App\Entity; -use App\Repository\GPURepository; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Table(name: 'gpu_core', schema: 'collection')] #[ORM\Entity] class GpuCore { - use GetSetTrait; + use GetSetTrait; - #[ORM\Column(name: 'id', type: 'integer', nullable: FALSE)] - #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'IDENTITY')] - private int $id; + #[ORM\Column(name: 'id', type: 'integer', nullable: FALSE)] + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] + private int $id; - #[ORM\ManyToOne(targetEntity: 'Brand')] - #[ORM\JoinColumn(name: 'brand_id', referencedColumnName: 'id')] - private Brand $brand; + #[ORM\ManyToOne(targetEntity: 'Brand')] + #[ORM\JoinColumn(name: 'brand_id', referencedColumnName: 'id')] + private Brand $brand; - #[ORM\Column(name: 'name')] - private readonly string $name; + #[ORM\Column(name: 'name')] + private readonly string $name; - #[ORM\Column(name: 'variant', nullable: TRUE)] - private readonly ?string $variant; + #[ORM\Column(name: 'variant', nullable: TRUE)] + private readonly ?string $variant; - #[ORM\Column(name: 'generation_name')] - private readonly string $generationName; + #[ORM\Column(name: 'generation_name')] + private readonly string $generationName; - #[ORM\Column(name: 'architecture')] - private readonly string $architecture; + #[ORM\Column(name: 'architecture')] + private readonly string $architecture; - #[ORM\Column(name: 'architecture_link')] - private readonly string $architectureLink; + #[ORM\Column(name: 'architecture_link')] + private readonly string $architectureLink; - #[ORM\Column(name: 'process_node', nullable: TRUE)] - private readonly ?int $processNode; + #[ORM\Column(name: 'process_node', nullable: TRUE)] + private readonly ?int $processNode; - public function __toString(): string - { - return "$this->brand $this->name ($this->variant/$this->generationName)"; - } + public function __toString(): string + { + return "{$this->brand} {$this->name} ({$this->variant}/{$this->generationName})"; + } - public function getId(): ?int - { - return $this->id; - } + public function getId(): ?int + { + return $this->id; + } - public function getName(): ?string - { - return $this->name; - } + public function getName(): ?string + { + return $this->name; + } - public function setName(string $name): self - { - $this->name = $name; + public function setName(string $name): self + { + $this->name = $name; - return $this; - } + return $this; + } - public function getVariant(): ?string - { - return $this->variant; - } + public function getVariant(): ?string + { + return $this->variant; + } - public function setVariant(string $variant): self - { - $this->variant = $variant; + public function setVariant(string $variant): self + { + $this->variant = $variant; - return $this; - } + return $this; + } - public function getGenerationName(): ?string - { - return $this->generationName; - } + public function getGenerationName(): ?string + { + return $this->generationName; + } - public function setGenerationName(string $generationName): self - { - $this->generationName = $generationName; + public function setGenerationName(string $generationName): self + { + $this->generationName = $generationName; - return $this; - } + return $this; + } - public function getArchitecture(): ?string - { - return $this->architecture; - } + public function getArchitecture(): ?string + { + return $this->architecture; + } - public function setArchitecture(string $architecture): self - { - $this->architecture = $architecture; + public function setArchitecture(string $architecture): self + { + $this->architecture = $architecture; - return $this; - } + return $this; + } - public function getArchitectureLink(): ?string - { - return $this->architectureLink; - } + public function getArchitectureLink(): ?string + { + return $this->architectureLink; + } - public function setArchitectureLink(string $architectureLink): self - { - $this->architectureLink = $architectureLink; + public function setArchitectureLink(string $architectureLink): self + { + $this->architectureLink = $architectureLink; - return $this; - } + return $this; + } - public function getProcessNode(): ?int - { - return $this->processNode; - } + public function getProcessNode(): ?int + { + return $this->processNode; + } - public function setProcessNode(int $processNode): self - { - $this->processNode = $processNode; + public function setProcessNode(int $processNode): self + { + $this->processNode = $processNode; - return $this; - } + return $this; + } - public function getBrand(): ?Brand - { - return $this->brand; - } + public function getBrand(): ?Brand + { + return $this->brand; + } - public function setBrand(?Brand $brand): self - { - $this->brand = $brand; + public function setBrand(?Brand $brand): self + { + $this->brand = $brand; - return $this; - } + return $this; + } } diff --git a/src/Entity/LensTrait.php b/src/Entity/LensTrait.php index 3721e5e..176ab65 100644 --- a/src/Entity/LensTrait.php +++ b/src/Entity/LensTrait.php @@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM; trait LensTrait { use PurchasePriceTrait; - use GetSetTrait; + use GetSetTrait; #[ORM\Column(name: 'brand', type: 'string', length: 64, nullable: TRUE)] private readonly ?string $brand; @@ -63,13 +63,12 @@ trait LensTrait #[ORM\Column(name: 'aperture_blades', type: 'smallint', nullable: TRUE)] private readonly ?int $apertureBlades; - public function __get(string $name): mixed - { - if (property_exists($this, $name)) - { - return $this->$name; - } + public function __get(string $name): mixed + { + if (property_exists($this, $name)) { + return $this->{$name}; + } - return null; - } + return NULL; + } } diff --git a/src/Form/BrandType.php b/src/Form/BrandType.php index 4ee7760..f354079 100644 --- a/src/Form/BrandType.php +++ b/src/Form/BrandType.php @@ -1,10 +1,9 @@ -add('name') - ; + ->add('name'); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/GPUCoreType.php b/src/Form/GPUCoreType.php index 40a8d3f..8d38d0d 100644 --- a/src/Form/GPUCoreType.php +++ b/src/Form/GPUCoreType.php @@ -1,10 +1,9 @@ -add('brand') + ->add('brand') ->add('name') ->add('variant') ->add('architecture') ->add('architectureLink') - ->add('generationName') - ->add('processNode') - ; + ->add('generationName') + ->add('processNode'); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Repository/AcquireRepository.php b/src/Repository/AcquireRepository.php index 05b4cb1..f180acc 100644 --- a/src/Repository/AcquireRepository.php +++ b/src/Repository/AcquireRepository.php @@ -7,42 +7,39 @@ use Doctrine\ORM\{EntityRepository}; use ReflectionObject; use Throwable; - abstract class AcquireRepository extends EntityRepository { - abstract public function reacquire(mixed $currentRecord): void; - abstract public function deacquire(mixed $currentRecord): void; + abstract public function reacquire(mixed $currentRecord): void; - /** - * Move a record from the table represented by $currentRecord - * into the table represented by $newRecord - * - * @param mixed $currentRecord - * @param mixed $newRecord - */ - protected function moveRecord(mixed $currentRecord, mixed $newRecord): void - { - $em = $this->getEntityManager(); + abstract public function deacquire(mixed $currentRecord): void; - $old = new ReflectionObject($currentRecord); - $new = new ReflectionObject($newRecord); + /** + * Move a record from the table represented by $currentRecord + * into the table represented by $newRecord + */ + protected function moveRecord(mixed $currentRecord, mixed $newRecord): void + { + $em = $this->getEntityManager(); - foreach ($old->getProperties() as $property) { - $propertyName = $property->getName(); - if ($new->hasProperty($propertyName)) { - $newProperty = $new->getProperty($propertyName); - $newProperty->setAccessible(TRUE); - $property->setAccessible(TRUE); - $newProperty->setValue($newRecord, $property->getValue($currentRecord)); - } - } + $old = new ReflectionObject($currentRecord); + $new = new ReflectionObject($newRecord); - try { - $em->persist($newRecord); - $em->remove($currentRecord); - $em->flush(); - } catch (Throwable) { - dump($newRecord); - } - } + foreach ($old->getProperties() as $property) { + $propertyName = $property->getName(); + if ($new->hasProperty($propertyName)) { + $newProperty = $new->getProperty($propertyName); + $newProperty->setAccessible(TRUE); + $property->setAccessible(TRUE); + $newProperty->setValue($newRecord, $property->getValue($currentRecord)); + } + } + + try { + $em->persist($newRecord); + $em->remove($currentRecord); + $em->flush(); + } catch (Throwable) { + dump($newRecord); + } + } } diff --git a/src/Traits/DeleteFormTrait.php b/src/Traits/DeleteFormTrait.php index b4b5127..b40dce4 100644 --- a/src/Traits/DeleteFormTrait.php +++ b/src/Traits/DeleteFormTrait.php @@ -6,11 +6,11 @@ use Symfony\Component\Form\FormInterface; trait DeleteFormTrait { - /** - * Creates a form to delete an entity. - */ - private function createDeleteForm(mixed $item): FormInterface - { - return $this->buildForm($item, self::ROUTE_PREFIX . 'delete', 'DELETE'); - } + /** + * Creates a form to delete an entity. + */ + private function createDeleteForm(mixed $item): FormInterface + { + return $this->buildForm($item, self::ROUTE_PREFIX . 'delete', 'DELETE'); + } } diff --git a/src/Traits/FormControllerTrait.php b/src/Traits/FormControllerTrait.php index 2b9927f..97bb0c7 100644 --- a/src/Traits/FormControllerTrait.php +++ b/src/Traits/FormControllerTrait.php @@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response}; trait FormControllerTrait { - private readonly EntityManagerInterface $entityManager; + private readonly EntityManagerInterface $entityManager; /** * Create a form generator @@ -25,9 +25,9 @@ trait FormControllerTrait * Show create form / create an item */ protected function itemCreate(Request $request, string $templateKey): RedirectResponse|Response - { - $template = self::TEMPLATE_PATH . 'new.html.twig'; - $redirectRoute = self::ROUTE_PREFIX . 'show'; + { + $template = self::TEMPLATE_PATH . 'new.html.twig'; + $redirectRoute = self::ROUTE_PREFIX . 'show'; $Entity = self::ENTITY; $item = new $Entity(); @@ -49,17 +49,17 @@ trait FormControllerTrait ]); } - protected function indexView(string $templateKey, array $sort = []): Response - { - return $this->itemListView($templateKey, $sort); - } + protected function indexView(string $templateKey, array $sort = []): Response + { + return $this->itemListView($templateKey, $sort); + } /** * List view for the data type */ protected function itemListView(string $templateKey, array $sort = []): Response { - $template = self::TEMPLATE_PATH . 'index.html.twig'; + $template = self::TEMPLATE_PATH . 'index.html.twig'; $items = $this->entityManager->getRepository(self::ENTITY)->findBy([], $sort); @@ -73,7 +73,7 @@ trait FormControllerTrait */ protected function itemView(mixed $item, string $templateKey): Response { - $template = self::TEMPLATE_PATH . 'show.html.twig'; + $template = self::TEMPLATE_PATH . 'show.html.twig'; $templateData = [ $templateKey => $item, @@ -91,9 +91,9 @@ trait FormControllerTrait * Show edit form / update an item */ protected function itemUpdate(Request $request, mixed $item, string $templateKey): RedirectResponse|Response - { - $template = self::TEMPLATE_PATH . 'edit.html.twig'; - $redirectRoute = self::ROUTE_PREFIX . 'show'; + { + $template = self::TEMPLATE_PATH . 'edit.html.twig'; + $redirectRoute = self::ROUTE_PREFIX . 'show'; $editForm = $this->createForm(self::FORM, $item); $editForm->handleRequest($request); @@ -158,31 +158,31 @@ trait FormControllerTrait return $this->redirectToRoute($redirectRoute); } - /** - * Actually delete an item - */ + /** + * Actually delete an item + */ protected function itemDelete(Request $request, mixed $item): RedirectResponse { - $redirectRoute = self::ROUTE_PREFIX . 'index'; + $redirectRoute = self::ROUTE_PREFIX . 'index'; $form = $this->createDeleteForm($item); $form->handleRequest($request); - // if ($this->isCsrfTokenValid((string)$item->getId(), $request->request->get('_token'))) { - $this->entityManager->remove($item); - $this->entityManager->flush(); - //} + // if ($this->isCsrfTokenValid((string)$item->getId(), $request->request->get('_token'))) { + $this->entityManager->remove($item); + $this->entityManager->flush(); + //} return $this->redirectToRoute($redirectRoute, [], Response::HTTP_SEE_OTHER); } - protected function deleteCSRF(Request $request, mixed $item): RedirectResponse - { - if ($this->isCsrfTokenValid('delete'.$item->getId(), $request->request->get('_token'))) { - $this->entityManager->remove($item); - $this->entityManager->flush(); - } + protected function deleteCSRF(Request $request, mixed $item): RedirectResponse + { + if ($this->isCsrfTokenValid('delete' . $item->getId(), $request->request->get('_token'))) { + $this->entityManager->remove($item); + $this->entityManager->flush(); + } - return $this->redirectToRoute(self::ROUTE_PREFIX . 'index', [], Response::HTTP_SEE_OTHER); - } + return $this->redirectToRoute(self::ROUTE_PREFIX . 'index', [], Response::HTTP_SEE_OTHER); + } } diff --git a/src/Types/BusInterface.php b/src/Types/BusInterface.php index 280aab9..787810a 100644 --- a/src/Types/BusInterface.php +++ b/src/Types/BusInterface.php @@ -3,11 +3,17 @@ namespace App\Types; enum BusInterface: string { - case PCI = 'PCI'; - case ISA = 'ISA'; - case VLB = 'VLB (Vesa Local Bus)'; - case AGP = 'AGP'; - case AGPX2 = 'AGP 2x'; - case AGPX4 = 'AGP 4x'; - case AGPX8 = 'AGP 8x'; + case PCI = 'PCI'; + + case ISA = 'ISA'; + + case VLB = 'VLB (Vesa Local Bus)'; + + case AGP = 'AGP'; + + case AGPX2 = 'AGP 2x'; + + case AGPX4 = 'AGP 4x'; + + case AGPX8 = 'AGP 8x'; } diff --git a/src/ValueObject/Money.php b/src/ValueObject/Money.php index 5821509..83f53e1 100644 --- a/src/ValueObject/Money.php +++ b/src/ValueObject/Money.php @@ -15,7 +15,7 @@ class Money implements Stringable public function getValue(): float { - return (float) str_replace(['$', ','], '', (string)$this->value); + return (float) str_replace(['$', ','], '', (string) $this->value); } public function __toString(): string