From ea2ec447e640afe39ad86c5e3592c3dbb5ea5ebf Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 18 Feb 2022 11:34:25 -0500 Subject: [PATCH] More refactoring --- src/Controller/CameraController.php | 12 + src/Controller/CameraTypeController.php | 36 +-- src/Controller/FilmController.php | 8 + src/Controller/FlashController.php | 31 ++- src/Controller/FormControllerTrait.php | 5 +- src/Controller/LensesController.php | 10 + .../PreviouslyOwnedCameraController.php | 6 + .../PreviouslyOwnedFlashController.php | 19 +- .../PreviouslyOwnedLensesController.php | 4 + src/Entity/CameraTrait.php | 227 +++--------------- src/Entity/CameraType.php | 8 + src/Entity/Film.php | 40 +++ src/Entity/FilmFormat.php | 7 + src/Entity/Flash.php | 7 +- src/Entity/FlashTrait.php | 60 +---- src/Entity/LensTrait.php | 6 - src/Entity/Lenses.php | 2 + src/Entity/PreviouslyOwnedFlash.php | 14 +- src/Entity/PreviouslyOwnedLenses.php | 2 + src/Entity/PurchasePriceTrait.php | 21 +- src/Types/MoneyType.php | 4 +- 21 files changed, 224 insertions(+), 305 deletions(-) diff --git a/src/Controller/CameraController.php b/src/Controller/CameraController.php index d581888..a5b42d0 100644 --- a/src/Controller/CameraController.php +++ b/src/Controller/CameraController.php @@ -22,10 +22,13 @@ class CameraController extends AbstractController { use FormControllerTrait; protected const ENTITY = Camera::class; + protected const FORM = CameraType::class; + public function __construct(private readonly ManagerRegistry $managerRegistry) { } + /** * Lists all camera entities. */ @@ -56,6 +59,7 @@ class CameraController extends AbstractController 'working' => $working, ]); } + /** * Creates a new camera entity. */ @@ -64,6 +68,7 @@ class CameraController extends AbstractController { return $this->itemCreate($request, 'camera/new.html.twig', 'camera', 'camera_show'); } + /** * Finds and displays a camera entity. */ @@ -72,6 +77,7 @@ class CameraController extends AbstractController { return $this->itemView($camera, 'camera/show.html.twig', 'camera'); } + /** * Displays a form to edit an existing camera entity. * @@ -82,6 +88,7 @@ class CameraController extends AbstractController { return $this->itemUpdate($request, $camera, 'camera/edit.html.twig', 'camera', 'camera_show'); } + /** * Deletes a camera entity. * @@ -92,6 +99,7 @@ class CameraController extends AbstractController { return $this->itemDelete($request, $camera, 'camera_index'); } + /** * Moves a camera to the previouslyOwned table * @@ -103,6 +111,7 @@ class CameraController extends AbstractController { return $this->itemDeacquire($request, $camera, 'previously-owned-camera_index'); } + /** * Creates a form to delete a camera entity. * @@ -114,6 +123,7 @@ class CameraController extends AbstractController { return $this->buildForm($camera, 'camera_delete', 'DELETE'); } + /** * Creates a form to move * @@ -123,10 +133,12 @@ class CameraController extends AbstractController { return $this->buildForm($camera, 'camera_deacquire'); } + private function isWorking(Camera $camera): bool { return $camera->getIsWorking(); } + private function isNotWorking(Camera $camera): bool { return !$this->isWorking($camera); diff --git a/src/Controller/CameraTypeController.php b/src/Controller/CameraTypeController.php index 0a7f2c3..563b4b8 100644 --- a/src/Controller/CameraTypeController.php +++ b/src/Controller/CameraTypeController.php @@ -2,72 +2,80 @@ namespace App\Controller; -use Symfony\Component\Form\Form; use App\Entity\CameraType; use App\Form\CameraTypeType; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Request; -/** - * Cameratype controller. - */ #[Route(path: 'camera-type')] class CameraTypeController extends AbstractController { use FormControllerTrait; + protected const ENTITY = CameraType::class; + protected const FORM = CameraTypeType::class; + + public function __construct(private readonly ManagerRegistry $managerRegistry) + { + } + /** * Lists all cameraType entities. */ #[Route(path: '/', name: 'camera-type_index', methods: ['GET'])] - public function indexAction() + public function indexAction(): Response { return $this->itemListView('cameratype/index.html.twig', 'cameraTypes', [ 'type' => 'ASC', ]); } + /** * Creates a new cameraType entity. */ #[Route(path: '/new', name: 'camera-type_new', methods: ['GET', 'POST'])] - public function newAction(Request $request) + public function newAction(Request $request): Response { return $this->itemCreate($request, 'cameratype/new.html.twig', 'cameraType', 'camera-type_show'); } + /** * Finds and displays a cameraType entity. */ #[Route(path: '/{id}', name: 'camera-type_show', methods: ['GET'])] - public function showAction(CameraType $cameraType) + public function showAction(CameraType $cameraType): Response { return $this->itemView($cameraType, 'cameratype/show.html.twig', 'cameraType'); } + /** * Displays a form to edit an existing cameraType entity. */ #[Route(path: '/{id}/edit', name: 'camera-type_edit', methods: ['GET', 'POST'])] - public function editAction(Request $request, CameraType $cameraType) + public function editAction(Request $request, CameraType $cameraType): RedirectResponse|Response { return $this->itemUpdate($request, $cameraType, 'cameratype/edit.html.twig', 'cameraType', 'camera-type_show'); } + /** * Deletes a cameraType entity. */ #[Route(path: '/{id}', name: 'camera-type_delete', methods: ['DELETE'])] - public function deleteAction(Request $request, CameraType $cameraType) + public function deleteAction(Request $request, CameraType $cameraType): RedirectResponse { return $this->itemDelete($request, $cameraType, 'camera-type_index'); } + /** * Creates a form to delete a cameraType entity. - * - * @param CameraType $cameraType The cameraType entity - * - * @return Form The form */ - private function createDeleteForm(CameraType $cameraType) + private function createDeleteForm(CameraType $cameraType): FormInterface { return $this->buildForm($cameraType, 'camera-type_delete', 'DELETE'); } diff --git a/src/Controller/FilmController.php b/src/Controller/FilmController.php index 2f84a22..efac486 100644 --- a/src/Controller/FilmController.php +++ b/src/Controller/FilmController.php @@ -21,10 +21,13 @@ class FilmController extends AbstractController { use FormControllerTrait; protected const ENTITY = Film::class; + protected const FORM = FilmType::class; + public function __construct(private readonly ManagerRegistry $managerRegistry) { } + /** * Lists all film entities. */ @@ -53,6 +56,7 @@ class FilmController extends AbstractController 'films' => $notInCamera, ]); } + /** * Creates a new film entity. */ @@ -61,6 +65,7 @@ class FilmController extends AbstractController { return $this->itemCreate($request, 'film/new.html.twig', 'film', 'film_show'); } + /** * Finds and displays a film entity. */ @@ -69,6 +74,7 @@ class FilmController extends AbstractController { return $this->itemView($film, 'film/show.html.twig', 'film'); } + /** * Displays a form to edit an existing film entity. * @@ -79,6 +85,7 @@ class FilmController extends AbstractController { return $this->itemUpdate($request, $film, 'film/edit.html.twig', 'film', 'film_show'); } + /** * Deletes a film entity. * @@ -89,6 +96,7 @@ class FilmController extends AbstractController { return $this->itemDelete($request, $film, 'film_index'); } + /** * Creates a form to delete a film entity. * diff --git a/src/Controller/FlashController.php b/src/Controller/FlashController.php index 10a7862..e033d8f 100644 --- a/src/Controller/FlashController.php +++ b/src/Controller/FlashController.php @@ -2,10 +2,13 @@ namespace App\Controller; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Form\FormInterface; use App\Entity\Flash; use App\Form\FlashType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Request; @@ -16,56 +19,64 @@ use Symfony\Component\HttpFoundation\Request; class FlashController extends AbstractController { use FormControllerTrait; + protected const ENTITY = Flash::class; + protected const FORM = FlashType::class; + + public function __construct(private readonly ManagerRegistry $managerRegistry) + { + } + /** * Lists all flash entities. */ #[Route(path: '/', name: 'flash_index', methods: ['GET'])] - public function indexAction() + public function indexAction(): Response { return $this->itemListView('flash/index.html.twig', 'flashes'); } + /** * Creates a new flash entity. */ #[Route(path: '/new', name: 'flash_new', methods: ['GET', 'POST'])] - public function newAction(Request $request) + public function newAction(Request $request): RedirectResponse|Response { return $this->itemCreate($request, 'flash/new.html.twig', 'flash', 'flash_show'); } + /** * Finds and displays a flash entity. */ #[Route(path: '/{id}', name: 'flash_show', methods: ['GET'])] - public function showAction(Flash $flash) + public function showAction(Flash $flash): Response { return $this->itemView($flash, 'flash/show.html.twig', 'flash'); } + /** * Displays a form to edit an existing flash entity. */ #[Route(path: '/{id}/edit', name: 'flash_edit', methods: ['GET', 'POST'])] - public function editAction(Request $request, Flash $flash) + public function editAction(Request $request, Flash $flash): RedirectResponse|Response { return $this->itemUpdate($request, $flash, 'flash/edit.html.twig', 'flash', 'flash_show'); } + /** * Deletes a flash entity. */ #[Route(path: '/{id}', name: 'flash_delete', methods: ['DELETE'])] - public function deleteAction(Request $request, Flash $flash) + public function deleteAction(Request $request, Flash $flash): RedirectResponse { return $this->itemDelete($request, $flash, 'flash_index'); } + /** * Creates a form to delete a flash entity. - * - * @param Flash $flash The flash entity - * - * @return FormInterface The form */ - private function createDeleteForm(Flash $flash) + private function createDeleteForm(Flash $flash): FormInterface { return $this->buildForm($flash, 'flash_delete', 'DELETE'); } diff --git a/src/Controller/FormControllerTrait.php b/src/Controller/FormControllerTrait.php index 13d604c..fc3ada5 100644 --- a/src/Controller/FormControllerTrait.php +++ b/src/Controller/FormControllerTrait.php @@ -2,10 +2,13 @@ namespace App\Controller; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\{Request, Response, RedirectResponse}; trait FormControllerTrait { + private readonly ManagerRegistry $managerRegistry; + /** * Create a form generator */ @@ -49,7 +52,7 @@ trait FormControllerTrait { */ protected function itemListView(string $template, string $templateKey, array $sort = []): Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $items = $em->getRepository(self::ENTITY)->findBy([], $sort); diff --git a/src/Controller/LensesController.php b/src/Controller/LensesController.php index 7cd95a6..9b8c979 100644 --- a/src/Controller/LensesController.php +++ b/src/Controller/LensesController.php @@ -18,10 +18,13 @@ class LensesController extends AbstractController { use FormControllerTrait; protected const ENTITY = Lenses::class; + protected const FORM = LensesType::class; + public function __construct(private readonly ManagerRegistry $managerRegistry) { } + /** * Lists all lens entities. */ @@ -52,6 +55,7 @@ class LensesController extends AbstractController 'lenses' => $receivedItems, ]); } + /** * Creates a new lens entity. */ @@ -60,6 +64,7 @@ class LensesController extends AbstractController { return $this->itemCreate($request, 'lenses/new.html.twig', 'lense', 'lens_show'); } + /** * Finds and displays a lens entity. */ @@ -68,6 +73,7 @@ class LensesController extends AbstractController { return $this->itemView($lens, 'lenses/show.html.twig', 'lense'); } + /** * Displays a form to edit an existing lens entity. */ @@ -76,6 +82,7 @@ class LensesController extends AbstractController { return $this->itemUpdate($request, $lens, 'lenses/edit.html.twig', 'lense', 'lens_show'); } + /** * Moves a camera to the previouslyOwned table * @@ -87,6 +94,7 @@ class LensesController extends AbstractController { return $this->itemDeacquire($request, $lens, 'previously-owned-lens_index'); } + /** * Deletes a lens entity. */ @@ -95,6 +103,7 @@ class LensesController extends AbstractController { return $this->itemDelete($request, $lens, 'lens_index'); } + /** * Creates a form to delete a lens entity. * @@ -106,6 +115,7 @@ class LensesController extends AbstractController { return $this->buildForm($lens, 'lens_delete', 'DELETE'); } + /** * Creates a form to move * diff --git a/src/Controller/PreviouslyOwnedCameraController.php b/src/Controller/PreviouslyOwnedCameraController.php index 518c8e9..6368177 100644 --- a/src/Controller/PreviouslyOwnedCameraController.php +++ b/src/Controller/PreviouslyOwnedCameraController.php @@ -20,7 +20,9 @@ class PreviouslyOwnedCameraController extends AbstractController { use FormControllerTrait; protected const ENTITY = PreviouslyOwnedCamera::class; + protected const FORM = PreviouslyOwnedCameraType::class; + /** * Lists all previouslyOwnedCamera entities. * @@ -35,6 +37,7 @@ class PreviouslyOwnedCameraController extends AbstractController 'model' => 'ASC', ]); } + /** * Finds and displays a previouslyOwnedCamera entity. */ @@ -43,6 +46,7 @@ class PreviouslyOwnedCameraController extends AbstractController { return $this->itemView($previouslyOwnedCamera, 'previouslyownedcamera/show.html.twig', 'previouslyOwnedCamera'); } + /** * Displays a form to edit an existing previouslyOwnedCamera entity. * @@ -53,6 +57,7 @@ class PreviouslyOwnedCameraController extends AbstractController { return $this->itemUpdate($request, $previouslyOwnedCamera, 'previouslyownedcamera/edit.html.twig', 'previouslyOwnedCamera', 'previously-owned-camera_show'); } + /** * Moves a camera to the previouslyOwned table * @@ -66,6 +71,7 @@ class PreviouslyOwnedCameraController extends AbstractController { return $this->itemReacquire($request, $camera, 'camera_index'); } + /** * Creates a form to move * diff --git a/src/Controller/PreviouslyOwnedFlashController.php b/src/Controller/PreviouslyOwnedFlashController.php index 7968717..9a68b06 100644 --- a/src/Controller/PreviouslyOwnedFlashController.php +++ b/src/Controller/PreviouslyOwnedFlashController.php @@ -4,7 +4,10 @@ namespace App\Controller; use App\Entity\PreviouslyOwnedFlash; use App\Form\PreviouslyOwnedFlashType; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Request; @@ -15,16 +18,24 @@ use Symfony\Component\HttpFoundation\Request; class PreviouslyOwnedFlashController extends AbstractController { use FormControllerTrait; + protected const ENTITY = PreviouslyOwnedFlash::class; + protected const FORM = PreviouslyOwnedFlashType::class; + + public function __construct(private readonly ManagerRegistry $managerRegistry) + { + } + /** * Lists all previouslyOwnedFlash entities. */ #[Route(path: '/', name: 'previously-owned-flash_index', methods: ['GET'])] - public function indexAction() + public function indexAction(): Response { return $this->itemListView('previouslyownedflash/index.html.twig', 'previouslyOwnedFlashes'); } + /** * Creates a new previouslyOwnedFlash entity. */ @@ -33,19 +44,21 @@ class PreviouslyOwnedFlashController extends AbstractController { return $this->itemCreate($request, 'previouslyownedflash/new.html.twig', 'previouslyOwnedFlash', 'previously-owned-flash_show'); } + /** * Finds and displays a previouslyOwnedFlash entity. */ #[Route(path: '/{id}', name: 'previously-owned-flash_show', methods: ['GET'])] - public function showAction(PreviouslyOwnedFlash $previouslyOwnedFlash) + public function showAction(PreviouslyOwnedFlash $previouslyOwnedFlash): Response { return $this->itemView($previouslyOwnedFlash, 'previouslyownedcamera/show.html.twig', 'previouslyOwnedFlash'); } + /** * Displays a form to edit an existing previouslyOwnedFlash entity. */ #[Route(path: '/{id}/edit', name: 'previously-owned-flash_edit', methods: ['GET', 'POST'])] - public function editAction(Request $request, PreviouslyOwnedFlash $previouslyOwnedFlash) + public function editAction(Request $request, PreviouslyOwnedFlash $previouslyOwnedFlash): RedirectResponse|Response { return $this->itemUpdate($request, $previouslyOwnedFlash, 'previouslyownedflash/edit.html.twig', 'previouslyOwnedFlash', 'previously-owned-flash_show'); } diff --git a/src/Controller/PreviouslyOwnedLensesController.php b/src/Controller/PreviouslyOwnedLensesController.php index 1698e8e..a718c1f 100644 --- a/src/Controller/PreviouslyOwnedLensesController.php +++ b/src/Controller/PreviouslyOwnedLensesController.php @@ -13,7 +13,9 @@ class PreviouslyOwnedLensesController extends AbstractController { use FormControllerTrait; protected const ENTITY = PreviouslyOwnedLenses::class; + protected const FORM = PreviouslyOwnedLensesType::class; + /** * Lists all previouslyOwnedLense entities. */ @@ -28,6 +30,7 @@ class PreviouslyOwnedLensesController extends AbstractController 'maxFStop' => 'ASC', ]); } + /** * Finds and displays a previouslyOwnedLense entity. */ @@ -36,6 +39,7 @@ class PreviouslyOwnedLensesController extends AbstractController { return $this->itemView($previouslyOwnedLens, 'previouslyownedlenses/show.html.twig', 'previouslyOwnedLense'); } + /** * Displays a form to edit an existing previouslyOwnedLense entity. */ diff --git a/src/Entity/CameraTrait.php b/src/Entity/CameraTrait.php index cbd112a..ccc3cce 100644 --- a/src/Entity/CameraTrait.php +++ b/src/Entity/CameraTrait.php @@ -15,95 +15,51 @@ trait CameraTrait { use PurchasePriceTrait; - /** - * @var CameraType - */ #[ORM\ManyToOne(targetEntity: 'CameraType')] - #[ORM\JoinColumn(name: 'type_id', referencedColumnName: 'id')]private readonly ?CameraType $type; + #[ORM\JoinColumn(name: 'type_id', referencedColumnName: 'id', nullable: false)] + private readonly CameraType $type; - /** - * @var string - */ - #[ORM\Column(name: 'brand', type: 'string', length: 64, nullable: false)]private readonly string $brand; + #[ORM\Column(name: 'brand', type: 'string', length: 64, nullable: false)] + private readonly string $brand; - /** - * @var string - */ - #[ORM\Column(name: 'mount', type: 'string', length: 32, nullable: false)]private readonly string $mount; + #[ORM\Column(name: 'mount', type: 'string', length: 32, nullable: false)] + private readonly string $mount; - /** - * @var string - */ - #[ORM\Column(name: 'model', type: 'string', length: 255, nullable: false)]private readonly string $model; + #[ORM\Column(name: 'model', type: 'string', length: 255, nullable: false)] + private readonly string $model; - /** - * @var boolean - */ - #[ORM\Column(name: 'is_digital', type: 'boolean', nullable: false)]private readonly bool $isDigital; + #[ORM\Column(name: 'is_digital', type: 'boolean', nullable: false)] + private readonly bool $isDigital; - /** - * @var string - */ #[ORM\Column(name: 'crop_factor', type: 'decimal', precision: 10, scale: 0, nullable: false)] private string $cropFactor = '1.0'; - /** - * @var boolean - */ - #[ORM\Column(name: 'is_working', type: 'boolean', nullable: false)]private readonly bool $isWorking; + #[ORM\Column(name: 'is_working', type: 'boolean', nullable: false)] + private readonly bool $isWorking; - /** - * @var string - */ - #[ORM\Column(name: 'notes', type: 'text', nullable: true)]private readonly ?string $notes; + #[ORM\Column(name: 'notes', type: 'text', nullable: true)] + private readonly ?string $notes; - /** - * @var string - */ - #[ORM\Column(name: 'serial', type: 'string', length: 20, nullable: false)]private readonly string $serial; + #[ORM\Column(name: 'serial', type: 'string', length: 20, nullable: false)] + private readonly string $serial; - /** - * @var boolean - */ #[ORM\Column(name: 'formerly_owned', type: 'boolean', nullable: false)] private bool $formerlyOwned = FALSE; - /** - * @var string - */ - #[ORM\Column(name: 'purchase_price', type: 'money', nullable: true)] - private $purchasePrice; + #[ORM\Column(name: 'battery_type', type: 'string', nullable: true)] + private readonly ?string $batteryType; - /** - * @var string - */ - #[ORM\Column(name: 'battery_type', type: 'string', nullable: true)]private readonly ?string $batteryType; - - /** - * @var string - */ #[ORM\Column(name: 'film_format', type: 'string', nullable: true)] private ?string $filmFormat = '135'; - /** - * @var boolean - */ #[ORM\Column(name: 'received', type: 'boolean', nullable: true)] private ?bool $received = FALSE; - /** - * Get id - */ public function getId(): int { return $this->id; } - /** - * Set type - * - * - */ public function setType(CameraType $type = null): self { $this->type = $type; @@ -111,21 +67,11 @@ trait CameraTrait return $this; } - /** - * Get type - * - * @return CameraType - */ - public function getType(): ?CameraType + public function getType(): CameraType { return $this->type; } - /** - * Set brand - * - * - */ public function setBrand(string $brand): self { $this->brand = $brand; @@ -133,21 +79,11 @@ trait CameraTrait return $this; } - /** - * Get brand - * - * @return string - */ - public function getBrand(): ?string + public function getBrand(): string { return $this->brand; } - /** - * Set mount - * - * - */ public function setMount(string $mount): self { $this->mount = $mount; @@ -155,21 +91,11 @@ trait CameraTrait return $this; } - /** - * Get mount - * - * @return string - */ - public function getMount(): ?string + public function getMount(): string { return $this->mount; } - /** - * Set model - * - * - */ public function setModel(string $model): self { $this->model = $model; @@ -177,21 +103,11 @@ trait CameraTrait return $this; } - /** - * Get model - * - * @return string - */ - public function getModel(): ?string + public function getModel(): string { return $this->model; } - /** - * Set isDigital - * - * - */ public function setIsDigital(bool $isDigital): self { $this->isDigital = $isDigital; @@ -199,21 +115,11 @@ trait CameraTrait return $this; } - /** - * Get isDigital - * - * @return boolean - */ - public function getIsDigital(): ?bool + public function getIsDigital(): bool { return $this->isDigital; } - /** - * Set cropFactor - * - * - */ public function setCropFactor(string $cropFactor): self { $this->cropFactor = $cropFactor; @@ -221,19 +127,11 @@ trait CameraTrait return $this; } - /** - * Get cropFactor - */ public function getCropFactor(): string { return $this->cropFactor; } - /** - * Set isWorking - * - * - */ public function setIsWorking(bool $isWorking): self { $this->isWorking = $isWorking; @@ -241,135 +139,78 @@ trait CameraTrait return $this; } - /** - * Get isWorking - * - * @return boolean - */ - public function getIsWorking(): ?bool + public function getIsWorking(): bool { return $this->isWorking; } - /** - * Set notes - * - * @param string $notes - */ - public function setNotes($notes): self + public function setNotes(string $notes): self { $this->notes = $notes; return $this; } - /** - * Get notes - */ public function getNotes(): string { return $this->notes ?? ''; } - /** - * Set serial - * - * @param string $serial - */ - public function setSerial($serial): self + public function setSerial(string $serial): self { $this->serial = $serial; return $this; } - /** - * Get serial - */ public function getSerial(): string { return $this->serial ?? ''; } - /** - * Set formerlyOwned - * - * @param boolean $formerlyOwned - */ - public function setFormerlyOwned($formerlyOwned): self + public function setFormerlyOwned(bool $formerlyOwned): self { $this->formerlyOwned = $formerlyOwned; return $this; } - /** - * Get formerlyOwned - * - * @return boolean - */ - public function getFormerlyOwned(): ?bool + public function getFormerlyOwned(): bool { return $this->formerlyOwned; } - /** - * Set batteryType - * - * @param string $batteryType - */ - public function setBatteryType($batteryType): self + public function setBatteryType(string $batteryType): self { $this->batteryType = $batteryType; return $this; } - /** - * Get batteryType - * - * @return string - */ - public function getBatteryType(): ?string + public function getBatteryType(): string { - return $this->batteryType; + return $this->batteryType ?? ''; } - /** - * Set filmFormat - * - * @param string $filmFormat - */ - public function setFilmFormat($filmFormat): self + public function setFilmFormat(string $filmFormat): self { $this->filmFormat = $filmFormat; return $this; } - /** - * Get filmFormat - */ public function getFilmFormat(): string { - return $this->filmFormat; + return $this->filmFormat ?? ''; } - /** - * Set received - * - * @param boolean $received - */ - public function setReceived($received): self + public function setReceived(bool $received): self { $this->received = $received; return $this; } - /** - * Get received - */ public function getReceived(): bool { return $this->received; diff --git a/src/Entity/CameraType.php b/src/Entity/CameraType.php index a72fb02..da5a3e7 100644 --- a/src/Entity/CameraType.php +++ b/src/Entity/CameraType.php @@ -17,16 +17,19 @@ class CameraType implements Stringable #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\SequenceGenerator(sequenceName: 'camera.camera_type_id_seq', allocationSize: 1, initialValue: 1)] private int $id; + /** * @var string */ #[ORM\Column(name: 'type', type: 'string', length: 255, nullable: false)] private string $type; + /** * @var string */ #[ORM\Column(name: 'description', type: 'text', nullable: true)] private ?string $description = null; + /** * Value for serialization */ @@ -34,6 +37,7 @@ class CameraType implements Stringable { return $this->type; } + /** * Get id */ @@ -41,6 +45,7 @@ class CameraType implements Stringable { return $this->id; } + /** * Set type * @@ -52,6 +57,7 @@ class CameraType implements Stringable return $this; } + /** * Set description * @@ -63,6 +69,7 @@ class CameraType implements Stringable return $this; } + /** * Get type * @@ -72,6 +79,7 @@ class CameraType implements Stringable { return $this->type; } + /** * Get description * diff --git a/src/Entity/Film.php b/src/Entity/Film.php index f9e6dd9..e3089a7 100644 --- a/src/Entity/Film.php +++ b/src/Entity/Film.php @@ -15,75 +15,90 @@ class Film #[ORM\Column(name: 'id', type: 'integer', nullable: false)] #[ORM\GeneratedValue(strategy: 'IDENTITY')] private int $id; + /** * @var string */ #[ORM\Column(name: 'brand', type: 'string', nullable: false)] private string $brand; + /** * @var string */ #[ORM\Column(name: 'product_line', type: 'string', nullable: true)] private ?string $productLine = null; + /** * @var string */ #[ORM\Column(name: 'film_name', type: 'string', nullable: false)] private string $filmName; + /** * @var string */ #[ORM\Column(name: 'film_alias', type: 'string', nullable: true)] private ?string $filmAlias = null; + /** * @var int */ #[ORM\Column(name: 'film_speed_asa', type: 'integer', nullable: false)] private int $filmSpeedAsa; + /** * @var int */ #[ORM\Column(name: 'film_speed_din', type: 'integer', nullable: false)] private int $filmSpeedDin; + /** * @var string */ #[ORM\Column(name: 'film_format', type: 'string', nullable: false)] private string $filmFormat; + /** * @var string */ #[ORM\Column(name: 'film_base', type: 'string', nullable: false, options: ['default' => 'Cellulose Triacetate'])] private string $filmBase = 'Cellulose Triacetate'; + /** * @var int */ #[ORM\Column(name: 'unused_rolls', type: 'integer', nullable: false, options: ['default' => 0])] private int $unusedRolls = 0; + /** * @var int */ #[ORM\Column(name: 'rolls_in_camera', type: 'integer', nullable: false, options: ['default' => 0])] private int $rollsInCamera = 0; + /** * @var int */ #[ORM\Column(name: 'developed_rolls', type: 'integer', nullable: false, options: ['default' => 0])] private int $developedRolls = 0; + /** * @var string */ #[ORM\Column(name: 'chemistry', type: 'string', nullable: false, options: ['default' => 'C-41'])] private string $chemistry = 'C-41'; + /** * @var string */ #[ORM\Column(name: 'notes', type: 'text', nullable: true)] private ?string $notes = null; + public function getId(): int { return $this->id; } + /** * @return string */ @@ -91,11 +106,13 @@ class Film { return $this->brand; } + public function setBrand(string $brand): self { $this->brand = $brand; return $this; } + /** * @return string */ @@ -103,6 +120,7 @@ class Film { return $this->productLine; } + /** * @param string $productLine */ @@ -111,6 +129,7 @@ class Film $this->productLine = $productLine; return $this; } + /** * @return string */ @@ -118,11 +137,13 @@ class Film { return $this->filmName; } + public function setFilmName(string $filmName): self { $this->filmName = $filmName; return $this; } + /** * @return string */ @@ -130,11 +151,13 @@ class Film { return $this->filmAlias; } + public function setFilmAlias(string $filmAlias): self { $this->filmAlias = $filmAlias; return $this; } + /** * @return int */ @@ -142,11 +165,13 @@ class Film { return $this->filmSpeedAsa; } + public function setFilmSpeedAsa(int $filmSpeedAsa): self { $this->filmSpeedAsa = $filmSpeedAsa; return $this; } + /** * @return int */ @@ -154,11 +179,13 @@ class Film { return $this->filmSpeedDin; } + public function setFilmSpeedDin(int $filmSpeedDin): self { $this->filmSpeedDin = $filmSpeedDin; return $this; } + /** * @return string */ @@ -166,11 +193,13 @@ class Film { return $this->filmFormat; } + public function setFilmFormat(string $filmFormat): self { $this->filmFormat = $filmFormat; return $this; } + /** * @return string */ @@ -178,11 +207,13 @@ class Film { return $this->filmBase; } + public function setFilmBase(string $filmBase): self { $this->filmBase = $filmBase; return $this; } + /** * @return int */ @@ -190,11 +221,13 @@ class Film { return $this->unusedRolls; } + public function setUnusedRolls(int $unusedRolls): self { $this->unusedRolls = $unusedRolls; return $this; } + /** * @return int */ @@ -202,11 +235,13 @@ class Film { return $this->rollsInCamera; } + public function setRollsInCamera(int $rollsInCamera): self { $this->rollsInCamera = $rollsInCamera; return $this; } + /** * @return int */ @@ -214,11 +249,13 @@ class Film { return $this->developedRolls; } + public function setDevelopedRolls(int $developedRolls): self { $this->developedRolls = $developedRolls; return $this; } + /** * @return string */ @@ -226,11 +263,13 @@ class Film { return $this->chemistry; } + public function setChemistry(string $chemistry): self { $this->chemistry = $chemistry; return $this; } + /** * @return string */ @@ -238,6 +277,7 @@ class Film { return $this->notes; } + public function setNotes(string $notes): self { $this->notes = $notes; diff --git a/src/Entity/FilmFormat.php b/src/Entity/FilmFormat.php index 758b520..e78804a 100644 --- a/src/Entity/FilmFormat.php +++ b/src/Entity/FilmFormat.php @@ -12,16 +12,19 @@ class FilmFormat #[ORM\GeneratedValue] #[ORM\Column(type: 'integer')] private int $id; + /** * @var int */ #[ORM\Column(name: 'number_id', type: 'integer')] private int $numberId; + /** * @var string */ #[ORM\Column(name: 'name', type: 'string')] private string $name; + /** * @return int */ @@ -29,6 +32,7 @@ class FilmFormat { return $this->id; } + /** * @return int */ @@ -36,11 +40,13 @@ class FilmFormat { return $this->numberId; } + public function setNumberId(int $numberId): self { $this->numberId = $numberId; return $this; } + /** * @return string */ @@ -48,6 +54,7 @@ class FilmFormat { return $this->name; } + public function setName(string $name): self { $this->name = $name; diff --git a/src/Entity/Flash.php b/src/Entity/Flash.php index 1806c70..3dbc614 100644 --- a/src/Entity/Flash.php +++ b/src/Entity/Flash.php @@ -12,19 +12,18 @@ use Doctrine\ORM\Mapping as ORM; class Flash { use FlashTrait; - /** - * @var integer - */ #[ORM\Column(name: 'id', type: 'integer', nullable: false)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\SequenceGenerator(sequenceName: 'camera.flash_id_seq', allocationSize: 1, initialValue: 1)] - private $id; + private int $id; + /** * @var boolean */ #[ORM\Column(name: 'received', type: 'boolean', nullable: false, options: ['default' => false])] private bool $received = false; + /** * @var boolean */ diff --git a/src/Entity/FlashTrait.php b/src/Entity/FlashTrait.php index 586e562..7b93228 100644 --- a/src/Entity/FlashTrait.php +++ b/src/Entity/FlashTrait.php @@ -8,75 +8,39 @@ trait FlashTrait { use PurchasePriceTrait; - /** - * @var string - */ - #[ORM\Column(name: 'brand', type: 'string', nullable: false)]private readonly string $brand; + #[ORM\Column(name: 'brand', type: 'string', nullable: false)] + private readonly string $brand; - /** - * @var string - */ - #[ORM\Column(name: 'model', type: 'string', nullable: false)]private readonly string $model; + #[ORM\Column(name: 'model', type: 'string', nullable: false)] + private readonly string $model; - /** - * @var boolean - */ #[ORM\Column(name: 'is_auto_flash', type: 'boolean', nullable: false)] private bool $isAutoFlash = false; - /** - * @var boolean - */ #[ORM\Column(name: 'is_ttl', type: 'boolean', nullable: false)] private bool $isTtl = false; - /** - * @var string - */ #[ORM\Column(name: 'ttl_type', type: 'string', nullable: false)] private string $ttlType = 'N / A'; - /** - * @var boolean - */ #[ORM\Column(name: 'is_p_ttl', type: 'boolean', nullable: false)] private bool $isPTtl = false; - /** - * @var string - */ #[ORM\Column(name: 'p_ttl_type', type: 'string', nullable: false)] private string $pTtlType = 'N / A'; - /** - * @var string - */ - #[ORM\Column(name: 'guide_number', type: 'string', nullable: true)]private readonly string $guideNumber; + #[ORM\Column(name: 'guide_number', type: 'string', nullable: true)] + private ?string $guideNumber = ''; - /** - * @var string - */ - #[ORM\Column(name: 'purchase_price', type: 'money', nullable: true)]private readonly ?string $purchasePrice; - - /** - * @var string - */ #[ORM\Column(name: 'batteries', type: 'string', nullable: false)] private string $batteries = '4x AA'; - /** - * @var string - */ - #[ORM\Column(name: 'notes', type: 'text', nullable: true)]private readonly ?string $notes; + #[ORM\Column(name: 'notes', type: 'text', nullable: true)] + private readonly ?string $notes; - /** - * @var string - */ - #[ORM\Column(name: 'serial', type: 'string', nullable: true)]private readonly ?string $serial; + #[ORM\Column(name: 'serial', type: 'string', nullable: true)] + private readonly ?string $serial; - /** - * Get id - */ public function getId(): int { return $this->id; @@ -85,11 +49,9 @@ trait FlashTrait /** * Set brand * - * @param string $brand * - * @return self */ - public function setBrand($brand) + public function setBrand(string $brand): self { $this->brand = $brand; diff --git a/src/Entity/LensTrait.php b/src/Entity/LensTrait.php index 586d1ce..ae00e15 100644 --- a/src/Entity/LensTrait.php +++ b/src/Entity/LensTrait.php @@ -62,12 +62,6 @@ trait LensTrait #[ORM\Column(name: 'serial', type: 'string', length: 10, nullable: true)] private readonly ?string $serial; - /** - * @var string - */ - #[ORM\Column(name: 'purchase_price', type: 'money', nullable: true)] - private readonly ?string $purchasePrice; - /** * @var string */ diff --git a/src/Entity/Lenses.php b/src/Entity/Lenses.php index 18769f8..45f762d 100644 --- a/src/Entity/Lenses.php +++ b/src/Entity/Lenses.php @@ -18,8 +18,10 @@ class Lenses #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\SequenceGenerator(sequenceName: 'camera.lenses_id_seq', allocationSize: 1, initialValue: 1)] private int $id; + #[ORM\Column(name: 'received', type: 'boolean', nullable: false)] private bool $received = false; + #[ORM\Column(name: 'formerly_owned', type: 'boolean', nullable: false)] private bool $formerlyOwned = false; } diff --git a/src/Entity/PreviouslyOwnedFlash.php b/src/Entity/PreviouslyOwnedFlash.php index 70b83cb..9d831d8 100644 --- a/src/Entity/PreviouslyOwnedFlash.php +++ b/src/Entity/PreviouslyOwnedFlash.php @@ -12,21 +12,15 @@ use Doctrine\ORM\Mapping as ORM; class PreviouslyOwnedFlash { use FlashTrait; - /** - * @var integer - */ + #[ORM\Column(name: 'id', type: 'integer', nullable: false)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] - private $id; - /** - * @var boolean - */ + private int $id; + #[ORM\Column(name: 'received', type: 'boolean', nullable: false, options: ['default' => true])] private bool $received = true; - /** - * @var boolean - */ + #[ORM\Column(name: 'formerly_owned', type: 'boolean', nullable: false, options: ['default' => true])] private bool $formerlyOwned = true; } diff --git a/src/Entity/PreviouslyOwnedLenses.php b/src/Entity/PreviouslyOwnedLenses.php index 73cdd22..4a51a48 100644 --- a/src/Entity/PreviouslyOwnedLenses.php +++ b/src/Entity/PreviouslyOwnedLenses.php @@ -17,11 +17,13 @@ class PreviouslyOwnedLenses #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] private int $id; + /** * @var boolean */ #[ORM\Column(name: 'received', type: 'boolean', nullable: false)] private bool $received = true; + /** * @var boolean */ diff --git a/src/Entity/PurchasePriceTrait.php b/src/Entity/PurchasePriceTrait.php index 8d41a3a..3b264cd 100644 --- a/src/Entity/PurchasePriceTrait.php +++ b/src/Entity/PurchasePriceTrait.php @@ -2,29 +2,24 @@ namespace App\Entity; +use Doctrine\ORM\Mapping as ORM; + trait PurchasePriceTrait { - /** - * Set purchasePrice - * - * @param string $purchasePrice - */ - public function setPurchasePrice($purchasePrice): self + #[ORM\Column(name: 'purchase_price', type: 'money', nullable: true)] + private ?string $purchasePrice = null; + + public function setPurchasePrice(?string $purchasePrice): self { $this->purchasePrice = $purchasePrice; return $this; } - /** - * Get purchasePrice - * - * @return string - */ - public function getPurchasePrice() + public function getPurchasePrice(): string { if (empty($this->purchasePrice)) { - return 0; + return '0'; } return $this->purchasePrice; diff --git a/src/Types/MoneyType.php b/src/Types/MoneyType.php index 4b30e29..8ef44c7 100644 --- a/src/Types/MoneyType.php +++ b/src/Types/MoneyType.php @@ -1,4 +1,4 @@ -