diff --git a/migrations/Version20211219140506.php b/migrations/Version20211219140506.php index 842ef34..c9e01e5 100644 --- a/migrations/Version20211219140506.php +++ b/migrations/Version20211219140506.php @@ -17,14 +17,16 @@ public function getDescription(): string return 'Add default group for mascots'; } - public function up(Schema $schema): void - { + public function up( + Schema $schema + ): void { // this up() migration is auto-generated, please modify it to your needs $this->addSql('ALTER TABLE mascot_group ADD default_group BOOLEAN DEFAULT \'false\' NOT NULL'); } - public function down(Schema $schema): void - { + public function down( + Schema $schema + ): void { // this down() migration is auto-generated, please modify it to your needs $this->addSql('CREATE SCHEMA public'); $this->addSql('ALTER TABLE mascot_group DROP default_group'); diff --git a/src/Command/RssSearchCommand.php b/src/Command/RssSearchCommand.php index da6f4a0..71c62d3 100644 --- a/src/Command/RssSearchCommand.php +++ b/src/Command/RssSearchCommand.php @@ -42,6 +42,7 @@ protected function execute( ): int { $io = new SymfonyStyle($input, $output); $count = 0; + foreach ($this->searchRepository->findBy(['active' => true]) as $search) { $response = $this->client->request( 'GET', diff --git a/src/Controller/Admin/DashboardController.php b/src/Controller/Admin/DashboardController.php index f589075..11baba9 100644 --- a/src/Controller/Admin/DashboardController.php +++ b/src/Controller/Admin/DashboardController.php @@ -13,7 +13,7 @@ class DashboardController extends AbstractDashboardController { - #[Route("/")] + #[Route('/')] public function index(): Response { return $this->render('admin/dashboard.html.twig'); diff --git a/src/Controller/Admin/Rss/SearchCrudController.php b/src/Controller/Admin/Rss/SearchCrudController.php index f0bda27..3159b9d 100644 --- a/src/Controller/Admin/Rss/SearchCrudController.php +++ b/src/Controller/Admin/Rss/SearchCrudController.php @@ -12,7 +12,8 @@ class SearchCrudController extends AbstractCrudController { - public static function getEntityFqcn(): string { + public static function getEntityFqcn(): string + { return Search::class; } diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index da7df51..16d1ea9 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -33,7 +33,7 @@ public function __construct( ) { } - #[Route("/", name: 'front.index')] + #[Route('/', name: 'front.index')] public function index( string $BASE_TEMPLATE, MascotService $mascotService, @@ -83,6 +83,7 @@ public function recache( TagAwareCacheInterface $cache ): RedirectResponse { $cache->invalidateTags([MascotService::TAG]); + return $this->redirectToRoute('front.index'); } @@ -91,6 +92,7 @@ public function proxy( Result $file ): Response { $response = $this->client->request('GET', $file->getUrl()); + if (Response::HTTP_OK !== $response->getStatusCode()) { return new Response('Failed to download file', 500); } @@ -110,6 +112,7 @@ public function proxyWithApi( if (!$service->addTorrent($file)) { return new Response('Failed to add new torrent via api', 500); } + return $this->redirectToRoute('front.index'); } @@ -117,27 +120,22 @@ public function proxyWithApi( public function setAllAsSeen(): RedirectResponse { $this->resultRepository->setAllAsSeen(); + return $this->redirectToRoute('front.index'); } #[Route('/set-mascot-group/{group}', name: 'front.set_mascot_group')] public function setMascotGroup( - ?MascotGroup $group + MascotGroup|null $group ): RedirectResponse { $this->getSession()?->set(SessionOptions::MASCOT_GROUP->value, $group); $this->getSession()?->set(SessionOptions::MASCOT_COUNTER->value, 0); + return $this->redirectToRoute('front.index'); } /** - * Generate a download - * - * @param string $contents - * @param string $filename - * @param string $mime - * @param string $disposition - * - * @return Response + * Generate a download. */ protected function download( string $contents, @@ -152,7 +150,7 @@ protected function download( $response->headers->set('Content-Type', $mime); $response->headers->set( 'Content-Disposition', - $response->headers->makeDisposition($disposition, $filename, 'file.'.$ext[count($ext)-1]) + $response->headers->makeDisposition($disposition, $filename, 'file.'.$ext[count($ext) - 1]) ); $response->setContent($contents); diff --git a/src/Entity/MascotGroup.php b/src/Entity/MascotGroup.php index fd9467b..dabf4e6 100644 --- a/src/Entity/MascotGroup.php +++ b/src/Entity/MascotGroup.php @@ -12,23 +12,23 @@ class MascotGroup #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private ?int $id; + private int|null $id; #[ORM\Column(type: Types::STRING, length: 255)] - private ?string $title; + private string|null $title; - #[ORM\Column(type: Types::ARRAY)] + #[ORM\Column(type: Types::JSON)] private array $directories = []; #[ORM\Column(options: ['default' => false])] - private ?bool $defaultGroup = false; + private bool|null $defaultGroup = false; - public function getId(): ?int + public function getId(): int|null { return $this->id; } - public function getTitle(): ?string + public function getTitle(): string|null { return $this->title; } @@ -41,7 +41,7 @@ public function setTitle( return $this; } - public function getDirectories(): ?array + public function getDirectories(): array|null { return $this->directories; } @@ -54,7 +54,7 @@ public function setDirectories( return $this; } - public function getDefaultGroup(): ?bool + public function getDefaultGroup(): bool|null { return $this->defaultGroup; } diff --git a/src/Entity/Rss/Group.php b/src/Entity/Rss/Group.php index 27edba0..9c51aa3 100644 --- a/src/Entity/Rss/Group.php +++ b/src/Entity/Rss/Group.php @@ -14,20 +14,26 @@ class Group #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private ?int $id; + private int|null $id; #[ORM\Column(type: Types::STRING, length: 50)] - private ?string $name; + private string|null $name; #[ORM\Column(type: Types::STRING, length: 255)] - private ?string $url; + private string|null $url; - public function getId(): ?int + #[Pure] + public function __toString(): string + { + return $this->getName() ?? 'Unknown'; + } + + public function getId(): int|null { return $this->id; } - public function getName(): ?string + public function getName(): string|null { return $this->name; } @@ -40,7 +46,7 @@ public function setName( return $this; } - public function getUrl(): ?string + public function getUrl(): string|null { return $this->url; } @@ -52,10 +58,4 @@ public function setUrl( return $this; } - - #[Pure] - public function __toString(): string - { - return $this->getName() ?? 'Unknown'; - } } diff --git a/src/Entity/Rss/Result.php b/src/Entity/Rss/Result.php index 3aca85e..810f794 100644 --- a/src/Entity/Rss/Result.php +++ b/src/Entity/Rss/Result.php @@ -13,32 +13,32 @@ class Result #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private ?int $id; + private int|null $id; #[ORM\Column(type: Types::TEXT)] - private ?string $url; + private string|null $url; #[ORM\Column(type: Types::TEXT)] - private ?string $title; + private string|null $title; #[ORM\Column(type: Types::JSON)] private array $data = []; #[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)] - private ?\DateTimeImmutable $seenAt; + private \DateTimeImmutable|null $seenAt; #[ORM\Column(type: Types::STRING, length: 255)] - private ?string $guid; + private string|null $guid; #[ORM\ManyToOne] - private ?Search $search; + private Search|null $search; - public function getId(): ?int + public function getId(): int|null { return $this->id; } - public function getUrl(): ?string + public function getUrl(): string|null { return $this->url; } @@ -51,7 +51,7 @@ public function setUrl( return $this; } - public function getTitle(): ?string + public function getTitle(): string|null { return $this->title; } @@ -64,7 +64,7 @@ public function setTitle( return $this; } - public function getData(): ?array + public function getData(): array|null { return $this->data; } @@ -77,20 +77,20 @@ public function setData( return $this; } - public function getSeenAt(): ?\DateTimeImmutable + public function getSeenAt(): \DateTimeImmutable|null { return $this->seenAt; } public function setSeenAt( - ?\DateTimeImmutable $seenAt + \DateTimeImmutable|null $seenAt ): self { $this->seenAt = $seenAt; return $this; } - public function getGuid(): ?string + public function getGuid(): string|null { return $this->guid; } @@ -103,13 +103,13 @@ public function setGuid( return $this; } - public function getSearch(): ?Search + public function getSearch(): Search|null { return $this->search; } public function setSearch( - ?Search $search + Search|null $search ): self { $this->search = $search; diff --git a/src/Entity/Rss/Search.php b/src/Entity/Rss/Search.php index f0d1797..c1aba1b 100644 --- a/src/Entity/Rss/Search.php +++ b/src/Entity/Rss/Search.php @@ -14,26 +14,34 @@ class Search #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private ?int $id; + private int|null $id; #[ORM\Column(type: Types::STRING, length: 255)] - private ?string $query; + private string|null $query; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: false)] - private ?Group $rssGroup; + private Group|null $rssGroup; #[ORM\Column(type: Types::STRING, length: 255, nullable: true)] - private ?string $directory; + private string|null $directory; #[ORM\Column(options: ['default' => true])] - private ?bool $active; + private bool|null $active; - public function getId(): ?int { + #[Pure] + public function __toString(): string + { + return $this->getQuery() ?? 'Unknown'; + } + + public function getId(): int|null + { return $this->id; } - public function getQuery(): ?string { + public function getQuery(): string|null + { return $this->query; } @@ -45,44 +53,42 @@ public function setQuery( return $this; } - public function getRssGroup(): ?Group { + public function getRssGroup(): Group|null + { return $this->rssGroup; } public function setRssGroup( - ?Group $rssGroup + Group|null $rssGroup ): static { $this->rssGroup = $rssGroup; return $this; } - public function getDirectory(): ?string { + public function getDirectory(): string|null + { return $this->directory; } public function setDirectory( - ?string $directory + string|null $directory ): static { $this->directory = $directory; return $this; } - public function isActive(): ?bool { + public function isActive(): bool|null + { return $this->active; } public function setActive( - ?bool $active + bool|null $active ): static { $this->active = $active; return $this; } - - #[Pure] - public function __toString(): string { - return $this->getQuery() ?? 'Unknown'; - } } diff --git a/src/Repository/MascotGroupRepository.php b/src/Repository/MascotGroupRepository.php index 52073b4..21b6175 100644 --- a/src/Repository/MascotGroupRepository.php +++ b/src/Repository/MascotGroupRepository.php @@ -20,7 +20,7 @@ public function __construct( parent::__construct($registry, MascotGroup::class); } - public function getDefault(): ?MascotGroup + public function getDefault(): MascotGroup|null { return $this->findBy(['defaultGroup' => true], ['id' => 'DESC'], 1)[0] ?? null; } diff --git a/src/Service/MascotService.php b/src/Service/MascotService.php index 08ee787..22e0599 100644 --- a/src/Service/MascotService.php +++ b/src/Service/MascotService.php @@ -12,10 +12,10 @@ class MascotService { use CacheTrait; - private int|null $mascotCounter = null; - public const TAG = 'mascot.service'; + private int|null $mascotCounter = null; + public function __construct( private readonly string $MASCOT_PATH, private readonly string $PUBLIC_DIR @@ -27,11 +27,13 @@ public function getMascot( array $paths = [] ): SplFileInfo|null { $this->mascotCounter = count($mascots = $this->getMascots($paths)); + if (null === ($mascot = $mascots[$counter] ?? null)) { return null; } $rel = mb_substr($this->MASCOT_PATH, mb_strlen($this->PUBLIC_DIR)); + return new SplFileInfo($this->MASCOT_PATH.DIRECTORY_SEPARATOR.$mascot, $rel.DIRECTORY_SEPARATOR.$mascot, $rel); } @@ -63,6 +65,7 @@ private function getMascots( array $paths = [] ): array { $key = self::TAG.'.mascots'; + foreach ($paths as $path) { $key .= '.'.strtr($path, ItemInterface::RESERVED_CHARACTERS, str_repeat('_', mb_strlen(ItemInterface::RESERVED_CHARACTERS))); } @@ -97,4 +100,4 @@ private function getMascots( } }); } -} \ No newline at end of file +} diff --git a/src/Service/QBitTorrentService.php b/src/Service/QBitTorrentService.php index 1c26e87..e0df9e2 100644 --- a/src/Service/QBitTorrentService.php +++ b/src/Service/QBitTorrentService.php @@ -14,10 +14,10 @@ */ class QBitTorrentService { - private ?string $session = null; + private string|null $session = null; public function __construct( - private ?LoggerInterface $logger, + private LoggerInterface|null $logger, private HttpClientInterface $client, private RouterInterface $router, private string $QBITTORRENT_URL, diff --git a/src/Service/SplashTitleService.php b/src/Service/SplashTitleService.php index 4be9136..1c88518 100644 --- a/src/Service/SplashTitleService.php +++ b/src/Service/SplashTitleService.php @@ -13,4 +13,4 @@ public function getTitle(): string { return self::TITLES[array_rand(self::TITLES)]; } -} \ No newline at end of file +} diff --git a/src/Traits/CacheTrait.php b/src/Traits/CacheTrait.php index f64ae2b..ea52a56 100644 --- a/src/Traits/CacheTrait.php +++ b/src/Traits/CacheTrait.php @@ -15,4 +15,4 @@ public function setCache( ): void { $this->cache = $cache; } -} \ No newline at end of file +} diff --git a/src/Traits/EntityManagerTrait.php b/src/Traits/EntityManagerTrait.php index 63363b0..676c317 100644 --- a/src/Traits/EntityManagerTrait.php +++ b/src/Traits/EntityManagerTrait.php @@ -15,4 +15,4 @@ public function setEntityManager( ): void { $this->em = $em; } -} \ No newline at end of file +} diff --git a/src/Traits/RequestStackTrait.php b/src/Traits/RequestStackTrait.php index a24acc4..9ab53eb 100644 --- a/src/Traits/RequestStackTrait.php +++ b/src/Traits/RequestStackTrait.php @@ -15,4 +15,4 @@ public function setRequestStack( ): void { $this->requestStack = $requestStack; } -} \ No newline at end of file +} diff --git a/src/Traits/SessionTrait.php b/src/Traits/SessionTrait.php index 8548a60..84b961c 100644 --- a/src/Traits/SessionTrait.php +++ b/src/Traits/SessionTrait.php @@ -17,4 +17,4 @@ public function getSession(): SessionInterface|null return null; } } -} \ No newline at end of file +}