Skip to content

Commit

Permalink
WIP: Rename Kobo to KoboDevices
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusa87 committed May 31, 2024
1 parent c1b9a6e commit 41cf283
Show file tree
Hide file tree
Showing 26 changed files with 101 additions and 98 deletions.
3 changes: 3 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
22 changes: 11 additions & 11 deletions src/Controller/KoboAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,43 +15,43 @@
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,
]);
}

#[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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/KoboDownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/KoboImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/KoboInitializationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/KoboStateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/KoboSyncController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/KoboTagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/DataFixtures/KoboFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/Kobo.php → src/Entity/KoboDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#[ORM\Entity(repositoryClass: KoboRepository::class)]

Check failure on line 12 in src/Entity/KoboDevice.php

View workflow job for this annotation

GitHub Actions / symfony-tests (0.23.1)

Class App\Repository\KoboRepository not found.

Check failure on line 12 in src/Entity/KoboDevice.php

View workflow job for this annotation

GitHub Actions / symfony-tests (0.23.1)

Parameter $repositoryClass of attribute class Doctrine\ORM\Mapping\Entity constructor expects class-string<Doctrine\ORM\EntityRepository<T of object>>|null, 'App\\Repository\\KoboRepository' given.
#[ORM\UniqueConstraint(name: 'kobo_access_key', columns: ['access_key'])]
#[UniqueEntity(fields: ['accessKey'])]
class Kobo
class KoboDevice
{
use RandomGeneratorTrait;
#[ORM\Id]
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/Entity/KoboSyncedBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand All @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/Entity/Shelf.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Shelf
private string $slug;

/**
* @var Collection<int, Kobo>
* @var Collection<int, \App\Entity\KoboDevice>
*/
#[ORM\ManyToMany(targetEntity: Kobo::class, mappedBy: 'shelves')]
#[ORM\ManyToMany(targetEntity: KoboDevice::class, mappedBy: 'shelves')]
private Collection $kobos;

#[ORM\Column(type: Types::JSON, nullable: true)]
Expand Down Expand Up @@ -145,7 +145,7 @@ public function setQueryString(?array $queryString): static
}

/**
* @param Collection<int, Kobo> $collection
* @param Collection<int, \App\Entity\KoboDevice> $collection
*/
public function setKobos(Collection $collection): self
{
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -175,7 +175,7 @@ public function removeKobo(Kobo $kobo): self
}

/**
* @return Collection<int, Kobo>
* @return Collection<int, \App\Entity\KoboDevice>
*/
public function getKobos(): Collection
{
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
private ?string $theme = null;

/**
* @var Collection<int, Kobo>
* @var Collection<int, \App\Entity\KoboDevice>
*/
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Kobo::class, orphanRemoval: true)]
#[ORM\OneToMany(mappedBy: 'user', targetEntity: KoboDevice::class, orphanRemoval: true)]
private Collection $kobos;

public function __construct()
Expand Down Expand Up @@ -385,7 +385,7 @@ public function setTheme(?string $theme): static
}

/**
* @return Collection<int,Kobo>
* @return Collection<int, \App\Entity\KoboDevice>
*/
public function getKobos(): Collection
{
Expand Down
4 changes: 2 additions & 2 deletions src/Form/KoboType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
]);
}
}
Loading

0 comments on commit 41cf283

Please sign in to comment.