From 41cf283fa49e60666149beb8171a5c455fc0c5a6 Mon Sep 17 00:00:00 2001 From: Laurent Constantin Date: Fri, 31 May 2024 10:28:59 +0200 Subject: [PATCH] WIP: Rename Kobo to KoboDevices --- rector.php | 3 +++ src/Controller/KoboAdminController.php | 22 +++++++++---------- src/Controller/KoboDownloadController.php | 8 +++---- src/Controller/KoboImageController.php | 4 ++-- .../KoboInitializationController.php | 4 ++-- src/Controller/KoboStateController.php | 6 ++--- src/Controller/KoboSyncController.php | 8 +++---- src/Controller/KoboTagController.php | 8 +++---- src/DataFixtures/KoboFixture.php | 4 ++-- src/Entity/{Kobo.php => KoboDevice.php} | 4 ++-- src/Entity/KoboSyncedBook.php | 6 ++--- src/Entity/Shelf.php | 12 +++++----- src/Entity/User.php | 6 ++--- src/Form/KoboType.php | 4 ++-- src/Kobo/DownloadHelper.php | 4 ++-- .../ParamConverter/KoboParamConverter.php | 8 +++---- src/Kobo/Response/MetadataResponseService.php | 6 ++--- src/Kobo/Response/SyncResponse.php | 4 ++-- src/Kobo/Response/SyncResponseFactory.php | 6 ++--- src/Repository/BookRepository.php | 14 ++++++------ ...epository.php => KoboDeviceRepository.php} | 16 +++++++------- src/Repository/KoboSyncedBookRepository.php | 8 +++---- src/Repository/ShelfRepository.php | 12 +++++----- .../Controller/AbstractKoboControllerTest.php | 10 ++++----- .../Controller/KoboDownloadControllerTest.php | 6 ++--- tests/Controller/KoboImageControllerTest.php | 6 ++--- 26 files changed, 101 insertions(+), 98 deletions(-) rename src/Entity/{Kobo.php => KoboDevice.php} (98%) rename src/Repository/{KoboRepository.php => KoboDeviceRepository.php} (72%) diff --git a/rector.php b/rector.php index 63401d94..b213c4f3 100644 --- a/rector.php +++ b/rector.php @@ -15,6 +15,9 @@ ->withRules([ AddVoidReturnTypeWhereNoReturnRector::class, ]) + ->withConfiguredRule(\Rector\Renaming\Rector\Name\RenameClassRector::class, [ + \App\Entity\Kobo::class => str_replace("Kobo", "KoboDevice", \App\Entity\Kobo::class), + ]) ->withImportNames(true, true, false, true) ->withSkip([ '**/config/bundles.php', diff --git a/src/Controller/KoboAdminController.php b/src/Controller/KoboAdminController.php index 5b94ba2e..a6d2a86a 100644 --- a/src/Controller/KoboAdminController.php +++ b/src/Controller/KoboAdminController.php @@ -2,9 +2,9 @@ namespace App\Controller; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Form\KoboType; -use App\Repository\KoboRepository; +use App\Repository\KoboDeviceRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -15,35 +15,35 @@ class KoboAdminController extends AbstractController { #[Route('/', name: 'app_kobo_admin_index', methods: ['GET'])] - public function index(KoboRepository $koboRepository): Response + public function index(KoboDeviceRepository $koboDeviceRepository): Response { return $this->render('kobo_admin/index.html.twig', [ - 'kobos' => $koboRepository->findAll(), + 'kobos' => $koboDeviceRepository->findAll(), ]); } #[Route('/new', name: 'app_kobo_admin_new', methods: ['GET', 'POST'])] public function new(Request $request, EntityManagerInterface $entityManager): Response { - $kobo = new Kobo(); - $form = $this->createForm(KoboType::class, $kobo); + $koboDevice = new KoboDevice(); + $form = $this->createForm(KoboType::class, $koboDevice); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $entityManager->persist($kobo); + $entityManager->persist($koboDevice); $entityManager->flush(); return $this->redirectToRoute('app_kobo_admin_index', [], Response::HTTP_SEE_OTHER); } return $this->render('kobo_admin/new.html.twig', [ - 'kobo' => $kobo, + 'kobo' => $koboDevice, 'form' => $form, ]); } #[Route('/{id}', name: 'app_kobo_admin_show', methods: ['GET'])] - public function show(Kobo $kobo): Response + public function show(KoboDevice $kobo): Response { return $this->render('kobo_admin/show.html.twig', [ 'kobo' => $kobo, @@ -51,7 +51,7 @@ public function show(Kobo $kobo): Response } #[Route('/{id}/edit', name: 'app_kobo_admin_edit', methods: ['GET', 'POST'])] - public function edit(Request $request, Kobo $kobo, EntityManagerInterface $entityManager): Response + public function edit(Request $request, KoboDevice $kobo, EntityManagerInterface $entityManager): Response { $form = $this->createForm(KoboType::class, $kobo); $form->handleRequest($request); @@ -69,7 +69,7 @@ public function edit(Request $request, Kobo $kobo, EntityManagerInterface $entit } #[Route('/{id}', name: 'app_kobo_admin_delete', methods: ['POST'])] - public function delete(Request $request, Kobo $kobo, EntityManagerInterface $entityManager): Response + public function delete(Request $request, KoboDevice $kobo, EntityManagerInterface $entityManager): Response { if ($this->isCsrfTokenValid('delete'.$kobo->getId(), (string) $request->request->get('_token'))) { $entityManager->remove($kobo); diff --git a/src/Controller/KoboDownloadController.php b/src/Controller/KoboDownloadController.php index 59a0918e..bb0470ea 100644 --- a/src/Controller/KoboDownloadController.php +++ b/src/Controller/KoboDownloadController.php @@ -3,7 +3,7 @@ namespace App\Controller; use App\Entity\Book; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Kobo\DownloadHelper; use App\Kobo\Proxy\KoboStoreProxy; use App\Repository\BookRepository; @@ -25,17 +25,17 @@ public function __construct( } #[Route('/v1/download/{id}.{extension}', name: 'download', requirements: ['bookId' => '\d+', 'extension' => '[A-Za-z0-9]+'], methods: ['GET'])] - public function download(Kobo $kobo, Book $book): Response + public function download(KoboDevice $kobo, Book $book): Response { $this->assertCanDownload($kobo, $book); return $this->downloadHelper->getResponse($book); } - private function assertCanDownload(Kobo $kobo, Book $book): void + private function assertCanDownload(KoboDevice $kobo, Book $book): void { // TODO Check permissions with is_granted and a dedicated voter ? - if (null === $this->bookRepository->findByIdAndKobo($book->getId() ?? 0, $kobo)) { + if (null === $this->bookRepository->findByIdAndKoboDevice($book->getId() ?? 0, $kobo)) { throw new AccessDeniedException('You are not allowed to download this book'); } } diff --git a/src/Controller/KoboImageController.php b/src/Controller/KoboImageController.php index d11f5b00..670b95e7 100644 --- a/src/Controller/KoboImageController.php +++ b/src/Controller/KoboImageController.php @@ -2,7 +2,7 @@ namespace App\Controller; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Kobo\DownloadHelper; use App\Kobo\Proxy\KoboProxyConfiguration; use App\Kobo\Proxy\KoboStoreProxy; @@ -42,7 +42,7 @@ public function __construct( #[Route('//{uuid}/{width}/{height}/false/image.jpg', name: 'image_quality_bad', defaults: ['isGreyscale' => false])] #[Route('/{uuid}/{width}/{height}/{Quality}/{isGreyscale}/image.jpg', name: 'image')] #[Route('//{uuid}/{width}/{height}/{Quality}/{isGreyscale}/image.jpg', name: 'image_bad')] - public function imageQuality(Request $request, Kobo $kobo, string $uuid, int $width, int $height, string $isGreyscale): Response + public function imageQuality(Request $request, KoboDevice $kobo, string $uuid, int $width, int $height, string $isGreyscale): Response { $isGreyscale = in_array($isGreyscale, ['true', 'True', '1'], true); $book = $this->bookRepository->findByUuidAndKobo($uuid, $kobo); diff --git a/src/Controller/KoboInitializationController.php b/src/Controller/KoboInitializationController.php index 75c44c35..81b40ef3 100644 --- a/src/Controller/KoboInitializationController.php +++ b/src/Controller/KoboInitializationController.php @@ -2,7 +2,7 @@ namespace App\Controller; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Kobo\Proxy\KoboProxyConfiguration; use App\Kobo\Proxy\KoboStoreProxy; use GuzzleHttp\Exception\GuzzleException; @@ -29,7 +29,7 @@ public function __construct( * @throws GuzzleException */ #[Route('/v1/initialization')] - public function initialization(Request $request, Kobo $kobo): Response + public function initialization(Request $request, KoboDevice $kobo): Response { $this->logger->info('Initialization request'); // Load the JSON data from the store diff --git a/src/Controller/KoboStateController.php b/src/Controller/KoboStateController.php index c4cf019b..8952e355 100644 --- a/src/Controller/KoboStateController.php +++ b/src/Controller/KoboStateController.php @@ -3,7 +3,7 @@ namespace App\Controller; use App\Entity\BookInteraction; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Kobo\Proxy\KoboStoreProxy; use App\Kobo\Request\ReadingStates; use App\Kobo\Request\ReadingStateStatusInfo; @@ -34,7 +34,7 @@ public function __construct( * Update reading state. **/ #[Route('/v1/library/{uuid}/state', name: 'api_endpoint_state_put', requirements: ['uuid' => '^[a-zA-Z0-9\-]+$'], methods: ['PUT'])] - public function state(Kobo $kobo, string $uuid, Request $request): Response|JsonResponse + public function state(KoboDevice $kobo, string $uuid, Request $request): Response|JsonResponse { $book = $this->bookRepository->findByUuidAndKobo($uuid, $kobo); @@ -92,7 +92,7 @@ public function state(Kobo $kobo, string $uuid, Request $request): Response|Json * @throws GuzzleException */ #[Route('/v1/library/{uuid}/state', name: 'api_endpoint_v1_getstate', requirements: ['uuid' => '^[a-zA-Z0-9\-]+$'], methods: ['GET'])] - public function getState(Kobo $kobo, string $uuid, Request $request): Response|JsonResponse + public function getState(KoboDevice $kobo, string $uuid, Request $request): Response|JsonResponse { if ($this->koboStoreProxy->isEnabled()) { return $this->koboStoreProxy->proxyOrRedirect($request); diff --git a/src/Controller/KoboSyncController.php b/src/Controller/KoboSyncController.php index 820766b8..36691259 100644 --- a/src/Controller/KoboSyncController.php +++ b/src/Controller/KoboSyncController.php @@ -3,7 +3,7 @@ namespace App\Controller; use App\Entity\Book; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Kobo\Proxy\KoboProxyConfiguration; use App\Kobo\Proxy\KoboStoreProxy; use App\Kobo\Response\SyncResponseFactory; @@ -43,12 +43,12 @@ public function __construct( * See KoboSyncTokenExtractor and Kobo * Both * Kobo will call this url multiple times if there are more book to sync (x-kobo-sync: continue) - * @param Kobo $kobo The kobo entity is retrieved via the accessKey in the url + * @param KoboDevice $kobo The kobo entity is retrieved via the accessKey in the url * @param SyncToken $syncToken It's provided from HTTP Headers + Get parameters, see SyncTokenParamConverter and KoboSyncTokenExtractor * @return Response **/ #[Route('/v1/library/sync', name: 'api_endpoint_v1_library_sync')] - public function apiEndpoint(Kobo $kobo, SyncToken $syncToken, Request $request): Response + public function apiEndpoint(KoboDevice $kobo, SyncToken $syncToken, Request $request): Response { $forced = $kobo->isForceSync() || $request->query->has('force'); $count = $this->koboSyncedBookRepository->countByKobo($kobo); @@ -91,7 +91,7 @@ public function apiEndpoint(Kobo $kobo, SyncToken $syncToken, Request $request): } #[Route('/v1/library/{uuid}/metadata', name: 'api_endpoint_v1_library_metadata')] - public function metadataEndpoint(Kobo $kobo, ?Book $book, Request $request): Response + public function metadataEndpoint(KoboDevice $kobo, ?Book $book, Request $request): Response { if ($book === null) { if ($this->koboStoreProxy->isEnabled()) { diff --git a/src/Controller/KoboTagController.php b/src/Controller/KoboTagController.php index 067ea3b1..183ce3ed 100644 --- a/src/Controller/KoboTagController.php +++ b/src/Controller/KoboTagController.php @@ -2,7 +2,7 @@ namespace App\Controller; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Entity\Shelf; use App\Kobo\Proxy\KoboStoreProxy; use App\Kobo\Request\TagDeleteRequest; @@ -35,7 +35,7 @@ public function __construct( * Yep, a POST for a DELETE, it's how Kobo does it */ #[Route('/v1/library/tags/{tagId}/items/delete', methods: ['POST'])] - public function delete(Request $request, Kobo $kobo, string $tagId): Response + public function delete(Request $request, KoboDevice $kobo, string $tagId): Response { if ($this->koboStoreProxy->isEnabled()) { return $this->koboStoreProxy->proxy($request); @@ -67,7 +67,7 @@ public function delete(Request $request, Kobo $kobo, string $tagId): Response #[Route('/v1/library/tags')] #[Route('/v1/library/tags/{tagId}')] - public function tags(Request $request, Kobo $kobo, ?string $tagId = null): Response + public function tags(Request $request, KoboDevice $kobo, ?string $tagId = null): Response { try { $content = $request->getContent(); @@ -110,7 +110,7 @@ public function tags(Request $request, Kobo $kobo, ?string $tagId = null): Respo return new JsonResponse($shelf->getId(), 201); } - private function findShelfByNameOrTagId(Kobo $kobo, ?string $name, ?string $tagId): ?Shelf + private function findShelfByNameOrTagId(KoboDevice $kobo, ?string $name, ?string $tagId): ?Shelf { if ($tagId !== null) { return $this->shelfRepository->findByKoboAndUuid($kobo, $tagId); diff --git a/src/DataFixtures/KoboFixture.php b/src/DataFixtures/KoboFixture.php index 67504e2d..7ec8e0f9 100644 --- a/src/DataFixtures/KoboFixture.php +++ b/src/DataFixtures/KoboFixture.php @@ -2,7 +2,7 @@ namespace App\DataFixtures; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Entity\User; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Common\DataFixtures\DependentFixtureInterface; @@ -14,7 +14,7 @@ class KoboFixture extends Fixture implements DependentFixtureInterface public function load(ObjectManager $manager): void { - $kobo = new Kobo(); + $kobo = new KoboDevice(); $kobo->setAccessKey('0000-0000-0000-0000'); $kobo->setName('test kobo'); $kobo->setUser($this->getUser()); diff --git a/src/Entity/Kobo.php b/src/Entity/KoboDevice.php similarity index 98% rename from src/Entity/Kobo.php rename to src/Entity/KoboDevice.php index 5c357a10..144131df 100644 --- a/src/Entity/Kobo.php +++ b/src/Entity/KoboDevice.php @@ -12,7 +12,7 @@ #[ORM\Entity(repositoryClass: KoboRepository::class)] #[ORM\UniqueConstraint(name: 'kobo_access_key', columns: ['access_key'])] #[UniqueEntity(fields: ['accessKey'])] -class Kobo +class KoboDevice { use RandomGeneratorTrait; #[ORM\Id] @@ -78,7 +78,7 @@ public function getShelves(): Collection return $this->shelves; } - public function setName(?string $name): Kobo + public function setName(?string $name): KoboDevice { $this->name = $name; diff --git a/src/Entity/KoboSyncedBook.php b/src/Entity/KoboSyncedBook.php index bc8ed771..36bdb4b6 100644 --- a/src/Entity/KoboSyncedBook.php +++ b/src/Entity/KoboSyncedBook.php @@ -21,7 +21,7 @@ class KoboSyncedBook #[ORM\ManyToOne(inversedBy: 'koboSyncedBooks')] #[ORM\JoinColumn(nullable: false)] - private ?Kobo $kobo = null; + private ?KoboDevice $kobo = null; #[ORM\Column(type: Types::DATETIME_MUTABLE)] #[Gedmo\Timestampable(on: 'create')] @@ -48,12 +48,12 @@ public function setBook(?Book $book): static return $this; } - public function getKobo(): ?Kobo + public function getKobo(): ?KoboDevice { return $this->kobo; } - public function setKobo(?Kobo $kobo): static + public function setKobo(?KoboDevice $kobo): static { $this->kobo = $kobo; diff --git a/src/Entity/Shelf.php b/src/Entity/Shelf.php index a1add790..d691039c 100644 --- a/src/Entity/Shelf.php +++ b/src/Entity/Shelf.php @@ -36,9 +36,9 @@ class Shelf private string $slug; /** - * @var Collection + * @var Collection */ - #[ORM\ManyToMany(targetEntity: Kobo::class, mappedBy: 'shelves')] + #[ORM\ManyToMany(targetEntity: KoboDevice::class, mappedBy: 'shelves')] private Collection $kobos; #[ORM\Column(type: Types::JSON, nullable: true)] @@ -145,7 +145,7 @@ public function setQueryString(?array $queryString): static } /** - * @param Collection $collection + * @param Collection $collection */ public function setKobos(Collection $collection): self { @@ -154,7 +154,7 @@ public function setKobos(Collection $collection): self return $this; } - public function addKobo(Kobo $kobo): self + public function addKobo(KoboDevice $kobo): self { if (!$this->kobos->contains($kobo)) { $this->kobos->add($kobo); @@ -164,7 +164,7 @@ public function addKobo(Kobo $kobo): self return $this; } - public function removeKobo(Kobo $kobo): self + public function removeKobo(KoboDevice $kobo): self { if ($this->kobos->contains($kobo)) { $this->kobos->removeElement($kobo); @@ -175,7 +175,7 @@ public function removeKobo(Kobo $kobo): self } /** - * @return Collection + * @return Collection */ public function getKobos(): Collection { diff --git a/src/Entity/User.php b/src/Entity/User.php index e82a86e5..eebfacf1 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -90,9 +90,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface private ?string $theme = null; /** - * @var Collection + * @var Collection */ - #[ORM\OneToMany(mappedBy: 'user', targetEntity: Kobo::class, orphanRemoval: true)] + #[ORM\OneToMany(mappedBy: 'user', targetEntity: KoboDevice::class, orphanRemoval: true)] private Collection $kobos; public function __construct() @@ -385,7 +385,7 @@ public function setTheme(?string $theme): static } /** - * @return Collection + * @return Collection */ public function getKobos(): Collection { diff --git a/src/Form/KoboType.php b/src/Form/KoboType.php index df7ed1be..47a3cc04 100644 --- a/src/Form/KoboType.php +++ b/src/Form/KoboType.php @@ -2,7 +2,7 @@ namespace App\Form; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Entity\Shelf; use App\Entity\User; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -38,7 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'data_class' => Kobo::class, + 'data_class' => KoboDevice::class, ]); } } diff --git a/src/Kobo/DownloadHelper.php b/src/Kobo/DownloadHelper.php index f9b03e1c..edc63d61 100644 --- a/src/Kobo/DownloadHelper.php +++ b/src/Kobo/DownloadHelper.php @@ -3,7 +3,7 @@ namespace App\Kobo; use App\Entity\Book; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Exception\BookFileNotFound; use App\Kobo\ImageProcessor\CoverTransformer; use App\Service\BookFileSystemManager; @@ -42,7 +42,7 @@ public function isEpub3(Book $book): bool return $book->getExtension() === 'epub3' || $this->readEpubVersionIs3($book) === true; } - public function getUrlForKobo(Book $book, Kobo $kobo): string + public function getUrlForKobo(Book $book, KoboDevice $kobo): string { return $this->urlGenerator->generate('app_kobodownload', [ 'id' => $book->getId(), diff --git a/src/Kobo/ParamConverter/KoboParamConverter.php b/src/Kobo/ParamConverter/KoboParamConverter.php index 9fbf7774..969ecf8f 100644 --- a/src/Kobo/ParamConverter/KoboParamConverter.php +++ b/src/Kobo/ParamConverter/KoboParamConverter.php @@ -2,7 +2,7 @@ namespace App\Kobo\ParamConverter; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Repository\KoboRepository; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use Symfony\Component\HttpFoundation\Request; @@ -18,10 +18,10 @@ public function __construct(protected KoboRepository $bookRepository) public function supports(Request $request, ArgumentMetadata $argument): bool { - return $argument->getType() === Kobo::class && $this->getFieldValue($request) !== null; + return $argument->getType() === KoboDevice::class && $this->getFieldValue($request) !== null; } - public function apply(Request $request): ?Kobo + public function apply(Request $request): ?KoboDevice { $value = $this->getFieldValue($request); @@ -29,7 +29,7 @@ public function apply(Request $request): ?Kobo } /** - * @return array + * @return array */ public function resolve(Request $request, ArgumentMetadata $argument): iterable { diff --git a/src/Kobo/Response/MetadataResponseService.php b/src/Kobo/Response/MetadataResponseService.php index da3cb2b9..d6f93a9d 100644 --- a/src/Kobo/Response/MetadataResponseService.php +++ b/src/Kobo/Response/MetadataResponseService.php @@ -3,7 +3,7 @@ namespace App\Kobo\Response; use App\Entity\Book; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Kobo\DownloadHelper; use App\Kobo\SyncToken; @@ -13,7 +13,7 @@ public function __construct(protected DownloadHelper $downloadHelper) { } - protected function getDownloadUrls(Book $book, Kobo $kobo, ?array $filters = []): array + protected function getDownloadUrls(Book $book, KoboDevice $kobo, ?array $filters = []): array { $platforms = $filters['DownloadUrlFilter'] ?? []; $platform = reset($platforms); @@ -35,7 +35,7 @@ protected function getDownloadUrls(Book $book, Kobo $kobo, ?array $filters = []) return $response; } - public function fromBook(Book $book, Kobo $kobo, ?SyncToken $syncToken = null): array + public function fromBook(Book $book, KoboDevice $kobo, ?SyncToken $syncToken = null): array { $data = [ 'Categories' => ['00000000-0000-0000-0000-000000000001'], diff --git a/src/Kobo/Response/SyncResponse.php b/src/Kobo/Response/SyncResponse.php index c42898fa..a57a4dc9 100644 --- a/src/Kobo/Response/SyncResponse.php +++ b/src/Kobo/Response/SyncResponse.php @@ -3,7 +3,7 @@ namespace App\Kobo\Response; use App\Entity\Book; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Entity\Shelf; use App\Kobo\SyncToken; use Symfony\Component\HttpFoundation\JsonResponse; @@ -31,7 +31,7 @@ class SyncResponse public const READING_STATUS_FINISHED = 'Finished'; public const READING_STATUS_IN_PROGRESS = 'Reading'; - public function __construct(protected MetadataResponseService $metadataResponse, protected SyncToken $syncToken, protected Kobo $kobo, protected SerializerInterface $serializer) + public function __construct(protected MetadataResponseService $metadataResponse, protected SyncToken $syncToken, protected KoboDevice $kobo, protected SerializerInterface $serializer) { } diff --git a/src/Kobo/Response/SyncResponseFactory.php b/src/Kobo/Response/SyncResponseFactory.php index 80bef155..1b943aed 100644 --- a/src/Kobo/Response/SyncResponseFactory.php +++ b/src/Kobo/Response/SyncResponseFactory.php @@ -3,7 +3,7 @@ namespace App\Kobo\Response; use App\Entity\Book; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Kobo\SyncToken; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Serializer\SerializerInterface; @@ -17,12 +17,12 @@ public function __construct(protected MetadataResponseService $metadataResponseS { } - public function create(SyncToken $syncToken, Kobo $kobo): SyncResponse + public function create(SyncToken $syncToken, KoboDevice $kobo): SyncResponse { return new SyncResponse($this->metadataResponseService, $syncToken, $kobo, $this->serializer); } - public function createMetadata(Kobo $kobo, Book $book): JsonResponse + public function createMetadata(KoboDevice $kobo, Book $book): JsonResponse { return new JsonResponse([$this->metadataResponseService->fromBook($book, $kobo)]); } diff --git a/src/Repository/BookRepository.php b/src/Repository/BookRepository.php index 34f2a0c2..b1e9986c 100644 --- a/src/Repository/BookRepository.php +++ b/src/Repository/BookRepository.php @@ -3,7 +3,7 @@ namespace App\Repository; use App\Entity\Book; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Kobo\SyncToken; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\Query; @@ -310,11 +310,11 @@ public function flush(): void } /** - * @param Kobo $kobo + * @param KoboDevice $kobo * @param SyncToken $syncToken * @return array */ - public function getChangedBooks(Kobo $kobo, SyncToken $syncToken, int $firstResult, int $maxResults): array + public function getChangedBooks(KoboDevice $kobo, SyncToken $syncToken, int $firstResult, int $maxResults): array { $qb = $this->getChangedBooksQueryBuilder($kobo, $syncToken); $qb->setFirstResult($firstResult) @@ -326,7 +326,7 @@ public function getChangedBooks(Kobo $kobo, SyncToken $syncToken, int $firstResu return $result; } - public function getChangedBooksCount(Kobo $kobo, SyncToken $syncToken): int + public function getChangedBooksCount(KoboDevice $kobo, SyncToken $syncToken): int { $qb = $this->getChangedBooksQueryBuilder($kobo, $syncToken); $qb->select('count(book.id) as nb'); @@ -334,7 +334,7 @@ public function getChangedBooksCount(Kobo $kobo, SyncToken $syncToken): int return (int) $qb->getQuery()->getSingleColumnResult(); } - private function getChangedBooksQueryBuilder(Kobo $kobo, SyncToken $syncToken): QueryBuilder + private function getChangedBooksQueryBuilder(KoboDevice $kobo, SyncToken $syncToken): QueryBuilder { $qb = $this->createQueryBuilder('book') ->select('book', 'koboSyncedBooks', 'bookInteractions') @@ -376,7 +376,7 @@ private function getChangedBooksQueryBuilder(Kobo $kobo, SyncToken $syncToken): return $qb; } - public function findByIdAndKobo(int $bookId, Kobo $kobo): ?Book + public function findByIdAndKoboDevice(int $bookId, KoboDevice $kobo): ?Book { /** @var Book|null $result */ $result = $this->createQueryBuilder('book') @@ -393,7 +393,7 @@ public function findByIdAndKobo(int $bookId, Kobo $kobo): ?Book return $result; } - public function findByUuidAndKobo(string $bookUuid, Kobo $kobo): ?Book + public function findByUuidAndKobo(string $bookUuid, KoboDevice $kobo): ?Book { /** @var Book|null $result */ $result = $this->createQueryBuilder('book') diff --git a/src/Repository/KoboRepository.php b/src/Repository/KoboDeviceRepository.php similarity index 72% rename from src/Repository/KoboRepository.php rename to src/Repository/KoboDeviceRepository.php index a6897e81..42f11385 100644 --- a/src/Repository/KoboRepository.php +++ b/src/Repository/KoboDeviceRepository.php @@ -2,22 +2,22 @@ namespace App\Repository; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Security\Core\User\UserInterface; /** - * @extends ServiceEntityRepository + * @extends ServiceEntityRepository */ -class KoboRepository extends ServiceEntityRepository +class KoboDeviceRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { - parent::__construct($registry, Kobo::class); + parent::__construct($registry, KoboDevice::class); } - public function byAccessKey(string $token): ?Kobo + public function byAccessKey(string $token): ?KoboDevice { $query = $this->createQueryBuilder('kobo') ->select('kobo', 'user') @@ -25,7 +25,7 @@ public function byAccessKey(string $token): ?Kobo ->where('kobo.accessKey = :accessKey') ->setParameter('accessKey', $token) ->getQuery(); - /** @var Kobo|null $result */ + /** @var KoboDevice|null $result */ $result = $query->getOneOrNullResult(); return $result; @@ -33,7 +33,7 @@ public function byAccessKey(string $token): ?Kobo /** * @param UserInterface|null $user - * @return array + * @return array */ public function findAllByUser(?UserInterface $user = null): array { @@ -46,7 +46,7 @@ public function findAllByUser(?UserInterface $user = null): array ->where('kobo.user = :user') ->setParameter('user', $user) ->getQuery(); - /** @var Kobo[] $result */ + /** @var \App\Entity\KoboDevice[] $result */ $result = $query->getResult(); return $result; diff --git a/src/Repository/KoboSyncedBookRepository.php b/src/Repository/KoboSyncedBookRepository.php index 4cae4ef1..e14b5e4f 100644 --- a/src/Repository/KoboSyncedBookRepository.php +++ b/src/Repository/KoboSyncedBookRepository.php @@ -3,7 +3,7 @@ namespace App\Repository; use App\Entity\Book; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Entity\KoboSyncedBook; use App\Kobo\SyncToken; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; @@ -49,7 +49,7 @@ public function __construct(ManagerRegistry $registry) // ->getOneOrNullResult() // ; // } - public function updateSyncedBooks(Kobo $kobo, array $books, SyncToken $syncToken): void + public function updateSyncedBooks(KoboDevice $kobo, array $books, SyncToken $syncToken): void { $updatedAt = $syncToken->lastModified ?? new \DateTime(); @@ -103,7 +103,7 @@ public function updateSyncedBooks(Kobo $kobo, array $books, SyncToken $syncToken $this->_em->flush(); } - public function deleteAllSyncedBooks(Kobo|int $koboId): int + public function deleteAllSyncedBooks(KoboDevice|int $koboId): int { $query = $this->createQueryBuilder('koboSyncedBook') ->delete() @@ -118,7 +118,7 @@ public function deleteAllSyncedBooks(Kobo|int $koboId): int return $result; } - public function countByKobo(Kobo $kobo): int + public function countByKobo(KoboDevice $kobo): int { /** @var int $result */ $result = $this->createQueryBuilder('koboSyncedBook') diff --git a/src/Repository/ShelfRepository.php b/src/Repository/ShelfRepository.php index 593422d5..d96fd48f 100644 --- a/src/Repository/ShelfRepository.php +++ b/src/Repository/ShelfRepository.php @@ -2,7 +2,7 @@ namespace App\Repository; -use App\Entity\Kobo; +use App\Entity\KoboDevice; use App\Entity\Shelf; use App\Kobo\SyncToken; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; @@ -48,7 +48,7 @@ public function __construct(ManagerRegistry $registry) // ->getOneOrNullResult() // ; // } - public function findByKoboAndId(Kobo $kobo, string $shelfId): ?Shelf + public function findByKoboAndId(KoboDevice $kobo, string $shelfId): ?Shelf { $qb = $this->createQueryBuilder('shelf') ->select('shelf') @@ -65,7 +65,7 @@ public function findByKoboAndId(Kobo $kobo, string $shelfId): ?Shelf return $result; } - public function findByKoboAndName(Kobo $kobo, mixed $name): ?Shelf + public function findByKoboAndName(KoboDevice $kobo, mixed $name): ?Shelf { $qb = $this->createQueryBuilder('shelf') ->select('shelf') @@ -83,11 +83,11 @@ public function findByKoboAndName(Kobo $kobo, mixed $name): ?Shelf } /** - * @param Kobo $kobo + * @param KoboDevice $kobo * @param SyncToken $syncToken * @return array */ - public function getShelvesToSync(Kobo $kobo, SyncToken $syncToken): array + public function getShelvesToSync(KoboDevice $kobo, SyncToken $syncToken): array { $qb = $this->createQueryBuilder('shelf') ->select('shelf') @@ -112,7 +112,7 @@ public function getShelvesToSync(Kobo $kobo, SyncToken $syncToken): array /** * @throws NonUniqueResultException */ - public function findByKoboAndUuid(Kobo $kobo, string $uuid): ?Shelf + public function findByKoboAndUuid(KoboDevice $kobo, string $uuid): ?Shelf { $qb = $this->createQueryBuilder('shelf') ->select('shelf') diff --git a/tests/Controller/AbstractKoboControllerTest.php b/tests/Controller/AbstractKoboControllerTest.php index 231501a2..da42c7bb 100644 --- a/tests/Controller/AbstractKoboControllerTest.php +++ b/tests/Controller/AbstractKoboControllerTest.php @@ -2,9 +2,9 @@ namespace App\Tests\Controller; +use App\Entity\KoboDevice; use App\DataFixtures\BookFixture; use App\Entity\Book; -use App\Entity\Kobo; use App\Service\BookFileSystemManager; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\NullLogger; @@ -18,7 +18,7 @@ abstract class AbstractKoboControllerTest extends WebTestCase const DEFAULT_BOOK_FOLDER_NAMING_FORMAT = '{authorFirst}/{author}/{title}/{serie}'; protected ?string $accessKey = null; - protected ?Kobo $kobo = null; + protected ?KoboDevice $kobo = null; protected function getEntityManager(): EntityManagerInterface{ /** @var EntityManagerInterface $entityManager */ @@ -35,7 +35,7 @@ protected function setUp(): void $this->accessKey = $this->kobo->getAccessKey(); } - public function getKobo(bool $refresh = false): Kobo + public function getKobo(bool $refresh = false): KoboDevice { if($refresh && $this->kobo !== null){ $this->getEntityManager()->refresh($this->kobo); @@ -72,9 +72,9 @@ protected static function getJsonResponse(): array return (array)json_decode($content, true, 512, JSON_THROW_ON_ERROR); } - private function loadKobo(): Kobo + private function loadKobo(): KoboDevice { - $kobo = $this->getEntityManager()->getRepository(Kobo::class)->findOneBy(['id' => 1]); + $kobo = $this->getEntityManager()->getRepository(KoboDevice::class)->findOneBy(['id' => 1]); if($kobo === null) { throw new \RuntimeException('Unable to find a Kobo, please load fixtures'); } diff --git a/tests/Controller/KoboDownloadControllerTest.php b/tests/Controller/KoboDownloadControllerTest.php index c9f2bd85..c4250f8c 100644 --- a/tests/Controller/KoboDownloadControllerTest.php +++ b/tests/Controller/KoboDownloadControllerTest.php @@ -2,9 +2,9 @@ namespace App\Tests\Controller; +use App\Entity\KoboDevice; use App\DataFixtures\BookFixture; use App\Entity\Book; -use App\Entity\Kobo; use App\Kobo\DownloadHelper; class KoboDownloadControllerTest extends AbstractKoboControllerTest @@ -34,8 +34,8 @@ public function testDownload(): void } - private function findByIdAndKobo(int $bookId, Kobo $kobo): ?Book + private function findByIdAndKobo(int $bookId, KoboDevice $kobo): ?Book { - return $this->getEntityManager()->getRepository(Book::class)->findByIdAndKobo($bookId, $kobo); + return $this->getEntityManager()->getRepository(Book::class)->findByIdAndKoboDevice($bookId, $kobo); } } \ No newline at end of file diff --git a/tests/Controller/KoboImageControllerTest.php b/tests/Controller/KoboImageControllerTest.php index 720212f6..2a4219bd 100644 --- a/tests/Controller/KoboImageControllerTest.php +++ b/tests/Controller/KoboImageControllerTest.php @@ -2,9 +2,9 @@ namespace App\Tests\Controller; +use App\Entity\KoboDevice; use App\DataFixtures\BookFixture; use App\Entity\Book; -use App\Entity\Kobo; use App\Kobo\DownloadHelper; class KoboImageControllerTest extends AbstractKoboControllerTest @@ -29,8 +29,8 @@ public function testDownload(): void self::assertResponseHeaderSame('Content-Type', 'image/jpeg'); } - private function findByIdAndKobo(int $bookId, Kobo $kobo): ?Book + private function findByIdAndKobo(int $bookId, KoboDevice $kobo): ?Book { - return $this->getEntityManager()->getRepository(Book::class)->findByIdAndKobo($bookId, $kobo); + return $this->getEntityManager()->getRepository(Book::class)->findByIdAndKoboDevice($bookId, $kobo); } } \ No newline at end of file