From 9ce840c0691aaaab47a7c2c0e0145654c60903b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Toborek?= Date: Sat, 24 Aug 2024 00:54:38 +0200 Subject: [PATCH] coding style fixes --- src/Command/RebuildImagesCommand.php | 8 ++++---- src/Controller/AlbumController.php | 4 ++-- src/Controller/Helper/CounterHelper.php | 2 +- src/Controller/Helper/MatomoHelper.php | 2 +- src/Controller/RobotsController.php | 4 ++-- src/Controller/SitemapController.php | 2 +- src/DataFixtures/ImageFixtures.php | 12 ++++++------ src/DataFixtures/ItemFixtures.php | 10 +++++----- src/Entity/Image.php | 4 ++-- src/Entity/Item.php | 2 +- src/Exception/ArrayKeyNotExistsException.php | 2 +- src/Exception/DomainNotSupportedException.php | 2 +- src/Exception/FileNotExistsException.php | 2 +- src/Exception/ObjectNotInitializedException.php | 2 +- src/Form/ItemType.php | 2 +- src/Image/ImageConverter.php | 4 ++-- src/Provider/StoragePathProvider.php | 12 ++++++------ src/Repository/ItemRepository.php | 6 +++--- src/Repository/UserRepository.php | 2 +- src/Twig/RouteExtension.php | 6 +++--- src/Value/FilePath.php | 2 +- tests/Functional/Controller/AlbumControllerTest.php | 2 +- tests/Functional/Controller/FeedControllerTest.php | 2 +- tests/Functional/Controller/RobotsControllerTest.php | 2 +- .../Functional/Controller/SecurityControllerTest.php | 2 +- .../Functional/Controller/SitemapControllerTest.php | 4 ++-- 26 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/Command/RebuildImagesCommand.php b/src/Command/RebuildImagesCommand.php index 6011308..24763d1 100644 --- a/src/Command/RebuildImagesCommand.php +++ b/src/Command/RebuildImagesCommand.php @@ -44,13 +44,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** @var string $slug */ $slug = $input->getArgument('album'); - $output->writeln(sprintf('Selected album: %s', $slug)); + $output->writeln(\sprintf('Selected album: %s', $slug)); $output->writeln(''); try { $this->imageConverter->setAlbum($this->albumProvider->getBySlug($slug)); } catch (AlbumSettingsNotFoundException) { - $output->writeln(sprintf('`%s` album was not found', $slug)); + $output->writeln(\sprintf('`%s` album was not found', $slug)); return 1; } @@ -63,14 +63,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $files = $item->getImages(); foreach ($files as $file) { - $output->writeln(sprintf('Converting (%d): %s', ++$processedCounter, $file)); + $output->writeln(\sprintf('Converting (%d): %s', ++$processedCounter, $file)); /* @noinspection PhpUnhandledExceptionInspection */ $this->imageConverter->convert($file); } } $output->writeln(''); - $output->writeln(sprintf('Done, %d images processed.', $processedCounter)); + $output->writeln(\sprintf('Done, %d images processed.', $processedCounter)); return 0; } diff --git a/src/Controller/AlbumController.php b/src/Controller/AlbumController.php index 3ef7726..f00cdc8 100644 --- a/src/Controller/AlbumController.php +++ b/src/Controller/AlbumController.php @@ -35,7 +35,7 @@ public function index(int $page): Response ); /* @noinspection PhpUnhandledExceptionInspection */ - return $this->render(sprintf('album/%s/index.html.twig', $album->getSlug()), [ + return $this->render(\sprintf('album/%s/index.html.twig', $album->getSlug()), [ 'items' => $items, 'album' => $this->albumProvider->getBySlug($album->getSlug()), ]); @@ -58,7 +58,7 @@ public function item(string $itemSlug): Response $this->counterHelper->increment($album->getSlug()); /* @noinspection PhpUnhandledExceptionInspection */ - return $this->render(sprintf('album/%s/item.html.twig', $album->getSlug()), [ + return $this->render(\sprintf('album/%s/item.html.twig', $album->getSlug()), [ 'item' => $item, 'next_item' => $this->itemProvider->getNext($item), 'prev_item' => $this->itemProvider->getPrevious($item), diff --git a/src/Controller/Helper/CounterHelper.php b/src/Controller/Helper/CounterHelper.php index d796ab7..47ee6d6 100644 --- a/src/Controller/Helper/CounterHelper.php +++ b/src/Controller/Helper/CounterHelper.php @@ -19,7 +19,7 @@ public function __construct(ParameterBagInterface $parameterBag) } // this file is hosted only on my server - $wrapperFile = sprintf('%s/../../include/wrappers/counter.php', getcwd()); + $wrapperFile = \sprintf('%s/../../include/wrappers/counter.php', getcwd()); if (file_exists($wrapperFile)) { /* @noinspection PhpIncludeInspection */ diff --git a/src/Controller/Helper/MatomoHelper.php b/src/Controller/Helper/MatomoHelper.php index 918e802..d334777 100644 --- a/src/Controller/Helper/MatomoHelper.php +++ b/src/Controller/Helper/MatomoHelper.php @@ -19,7 +19,7 @@ public function __construct(ParameterBagInterface $parameterBag) } // this file is hosted only on my server - $wrapperFile = sprintf('%s/../../include/wrappers/matomo.php', getcwd()); + $wrapperFile = \sprintf('%s/../../include/wrappers/matomo.php', getcwd()); if (file_exists($wrapperFile)) { /* @noinspection PhpIncludeInspection */ diff --git a/src/Controller/RobotsController.php b/src/Controller/RobotsController.php index 7a9445d..b12aa7e 100644 --- a/src/Controller/RobotsController.php +++ b/src/Controller/RobotsController.php @@ -23,10 +23,10 @@ public function index(): Response $album = $this->domainHelper->getCurrentAlbum(); /** @var string $robots */ - $robots = file_get_contents(sprintf( + $robots = file_get_contents(\sprintf( '%s/%s', getcwd(), - $this->packages->getUrl(sprintf( + $this->packages->getUrl(\sprintf( 'assets/robots/%s/robots.txt', $album->getSlug() )) diff --git a/src/Controller/SitemapController.php b/src/Controller/SitemapController.php index c638116..698a7f4 100644 --- a/src/Controller/SitemapController.php +++ b/src/Controller/SitemapController.php @@ -37,7 +37,7 @@ public function index(): Response } /* @noinspection PhpUnhandledExceptionInspection */ - return $this->render(sprintf('album/%s/sitemap.html.twig', $album->getSlug()), [ + return $this->render(\sprintf('album/%s/sitemap.html.twig', $album->getSlug()), [ 'history' => $history, 'album' => $album, ]); diff --git a/src/DataFixtures/ImageFixtures.php b/src/DataFixtures/ImageFixtures.php index 03117c2..a531bb4 100644 --- a/src/DataFixtures/ImageFixtures.php +++ b/src/DataFixtures/ImageFixtures.php @@ -66,14 +66,14 @@ public function load(ObjectManager $manager): void $slug = $album->getSlug(); /** @var Item $itemReference */ - $itemReference = $this->getReference(sprintf(ItemFixtures::ITEM_REFERENCE, $slug, $item)); - $fileId = sha1(sprintf('%s-%d-%d', $slug, $item, $i)); + $itemReference = $this->getReference(\sprintf(ItemFixtures::ITEM_REFERENCE, $slug, $item)); + $fileId = sha1(\sprintf('%s-%d-%d', $slug, $item, $i)); $file = (new Image()) ->setItem($itemReference) ->setExtension(self::DEFAULT_EXTENSION) - ->setDescription(sprintf(self::DEFAULT_DESCRIPTION, $slug, $item, $i)) - ->setName(sprintf(self::DEFAULT_NAME, $slug, $item, $i)) + ->setDescription(\sprintf(self::DEFAULT_DESCRIPTION, $slug, $item, $i)) + ->setName(\sprintf(self::DEFAULT_NAME, $slug, $item, $i)) ->setFilename($fileId) ->setIsMain(2 === $i) ->setPosition($i); @@ -81,7 +81,7 @@ public function load(ObjectManager $manager): void $manager->persist($file); $manager->flush(); - $filename = sprintf( + $filename = \sprintf( '%s/%s.%s', $this->storagePathProvider->getRelativeDir(StoragePathProvider::PATH_RAW), $file->getFilename(), @@ -137,7 +137,7 @@ private function removeFiles(string $path): void if (!$filename->isDir() && '.gitkeep' !== $filename->getFileName() && '.htaccess' !== $filename->getFileName()) { - unlink(sprintf('%s/%s', $path, $filename->getFileName())); + unlink(\sprintf('%s/%s', $path, $filename->getFileName())); } } } diff --git a/src/DataFixtures/ItemFixtures.php b/src/DataFixtures/ItemFixtures.php index c65402f..e4762d9 100644 --- a/src/DataFixtures/ItemFixtures.php +++ b/src/DataFixtures/ItemFixtures.php @@ -33,10 +33,10 @@ public function load(ObjectManager $manager): void for ($i = 1; $i <= self::ITEM_LIMIT; ++$i) { $item = (new Item()) ->setAlbum($slug) - ->setDate((new DateTime())->modify(sprintf('+%d day', $i))) - ->setTitle(sprintf(self::DEFAULT_TITLE, $slug, $i)) - ->setDescription(sprintf(self::DEFAULT_DESCRIPTION, $slug, $i)) - ->setSlug(sprintf(self::DEFAULT_SLUG, $slug, $i)) + ->setDate((new DateTime())->modify(\sprintf('+%d day', $i))) + ->setTitle(\sprintf(self::DEFAULT_TITLE, $slug, $i)) + ->setDescription(\sprintf(self::DEFAULT_DESCRIPTION, $slug, $i)) + ->setSlug(\sprintf(self::DEFAULT_SLUG, $slug, $i)) ->setLatitude(self::DEFAULT_LATITUDE) ->setLongitude(self::DEFAULT_LONGITUDE) ->setIsActive(true); @@ -44,7 +44,7 @@ public function load(ObjectManager $manager): void $manager->persist($item); $manager->flush(); - $this->addReference(sprintf(self::ITEM_REFERENCE, $slug, $i), $item); + $this->addReference(\sprintf(self::ITEM_REFERENCE, $slug, $i), $item); } } } diff --git a/src/Entity/Image.php b/src/Entity/Image.php index 5b323f5..78216cb 100644 --- a/src/Entity/Image.php +++ b/src/Entity/Image.php @@ -111,7 +111,7 @@ public function upload(): void $this->file->move( $this->storagePathProvider->getRelativeDir(StoragePathProvider::PATH_RAW), - sprintf('%s.%s', $this->filename, $this->extension) + \sprintf('%s.%s', $this->filename, $this->extension) ); $this->file = null; @@ -152,7 +152,7 @@ public function setFile(UploadedFile $uploadedFile): self } $this->extension = $uploadedFile->getClientOriginalExtension(); - $this->filename = sha1(sprintf( + $this->filename = sha1(\sprintf( '%d-%s-%s', random_int(1, 1000), uniqid(), diff --git a/src/Entity/Item.php b/src/Entity/Item.php index 06d10db..596b81d 100644 --- a/src/Entity/Item.php +++ b/src/Entity/Item.php @@ -221,6 +221,6 @@ public function getIsActive(): bool public function getGuid(): string { - return sprintf('%s_%s', $this->getAlbum() ?? '', md5((string) $this->getId())); + return \sprintf('%s_%s', $this->getAlbum() ?? '', md5((string) $this->getId())); } } diff --git a/src/Exception/ArrayKeyNotExistsException.php b/src/Exception/ArrayKeyNotExistsException.php index ebb85ef..de92bb4 100644 --- a/src/Exception/ArrayKeyNotExistsException.php +++ b/src/Exception/ArrayKeyNotExistsException.php @@ -9,6 +9,6 @@ class ArrayKeyNotExistsException extends Exception { public function __construct(string $key, int $code = 0, Throwable $previous = null) { - parent::__construct(sprintf('Array key `%s` not exists', $key), $code, $previous); + parent::__construct(\sprintf('Array key `%s` not exists', $key), $code, $previous); } } diff --git a/src/Exception/DomainNotSupportedException.php b/src/Exception/DomainNotSupportedException.php index 0d61964..ca58298 100644 --- a/src/Exception/DomainNotSupportedException.php +++ b/src/Exception/DomainNotSupportedException.php @@ -9,6 +9,6 @@ class DomainNotSupportedException extends Exception { public function __construct(string $domain, int $code = 0, Throwable $previous = null) { - parent::__construct(sprintf('Domain `%s` is not supported', $domain), $code, $previous); + parent::__construct(\sprintf('Domain `%s` is not supported', $domain), $code, $previous); } } diff --git a/src/Exception/FileNotExistsException.php b/src/Exception/FileNotExistsException.php index 32fd981..1262f5b 100644 --- a/src/Exception/FileNotExistsException.php +++ b/src/Exception/FileNotExistsException.php @@ -9,6 +9,6 @@ class FileNotExistsException extends Exception { public function __construct(string $key, int $code = 0, Throwable $previous = null) { - parent::__construct(sprintf('File `%s` not exists', $key), $code, $previous); + parent::__construct(\sprintf('File `%s` not exists', $key), $code, $previous); } } diff --git a/src/Exception/ObjectNotInitializedException.php b/src/Exception/ObjectNotInitializedException.php index 78a4590..1345fe3 100644 --- a/src/Exception/ObjectNotInitializedException.php +++ b/src/Exception/ObjectNotInitializedException.php @@ -9,6 +9,6 @@ class ObjectNotInitializedException extends Exception { public function __construct(string $key, int $code = 0, Throwable $previous = null) { - parent::__construct(sprintf('Class object `%s` not initialized', $key), $code, $previous); + parent::__construct(\sprintf('Class object `%s` not initialized', $key), $code, $previous); } } diff --git a/src/Form/ItemType.php b/src/Form/ItemType.php index d734b49..db85f10 100644 --- a/src/Form/ItemType.php +++ b/src/Form/ItemType.php @@ -29,7 +29,7 @@ public function __construct(AlbumProvider $albumProvider, AdminSettingsProvider $albums = $albumProvider->getAll(); foreach ($albums as $album) { - $this->albums[sprintf('%s (%s)', $album->getTitle(), $album->getSlug())] = $album->getSlug(); + $this->albums[\sprintf('%s (%s)', $album->getTitle(), $album->getSlug())] = $album->getSlug(); } $this->defaultAlbum = $adminSettingsProvider->getAlbum(); diff --git a/src/Image/ImageConverter.php b/src/Image/ImageConverter.php index bc9be3d..35818a7 100644 --- a/src/Image/ImageConverter.php +++ b/src/Image/ImageConverter.php @@ -88,10 +88,10 @@ private function addWatermark( ImageInterface $image ): ImageInterface { if (!isset($this->watermark[$this->album->getSlug()])) { - $watermarkFile = sprintf( + $watermarkFile = \sprintf( '%s/public_html%s', $this->parameterBag->get('kernel.project_dir'), - $this->packages->getUrl(sprintf( + $this->packages->getUrl(\sprintf( 'assets/images/watermark/%s', $this->album->getWatermark()->getFile() )) diff --git a/src/Provider/StoragePathProvider.php b/src/Provider/StoragePathProvider.php index 5318304..62c803f 100644 --- a/src/Provider/StoragePathProvider.php +++ b/src/Provider/StoragePathProvider.php @@ -31,26 +31,26 @@ public function __construct(ParameterBagInterface $parameterBag) public function getPublicDir(int $path): string { if (self::PATH_IMAGES === $path) { - return sprintf('/%s', $this->storageImagesPath); + return \sprintf('/%s', $this->storageImagesPath); } if (self::PATH_THUMBS === $path) { - return sprintf('/%s', $this->storageThumbsPath); + return \sprintf('/%s', $this->storageThumbsPath); } - return sprintf('/%s', $this->storageRawPath); + return \sprintf('/%s', $this->storageRawPath); } public function getRelativeDir(int $path): string { if (self::PATH_IMAGES === $path) { - return sprintf(self::RELATIVE_PATH_PATTERN, __DIR__, $this->storageImagesPath); + return \sprintf(self::RELATIVE_PATH_PATTERN, __DIR__, $this->storageImagesPath); } if (self::PATH_THUMBS === $path) { - return sprintf(self::RELATIVE_PATH_PATTERN, __DIR__, $this->storageThumbsPath); + return \sprintf(self::RELATIVE_PATH_PATTERN, __DIR__, $this->storageThumbsPath); } - return sprintf(self::RELATIVE_PATH_PATTERN, __DIR__, $this->storageRawPath); + return \sprintf(self::RELATIVE_PATH_PATTERN, __DIR__, $this->storageRawPath); } } diff --git a/src/Repository/ItemRepository.php b/src/Repository/ItemRepository.php index 2bf37ec..01e638b 100644 --- a/src/Repository/ItemRepository.php +++ b/src/Repository/ItemRepository.php @@ -26,7 +26,7 @@ public function getAllPaginated( ): PaginationInterface { $query = $this ->createQueryBuilder('i') - ->orderBy(sprintf('i.%s', $itemsSort), $itemsSortDirection); + ->orderBy(\sprintf('i.%s', $itemsSort), $itemsSortDirection); if ($activeOnly) { $query @@ -83,7 +83,7 @@ public function getById(int $itemId): Item if (!\is_object($item)) { /* @noinspection PhpUnhandledExceptionInspection */ - throw new RecordNotFoundException(sprintf('No item found for id [%d]', $itemId)); + throw new RecordNotFoundException(\sprintf('No item found for id [%d]', $itemId)); } return $item; @@ -103,7 +103,7 @@ public function getBySlug(string $albumSlug, string $itemSlug): Item if (!$item) { /* @noinspection PhpUnhandledExceptionInspection */ - throw new RecordNotFoundException(sprintf('No item found for slug [%s:%s]', $albumSlug, $itemSlug)); + throw new RecordNotFoundException(\sprintf('No item found for slug [%s:%s]', $albumSlug, $itemSlug)); } return $item; diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 9299f43..f849ee7 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -22,7 +22,7 @@ public function __construct(ManagerRegistry $registry) public function upgradePassword(UserInterface $user, string $newHashedPassword): void { if (!$user instanceof User) { - throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class)); + throw new UnsupportedUserException(\sprintf('Instances of "%s" are not supported.', $user::class)); } $user->setPassword($newHashedPassword); diff --git a/src/Twig/RouteExtension.php b/src/Twig/RouteExtension.php index c2db786..15c7ed1 100644 --- a/src/Twig/RouteExtension.php +++ b/src/Twig/RouteExtension.php @@ -41,7 +41,7 @@ public function getRouteWithPagination(?string $itemSlug): string $route = $this->generateRoute($itemSlug); if (isset($this->attributes['page']) && (int) $this->attributes['page'] > 1) { - return sprintf('%s/%d', $route, $this->attributes['page']); + return \sprintf('%s/%d', $route, $this->attributes['page']); } return $route; @@ -58,11 +58,11 @@ private function generateRoute(?string $itemSlug): string $itemSlug = $this->attributes['itemSlug'] ?? null; } - return sprintf( + return \sprintf( 'http%s://%s%s', !isset($_SERVER['HTTPS']) || 'on' !== $_SERVER['HTTPS'] ? '' : 's', $_SERVER['SERVER_NAME'], - empty($itemSlug) ? '' : sprintf('/%s', $itemSlug) + empty($itemSlug) ? '' : \sprintf('/%s', $itemSlug) ); } } diff --git a/src/Value/FilePath.php b/src/Value/FilePath.php index 23e71f3..4bd1b02 100644 --- a/src/Value/FilePath.php +++ b/src/Value/FilePath.php @@ -48,6 +48,6 @@ public function getRawRelativePath(): string private function createPath(string $path, string $extension = 'jpg'): string { - return sprintf('%s/%s.%s', $path, $this->filename, $extension); + return \sprintf('%s/%s.%s', $path, $this->filename, $extension); } } diff --git a/tests/Functional/Controller/AlbumControllerTest.php b/tests/Functional/Controller/AlbumControllerTest.php index cb9dd41..e801572 100644 --- a/tests/Functional/Controller/AlbumControllerTest.php +++ b/tests/Functional/Controller/AlbumControllerTest.php @@ -17,7 +17,7 @@ public function testIndex(): void { $client = static::createClient(); - $client->request('GET', sprintf('https://%s', self::HOST)); + $client->request('GET', \sprintf('https://%s', self::HOST)); $this->assertSame(200, $client->getResponse()->getStatusCode()); } diff --git a/tests/Functional/Controller/FeedControllerTest.php b/tests/Functional/Controller/FeedControllerTest.php index fad6805..81cddb5 100644 --- a/tests/Functional/Controller/FeedControllerTest.php +++ b/tests/Functional/Controller/FeedControllerTest.php @@ -17,7 +17,7 @@ public function testIndex(): void { $client = static::createClient(); - $client->request('GET', sprintf('https://%s/feed', self::HOST)); + $client->request('GET', \sprintf('https://%s/feed', self::HOST)); $this->assertSame(200, $client->getResponse()->getStatusCode()); } diff --git a/tests/Functional/Controller/RobotsControllerTest.php b/tests/Functional/Controller/RobotsControllerTest.php index d2aa90d..14ec85d 100644 --- a/tests/Functional/Controller/RobotsControllerTest.php +++ b/tests/Functional/Controller/RobotsControllerTest.php @@ -17,7 +17,7 @@ public function testIndex(): void { $client = static::createClient(); - $client->request('GET', sprintf('https://%s/sitemap', self::HOST)); + $client->request('GET', \sprintf('https://%s/sitemap', self::HOST)); $this->assertSame(200, $client->getResponse()->getStatusCode()); } diff --git a/tests/Functional/Controller/SecurityControllerTest.php b/tests/Functional/Controller/SecurityControllerTest.php index d471ae3..72adddc 100644 --- a/tests/Functional/Controller/SecurityControllerTest.php +++ b/tests/Functional/Controller/SecurityControllerTest.php @@ -17,7 +17,7 @@ public function testList(): void { $client = static::createClient(); - $client->request('GET', sprintf('https://%s/zaplecze/login', self::HOST)); + $client->request('GET', \sprintf('https://%s/zaplecze/login', self::HOST)); $this->assertSame(200, $client->getResponse()->getStatusCode()); } diff --git a/tests/Functional/Controller/SitemapControllerTest.php b/tests/Functional/Controller/SitemapControllerTest.php index c376021..8c2a0bf 100644 --- a/tests/Functional/Controller/SitemapControllerTest.php +++ b/tests/Functional/Controller/SitemapControllerTest.php @@ -17,7 +17,7 @@ public function testIndex(): void { $client = static::createClient(); - $client->request('GET', sprintf('https://%s/sitemap', self::HOST)); + $client->request('GET', \sprintf('https://%s/sitemap', self::HOST)); $this->assertSame(200, $client->getResponse()->getStatusCode()); } @@ -26,7 +26,7 @@ public function testIndexXml(): void { $client = static::createClient(); - $client->request('GET', sprintf('https://%s/sitemap.xml', self::HOST)); + $client->request('GET', \sprintf('https://%s/sitemap.xml', self::HOST)); $this->assertSame(200, $client->getResponse()->getStatusCode()); }