Skip to content

Commit

Permalink
feat(php82): Enforce PHP 8.2 with rector
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusa87 committed Dec 7, 2024
1 parent c3d7bfc commit 30bef65
Show file tree
Hide file tree
Showing 53 changed files with 101 additions and 160 deletions.
4 changes: 1 addition & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
return fn(array $context) => new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Symfony\Set\SymfonySetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

Expand All @@ -21,6 +22,7 @@
codeQuality: true
)
->withSets([
LevelSetList::UP_TO_PHP_82,
SymfonySetList::SYMFONY_64,
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
Expand Down
10 changes: 5 additions & 5 deletions src/Command/BooksCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
class BooksCheckCommand extends Command
{
public function __construct(
private BookFileSystemManagerInterface $fileSystemManager,
private BookRepository $bookRepository,
private RouterInterface $router,
private BookProgressionService $bookProgressionService,
private readonly BookFileSystemManagerInterface $fileSystemManager,
private readonly BookRepository $bookRepository,
private readonly RouterInterface $router,
private readonly BookProgressionService $bookProgressionService,
) {
parent::__construct();
}
Expand Down Expand Up @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

try {
$file = $this->fileSystemManager->getBookFile($book);
} catch (\Exception $e) {
} catch (\Exception) {
$io->writeln('');
$io->writeln('Book not found: '.$book->getBookPath().'/'.$book->getBookFilename());
$io->writeln('Book not found: '.$this->router->generate('app_book', ['book' => $book->getId(), 'slug' => $book->getSlug()]));
Expand Down
2 changes: 1 addition & 1 deletion src/Command/BooksExtractCoverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)]
class BooksExtractCoverCommand extends Command
{
public function __construct(private BookFileSystemManagerInterface $fileSystemManager, private BookRepository $bookRepository, private EntityManagerInterface $entityManager)
public function __construct(private readonly BookFileSystemManagerInterface $fileSystemManager, private readonly BookRepository $bookRepository, private readonly EntityManagerInterface $entityManager)
{
parent::__construct();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Command/BooksScanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
class BooksScanCommand extends Command
{
public function __construct(
private EntityManagerInterface $entityManager,
private BookManager $bookManager,
private BookFileSystemManagerInterface $fileSystemManager,
private readonly EntityManagerInterface $entityManager,
private readonly BookManager $bookManager,
private readonly BookFileSystemManagerInterface $fileSystemManager,
) {
parent::__construct();
}
Expand Down
7 changes: 1 addition & 6 deletions src/Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@
)]
class CreateUserCommand extends Command
{
private UserPasswordHasherInterface $passwordHasher;
private UserRepository $userRepository;

public function __construct(UserPasswordHasherInterface $passwordHasher, UserRepository $userRepository)
public function __construct(private readonly UserPasswordHasherInterface $passwordHasher, private readonly UserRepository $userRepository)
{
parent::__construct();
$this->passwordHasher = $passwordHasher;
$this->userRepository = $userRepository;
}

protected function configure(): void
Expand Down
6 changes: 2 additions & 4 deletions src/Command/TranslationRetrieveFromProfilerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)]
class TranslationRetrieveFromProfilerCommand extends Command
{
public function __construct(private ?Profiler $profiler, private KernelInterface $kernel)
public function __construct(private readonly ?Profiler $profiler, private readonly KernelInterface $kernel)
{
parent::__construct();
}
Expand Down Expand Up @@ -60,9 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}

$filtered_values = array_filter($raw_values, function ($value) {
return $value['state'] !== 0;
});
$filtered_values = array_filter($raw_values, fn ($value) => $value['state'] !== 0);

$grouped = self::groupBy($filtered_values, 'domain');

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function index(Book $book, string $slug, BookRepository $bookRepository,
if ($index === 0.0 || floor($index ?? 0.0) !== $index) {
$index = '?';
}
$serie[$index] = $serie[$index] ?? [];
$serie[$index] ??= [];
$serie[$index][] = $bookInSerie;
}
$keys = array_filter(array_keys($serie), static fn ($key) => is_numeric($key));
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public function allbooks(Request $request, BookRepository $bookRepository, Filte
#[Route('/timeline/{type?}/{year?}', name: 'app_timeline', requirements: ['page' => '\d+'])]
public function timeline(?string $type, ?string $year, BookRepository $bookRepository, FilteredBookUrlGenerator $filteredBookUrlGenerator, PaginatorInterface $paginator, int $page = 1): Response
{
$redirectType = $type === null ? 'all' : $type;
$redirectYear = $year === null ? date('Y') : $year;
$redirectType = $type ?? 'all';
$redirectYear = $year ?? date('Y');
if ($redirectYear !== $year || $redirectType !== $type) {
return $this->redirectToRoute('app_timeline', ['type' => $redirectType, 'year' => $redirectYear]);
}
Expand Down
10 changes: 3 additions & 7 deletions src/Controller/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#[Route('/groups')]
class GroupController extends AbstractController
{
public function __construct(private BookRepository $bookRepository)
public function __construct(private readonly BookRepository $bookRepository)
{
}

Expand Down Expand Up @@ -48,13 +48,9 @@ public function groups(Request $request, string $type, string $letter = 'a'): Re
}

if ($search !== '') {
$group = array_filter($group, static function ($item) use ($search) {
return str_contains(strtolower($item['item']), strtolower($search));
});
$group = array_filter($group, static fn ($item) => str_contains(strtolower((string) $item['item']), strtolower($search)));
} else {
$group = array_filter($group, static function ($item) use ($letter) {
return str_starts_with(strtolower($item['item']), $letter);
});
$group = array_filter($group, static fn ($item) => str_starts_with(strtolower((string) $item['item']), $letter));
}

return $this->render('group/index.html.twig', [
Expand Down
4 changes: 1 addition & 3 deletions src/Controller/RunCommandManuallyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public function index(): Response
#[Route('/admin/commands/run/{name}', name: 'run_command')]
public function run(string $name): Response
{
$commands = array_filter($this->getCommands(), function (array $command) use ($name) {
return $command['action'] == $name;
});
$commands = array_filter($this->getCommands(), fn (array $command) => $command['action'] == $name);
if (count($commands) < 1) {
throw $this->createNotFoundException(sprintf('Command "%s" does not exist.', $name));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#[Route('/user')]
class UserController extends AbstractController
{
public function __construct(private UserPasswordHasherInterface $passwordHasher)
public function __construct(private readonly UserPasswordHasherInterface $passwordHasher)
{
}

Expand Down
6 changes: 2 additions & 4 deletions src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Book

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Gedmo\Timestampable(on: 'update')]
private ?\DateTimeInterface $updated;
private ?\DateTimeInterface $updated = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $imagePath = null;
Expand Down Expand Up @@ -320,9 +320,7 @@ public function setPublishDate(?\DateTimeInterface $publishDate): static
*/
public function getAuthors(): array
{
return array_map(static function ($item) {
return ucwords(strtolower($item), self::UCWORDS_SEPARATORS);
}, $this->authors);
return array_map(static fn ($item) => ucwords(strtolower((string) $item), self::UCWORDS_SEPARATORS), $this->authors);

Check failure on line 323 in src/Entity/Book.php

View workflow job for this annotation

GitHub Actions / symfony-tests (0.23.1)

Casting to string something that's already string.
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/BookInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BookInteraction

#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true, options: ['default' => '2024-01-12 00:00:00'])]
#[Gedmo\Timestampable(on: 'update')]
private ?\DateTimeImmutable $updated;
private ?\DateTimeImmutable $updated = null;

#[ORM\Column]
private bool $hidden = false;
Expand Down
18 changes: 6 additions & 12 deletions src/Entity/BookmarkUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ class BookmarkUser
#[ORM\Column(length: 255, nullable: true)]
private ?string $locationSource = null;

#[ORM\ManyToOne(inversedBy: 'bookmarkUsers')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user;

#[ORM\ManyToOne(inversedBy: 'bookmarkUsers')]
#[ORM\JoinColumn(nullable: false)]
private ?Book $book;

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Gedmo\Timestampable(on: 'update')]
private ?\DateTimeInterface $updated;
private ?\DateTimeInterface $updated = null;

public function __construct(?Book $book, ?User $user)
public function __construct(#[ORM\ManyToOne(inversedBy: 'bookmarkUsers')]
#[ORM\JoinColumn(nullable: false)]
private ?Book $book, #[ORM\ManyToOne(inversedBy: 'bookmarkUsers')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user)
{
$this->book = $book;
$this->user = $user;
}

public function getId(): ?int
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/KoboDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class KoboDevice

#[Assert\NotBlank(allowNull: false)]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name;
private ?string $name = null;

#[ORM\ManyToOne(inversedBy: 'kobos')]
#[ORM\JoinColumn(nullable: false)]
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/LanguageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

final class LanguageListener
{
public function __construct(private RequestStack $requestStack, private Security $security)
public function __construct(private readonly RequestStack $requestStack, private readonly Security $security)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/LoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

final class LoginListener
{
public function __construct(private EntityManagerInterface $entityManager, private RequestStack $requestStack, private Security $security)
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly RequestStack $requestStack, private readonly Security $security)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/EventSubscriber/KoboLogRequestSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function onKernelResponse(ResponseEvent $event): void

try {
$content = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
} catch (\JsonException) {
$content = $event->getResponse()->getContent();
}

Expand All @@ -53,7 +53,7 @@ public function onKernelController(ControllerEvent $event): void

try {
$content = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
} catch (\JsonException) {
$content = $event->getRequest()->getContent();
}

Expand Down
6 changes: 2 additions & 4 deletions src/Form/BookFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BookFilterType extends AbstractType
{
public const AUTOCOMPLETE_DELIMITER = '🪓';

public function __construct(private RouterInterface $router)
public function __construct(private readonly RouterInterface $router)
{
}

Expand Down Expand Up @@ -348,9 +348,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$direction = 'ASC';
if ($orderByValue === null) {
$params = $qb->getParameters()->toArray();
$params = array_filter($params, static function ($param) {
return $param->getName() === 'serie0';
});
$params = array_filter($params, static fn ($param) => $param->getName() === 'serie0');
if ($params !== []) {
$orderByValue = 'serieIndex';
} else {
Expand Down
8 changes: 3 additions & 5 deletions src/Form/KoboType.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder->add('shelves', EntityType::class, [
'label' => 'Sync with Shelves',
'class' => Shelf::class,
'query_builder' => function (EntityRepository $er): QueryBuilder {
return $er->createQueryBuilder('u')
->setParameter('user', $this->security->getUser())
->andWhere('u.user = :user');
},
'query_builder' => fn (EntityRepository $er): QueryBuilder => $er->createQueryBuilder('u')
->setParameter('user', $this->security->getUser())
->andWhere('u.user = :user'),
'choice_label' => 'name',
'multiple' => true,
'expanded' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/Form/ProfileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class ProfileType extends AbstractType
{
public function __construct(private RouterInterface $router)
public function __construct(private readonly RouterInterface $router)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kobo/BookDownloadInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class BookDownloadInfo
{
public function __construct(private int $size, private string $url)
public function __construct(private readonly int $size, private readonly string $url)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kobo/ImageProcessor/CoverTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function streamFile(string $coverPath, int $maxWidth, int $maxHeight, str

return;
}
list($originalWidth, $originalHeight) = $sizes;
[$originalWidth, $originalHeight] = $sizes;

$aspectRatio = $originalWidth / max(1, $originalHeight);

Expand Down
4 changes: 2 additions & 2 deletions src/Kobo/Kepubify/KebpubifyCachedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class KebpubifyCachedData implements \JsonSerializable
{
private string $content;
private int $size;
private readonly string $content;
private readonly int $size;

public function __construct(string $filename)
{
Expand Down
12 changes: 5 additions & 7 deletions src/Kobo/Proxy/KoboProxyLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ public function __construct(
*/
public function __invoke(callable $handler): \Closure
{
return function ($request, array $options) use ($handler) {
return $handler($request, $options)->then(
$this->onSuccess($request),
$this->onFailure($request)
);
};
return fn ($request, array $options) => $handler($request, $options)->then(
$this->onSuccess($request),
$this->onFailure($request)
);
}

/**
Expand Down Expand Up @@ -59,7 +57,7 @@ private function log(RequestInterface $request, ?ResponseInterface $response = n
{
try {
$requestContent = json_decode($request->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
} catch (\JsonException) {
$requestContent = $request->getBody()->getContents();
}
$responseContent = $response?->getBody()->getContents();
Expand Down
6 changes: 2 additions & 4 deletions src/Kobo/Proxy/KoboStoreProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function transformUrl(ServerRequestInterface $psrRequest, string $hostna
{
$host = parse_url($hostnameOrUrl, PHP_URL_HOST);
$host = $host === false ? $hostnameOrUrl : $host;
$host = $host ?? $hostnameOrUrl;
$host ??= $hostnameOrUrl;
$path = $this->tokenExtractor->getOriginalPath($psrRequest, $psrRequest->getUri()->getPath());

return $psrRequest->getUri()->withHost($host)->withPath($path);
Expand Down Expand Up @@ -149,9 +149,7 @@ public function proxyAsync(Request $request, bool $streamAllowed): PromiseInterf
'http_errors' => false,
'connect_timeout' => 5,
'stream' => $streamAllowed,
])->then(function (ResponseInterface $response) {
return $this->cleanupPsrResponse($response);
});
])->then(fn (ResponseInterface $response) => $this->cleanupPsrResponse($response));
}

private function convertRequest(Request $request, string $hostname): RequestInterface
Expand Down
Loading

0 comments on commit 30bef65

Please sign in to comment.