From f2a15d82a2ec5901a61ca38a87f983395605c156 Mon Sep 17 00:00:00 2001 From: roadiz-ci Date: Fri, 6 Dec 2024 08:57:52 +0000 Subject: [PATCH] Merge branch release/v2.4.0 --- .github/workflows/run-test.yml | 4 +- Makefile | 3 - composer.json | 32 +++-- phpcs.xml.dist | 13 -- src/Controller/Admin/FontsController.php | 68 ++-------- src/Controller/FontFaceController.php | 33 ++--- .../DoctrineMigrationCompilerPass.php | 20 +-- .../RoadizFontExtension.php | 5 +- .../FontLifeCycleSubscriber.php | 75 ++++------- src/Entity/Font.php | 116 ++++-------------- src/Event/Font/FontEvent.php | 14 +-- src/EventSubscriber/UpdateFontSubscriber.php | 10 +- src/Form/FontType.php | 15 +-- src/Form/FontVariantsType.php | 12 +- src/Repository/FontRepository.php | 2 +- 15 files changed, 110 insertions(+), 312 deletions(-) delete mode 100644 Makefile delete mode 100644 phpcs.xml.dist diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 189e3a5..3b9abf4 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['8.1', '8.2', '8.3'] + php-version: ['8.2', '8.3'] steps: - uses: shivammathur/setup-php@v2 with: @@ -35,7 +35,5 @@ jobs: ${{ runner.os }}-php-${{ matrix.php-version }}- - name: Install Dependencies run: composer install --no-scripts --no-ansi --no-interaction --no-progress - - name: Run PHP Code Sniffer - run: vendor/bin/phpcs -p ./src - name: Run PHPStan run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon diff --git a/Makefile b/Makefile deleted file mode 100644 index 16ef814..0000000 --- a/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -test: - php -d "memory_limit=-1" vendor/bin/phpcbf --report=full --report-file=./report.txt -p ./src - php -d "memory_limit=-1" vendor/bin/phpstan analyse -c phpstan.neon diff --git a/composer.json b/composer.json index 8aba042..f151878 100644 --- a/composer.json +++ b/composer.json @@ -20,16 +20,15 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=8.1", - "doctrine/annotations": "^1.0", + "php": ">=8.2", + "doctrine/annotations": "^2.0", "doctrine/doctrine-bundle": "^2.8.1", "doctrine/doctrine-migrations-bundle": "^3.1", - "doctrine/orm": "~2.19.0", + "doctrine/orm": "~2.20.0", "jms/serializer": "^3.9.0", "league/flysystem": "^3.0", - "roadiz/models": "2.3.*", - "roadiz/rozier": "2.3.*", - "sensio/framework-extra-bundle": "^6.1", + "roadiz/models": "2.4.*", + "roadiz/rozier": "2.4.*", "symfony/asset": "6.4.*", "symfony/cache": "6.4.*", "symfony/dotenv": "6.4.*", @@ -44,25 +43,24 @@ "symfony/twig-bundle": "6.4.*", "symfony/validator": "6.4.*", "symfony/yaml": "6.4.*", - "twig/extra-bundle": "^3.0", + "twig/extra-bundle": "^3.16", "twig/intl-extra": "*", "twig/string-extra": "*", - "twig/twig": "^3.1" + "twig/twig": "^3.16" }, "require-dev": { "php-coveralls/php-coveralls": "^2.4", "phpstan/phpstan": "^1.5.3", "phpstan/phpstan-doctrine": "^1.3", "phpunit/phpunit": "^9.5", - "squizlabs/php_codesniffer": "^3.5", + "roadiz/compat-bundle": "2.4.*", + "roadiz/core-bundle": "2.4.*", + "roadiz/documents": "2.4.*", + "roadiz/entity-generator": "2.4.*", + "roadiz/rozier-bundle": "2.4.*", "symfony/browser-kit": "6.4.*", "symfony/phpunit-bridge": "^7.0", - "symfony/stopwatch": "6.4.*", - "roadiz/core-bundle": "2.3.*", - "roadiz/compat-bundle": "2.3.*", - "roadiz/rozier-bundle": "2.3.*", - "roadiz/documents": "2.3.*", - "roadiz/entity-generator": "2.3.*" + "symfony/stopwatch": "6.4.*" }, "config": { "optimize-autoloader": true, @@ -89,8 +87,8 @@ }, "extra": { "branch-alias": { - "dev-main": "2.3.x-dev", - "dev-develop": "2.4.x-dev" + "dev-main": "2.4.x-dev", + "dev-develop": "2.5.x-dev" } } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index 19bff0c..0000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - src/ - diff --git a/src/Controller/Admin/FontsController.php b/src/Controller/Admin/FontsController.php index 894ea81..e66a3cd 100644 --- a/src/Controller/Admin/FontsController.php +++ b/src/Controller/Admin/FontsController.php @@ -22,126 +22,84 @@ class FontsController extends AbstractAdminController { - private FilesystemOperator $fontStorage; - public function __construct( - FilesystemOperator $fontStorage, + private readonly FilesystemOperator $fontStorage, SerializerInterface $serializer, - UrlGeneratorInterface $urlGenerator + UrlGeneratorInterface $urlGenerator, ) { parent::__construct($serializer, $urlGenerator); - $this->fontStorage = $fontStorage; } - /** - * @inheritDoc - */ protected function supports(PersistableInterface $item): bool { return $item instanceof Font; } - /** - * @inheritDoc - */ protected function getNamespace(): string { return 'font'; } - /** - * @inheritDoc - */ protected function createEmptyItem(Request $request): PersistableInterface { return new Font(); } - /** - * @inheritDoc - */ protected function getTemplateFolder(): string { return '@RoadizFont/admin'; } - /** - * @inheritDoc - */ protected function getRequiredRole(): string { return 'ROLE_ACCESS_FONTS'; } - /** - * @inheritDoc - */ protected function getEntityClass(): string { return Font::class; } - /** - * @inheritDoc - */ protected function getFormType(): string { return FontType::class; } - /** - * @inheritDoc - */ protected function getDefaultOrder(Request $request): array { return ['name' => 'ASC']; } - /** - * @inheritDoc - */ protected function getDefaultRouteName(): string { return 'fontsHomePage'; } - /** - * @inheritDoc - */ protected function getEditRouteName(): string { return 'fontsEditPage'; } - /** - * @inheritDoc - */ protected function createUpdateEvent(PersistableInterface $item): ?Event { if ($item instanceof Font) { return new PreUpdatedFontEvent($item); } + return null; } - /** - * @inheritDoc - */ protected function getEntityName(PersistableInterface $item): string { if ($item instanceof Font) { return $item->getName(); } - throw new \InvalidArgumentException('Item should be instance of ' . $this->getEntityClass()); + throw new \InvalidArgumentException('Item should be instance of '.$this->getEntityClass()); } /** * Return a ZipArchive of requested font. * - * @param Request $request - * @param int $id - * - * @return BinaryFileResponse * @throws FilesystemException */ public function downloadAction(Request $request, int $id): BinaryFileResponse @@ -151,37 +109,37 @@ public function downloadAction(Request $request, int $id): BinaryFileResponse /** @var Font|null $font */ $font = $this->em()->find(Font::class, $id); - if ($font !== null) { + if (null !== $font) { // Prepare File - $file = tempnam(sys_get_temp_dir(), "font_" . $font->getId()); + $file = tempnam(sys_get_temp_dir(), 'font_'.$font->getId()); if (false === $file) { throw new \RuntimeException('Cannot create temporary file.'); } $zip = new \ZipArchive(); $zip->open($file, \ZipArchive::CREATE); - if ("" != $font->getEOTFilename()) { + if ('' != $font->getEOTFilename()) { $zip->addFromString($font->getEOTFilename(), $this->fontStorage->read($font->getEOTRelativeUrl())); } - if ("" != $font->getSVGFilename()) { + if ('' != $font->getSVGFilename()) { $zip->addFromString($font->getSVGFilename(), $this->fontStorage->read($font->getSVGRelativeUrl())); } - if ("" != $font->getWOFFFilename()) { + if ('' != $font->getWOFFFilename()) { $zip->addFromString($font->getWOFFFilename(), $this->fontStorage->read($font->getWOFFRelativeUrl())); } - if ("" != $font->getWOFF2Filename()) { + if ('' != $font->getWOFF2Filename()) { $zip->addFromString($font->getWOFF2Filename(), $this->fontStorage->read($font->getWOFF2RelativeUrl())); } - if ("" != $font->getOTFFilename()) { + if ('' != $font->getOTFFilename()) { $zip->addFromString($font->getOTFFilename(), $this->fontStorage->read($font->getOTFRelativeUrl())); } // Close and send to users $zip->close(); - $filename = StringHandler::slugify($font->getName() . ' ' . $font->getReadableVariant()) . '.zip'; + $filename = StringHandler::slugify($font->getName().' '.$font->getReadableVariant()).'.zip'; return (new BinaryFileResponse($file, Response::HTTP_OK, [ 'content-type' => 'application/zip', - 'content-disposition' => 'attachment; filename=' . $filename, + 'content-disposition' => 'attachment; filename='.$filename, ], false))->deleteFileAfterSend(true); } diff --git a/src/Controller/FontFaceController.php b/src/Controller/FontFaceController.php index 54805b5..c178a0f 100644 --- a/src/Controller/FontFaceController.php +++ b/src/Controller/FontFaceController.php @@ -13,12 +13,12 @@ use Symfony\Component\HttpFoundation\Response; use Twig\Environment; -final class FontFaceController +final readonly class FontFaceController { public function __construct( - private readonly FilesystemOperator $fontStorage, - private readonly ManagerRegistry $managerRegistry, - private readonly Environment $templating, + private FilesystemOperator $fontStorage, + private ManagerRegistry $managerRegistry, + private Environment $templating, ) { } @@ -28,27 +28,27 @@ private function getFontData(Font $font, string $extension): ?array return match ($extension) { 'eot' => [ $this->fontStorage->read($font->getEOTRelativeUrl()), - Font::MIME_EOT + Font::MIME_EOT, ], 'woff' => [ $this->fontStorage->read($font->getWOFFRelativeUrl()), - Font::MIME_WOFF + Font::MIME_WOFF, ], 'woff2' => [ $this->fontStorage->read($font->getWOFF2RelativeUrl()), - Font::MIME_WOFF2 + Font::MIME_WOFF2, ], 'svg' => [ $this->fontStorage->read($font->getSVGRelativeUrl()), - Font::MIME_SVG + Font::MIME_SVG, ], 'otf' => [ $this->fontStorage->read($font->getOTFRelativeUrl()), - Font::MIME_OTF + Font::MIME_OTF, ], 'ttf' => [ $this->fontStorage->read($font->getOTFRelativeUrl()), - Font::MIME_TTF + Font::MIME_TTF, ], default => null, }; @@ -60,12 +60,6 @@ private function getFontData(Font $font, string $extension): ?array /** * Request a single protected font file from Roadiz. * - * @param Request $request - * @param string $filename - * @param int $variant - * @param string $extension - * - * @return Response * @throws \Exception */ public function fontFileAction(Request $request, string $filename, int $variant, string $extension): Response @@ -103,7 +97,7 @@ public function fontFileAction(Request $request, string $filename, int $variant, return $response; } } - $msg = "Font doesn't exist " . $filename; + $msg = "Font doesn't exist ".$filename; return new Response( $msg, @@ -115,9 +109,6 @@ public function fontFileAction(Request $request, string $filename, int $variant, /** * Request the font-face CSS file listing available fonts. * - * @param Request $request - * - * @return Response * @throws \Exception */ public function fontFacesAction(Request $request): Response @@ -151,7 +142,7 @@ public function fontFacesAction(Request $request): Response ]; /** @var Font $font */ foreach ($fonts as $font) { - $variantHash = $font->getHash() . $font->getVariant(); + $variantHash = $font->getHash().$font->getVariant(); $assignation['fonts'][] = [ 'font' => $font, 'variantHash' => $variantHash, diff --git a/src/DependencyInjection/Compiler/DoctrineMigrationCompilerPass.php b/src/DependencyInjection/Compiler/DoctrineMigrationCompilerPass.php index 0c30e6b..5370dfd 100644 --- a/src/DependencyInjection/Compiler/DoctrineMigrationCompilerPass.php +++ b/src/DependencyInjection/Compiler/DoctrineMigrationCompilerPass.php @@ -4,15 +4,11 @@ namespace RZ\Roadiz\FontBundle\DependencyInjection\Compiler; -use RuntimeException; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; class DoctrineMigrationCompilerPass implements CompilerPassInterface { - /** - * @inheritDoc - */ public function process(ContainerBuilder $container): void { if ($container->hasDefinition('doctrine.migrations.configuration')) { @@ -27,13 +23,13 @@ public function process(ContainerBuilder $container): void private function checkIfBundleRelativePath(string $path, ContainerBuilder $container): string { - if (isset($path[0]) && $path[0] === '@') { - $pathParts = explode('/', $path); + if (isset($path[0]) && '@' === $path[0]) { + $pathParts = explode('/', $path); $bundleName = \mb_substr($pathParts[0], 1); $bundlePath = $this->getBundlePath($bundleName, $container); - return $bundlePath . \mb_substr($path, \mb_strlen('@' . $bundleName)); + return $bundlePath.\mb_substr($path, \mb_strlen('@'.$bundleName)); } return $path; @@ -44,14 +40,8 @@ private function getBundlePath(string $bundleName, ContainerBuilder $container): $bundleMetadata = $container->getParameter('kernel.bundles_metadata'); assert(is_array($bundleMetadata)); - if (! isset($bundleMetadata[$bundleName])) { - throw new RuntimeException( - sprintf( - 'The bundle "%s" has not been registered, available bundles: %s', - $bundleName, - implode(', ', array_keys($bundleMetadata)) - ) - ); + if (!isset($bundleMetadata[$bundleName])) { + throw new \RuntimeException(sprintf('The bundle "%s" has not been registered, available bundles: %s', $bundleName, implode(', ', array_keys($bundleMetadata)))); } return $bundleMetadata[$bundleName]['path']; diff --git a/src/DependencyInjection/RoadizFontExtension.php b/src/DependencyInjection/RoadizFontExtension.php index 256a0d6..3b61072 100644 --- a/src/DependencyInjection/RoadizFontExtension.php +++ b/src/DependencyInjection/RoadizFontExtension.php @@ -16,12 +16,9 @@ public function getAlias(): string return 'roadiz_font'; } - /** - * @inheritDoc - */ public function load(array $configs, ContainerBuilder $container): void { - $loader = new YamlFileLoader($container, new FileLocator(dirname(__DIR__) . '/../config')); + $loader = new YamlFileLoader($container, new FileLocator(dirname(__DIR__).'/../config')); $loader->load('services.yaml'); } } diff --git a/src/Doctrine/EventSubscriber/FontLifeCycleSubscriber.php b/src/Doctrine/EventSubscriber/FontLifeCycleSubscriber.php index 465b2ed..4925243 100644 --- a/src/Doctrine/EventSubscriber/FontLifeCycleSubscriber.php +++ b/src/Doctrine/EventSubscriber/FontLifeCycleSubscriber.php @@ -4,9 +4,13 @@ namespace RZ\Roadiz\FontBundle\Doctrine\EventSubscriber; -use Doctrine\Common\EventSubscriber; +use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; +use Doctrine\ORM\Event\PostPersistEventArgs; +use Doctrine\ORM\Event\PostUpdateEventArgs; +use Doctrine\ORM\Event\PrePersistEventArgs; +use Doctrine\ORM\Event\PreRemoveEventArgs; +use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Events; -use Doctrine\Persistence\Event\LifecycleEventArgs; use League\Flysystem\FilesystemException; use League\Flysystem\FilesystemOperator; use Psr\Log\LoggerInterface; @@ -16,34 +20,22 @@ /** * Handle file management on Fonts lifecycle events. */ -final class FontLifeCycleSubscriber implements EventSubscriber +#[AsDoctrineListener(event: Events::prePersist)] +#[AsDoctrineListener(event: Events::preUpdate)] +#[AsDoctrineListener(event: Events::preRemove)] +#[AsDoctrineListener(event: Events::postPersist)] +#[AsDoctrineListener(event: Events::postUpdate)] +final class FontLifeCycleSubscriber { private static array $formats = ['svg', 'otf', 'eot', 'woff', 'woff2']; public function __construct( private readonly FilesystemOperator $fontStorage, - private readonly LoggerInterface $logger + private readonly LoggerInterface $logger, ) { } - /** - * {@inheritdoc} - */ - public function getSubscribedEvents(): array - { - return [ - Events::prePersist, - Events::preUpdate, - Events::preRemove, - Events::postPersist, - Events::postUpdate, - ]; - } - - /** - * @param LifecycleEventArgs $args - */ - public function prePersist(LifecycleEventArgs $args): void + public function prePersist(PrePersistEventArgs $args): void { $entity = $args->getObject(); // perhaps you only want to act on some "Font" entity @@ -52,10 +44,7 @@ public function prePersist(LifecycleEventArgs $args): void } } - /** - * @param LifecycleEventArgs $args - */ - public function preUpdate(LifecycleEventArgs $args): void + public function preUpdate(PreUpdateEventArgs $args): void { $entity = $args->getObject(); // perhaps you only want to act on some "Font" entity @@ -64,11 +53,7 @@ public function preUpdate(LifecycleEventArgs $args): void } } - /** - * @param LifecycleEventArgs $args - * @throws FilesystemException - */ - public function postPersist(LifecycleEventArgs $args): void + public function postPersist(PostPersistEventArgs $args): void { $entity = $args->getObject(); // perhaps you only want to act on some "Font" entity @@ -77,11 +62,7 @@ public function postPersist(LifecycleEventArgs $args): void } } - /** - * @param LifecycleEventArgs $args - * @throws FilesystemException - */ - public function postUpdate(LifecycleEventArgs $args): void + public function postUpdate(PostUpdateEventArgs $args): void { $entity = $args->getObject(); // perhaps you only want to act on some "Font" entity @@ -90,7 +71,7 @@ public function postUpdate(LifecycleEventArgs $args): void } } - public function preRemove(LifecycleEventArgs $args): void + public function preRemove(PreRemoveEventArgs $args): void { $entity = $args->getObject(); // perhaps you only want to act on some "Product" entity @@ -98,8 +79,8 @@ public function preRemove(LifecycleEventArgs $args): void try { // factorize previous code with loop foreach (self::$formats as $format) { - $getter = 'get' . \mb_strtoupper($format) . 'Filename'; - $relativeUrlGetter = 'get' . \mb_strtoupper($format) . 'RelativeUrl'; + $getter = 'get'.\mb_strtoupper($format).'Filename'; + $relativeUrlGetter = 'get'.\mb_strtoupper($format).'RelativeUrl'; if (null !== $entity->$getter() && $this->fontStorage->fileExists($entity->$relativeUrlGetter())) { $this->fontStorage->delete($entity->$relativeUrlGetter()); $this->logger->info('Font file deleted', ['file' => $entity->$relativeUrlGetter()]); @@ -119,38 +100,36 @@ public function preRemove(LifecycleEventArgs $args): void } } } catch (FilesystemException $e) { - //do nothing + // do nothing } } } public function setFontFilesNames(Font $font): void { - if ($font->getHash() == "") { + if ('' == $font->getHash()) { $font->generateHashWithSecret('default_roadiz_secret'); } foreach (self::$formats as $format) { /** @var UploadedFile|null $file */ - $file = $font->{'get' . ucfirst($format) . 'File'}(); + $file = $font->{'get'.ucfirst($format).'File'}(); if (null !== $file) { - $font->{'set' . \mb_strtoupper($format) . 'Filename'}($file->getClientOriginalName()); + $font->{'set'.\mb_strtoupper($format).'Filename'}($file->getClientOriginalName()); } } } /** - * @param Font $font - * @return void * @throws FilesystemException */ public function upload(Font $font): void { foreach (self::$formats as $format) { /** @var UploadedFile|null $file */ - $file = $font->{'get' . ucfirst($format) . 'File'}(); + $file = $font->{'get'.ucfirst($format).'File'}(); /** @var string|null $relativeUrl */ - $relativeUrl = $font->{'get' . \mb_strtoupper($format) . 'RelativeUrl'}(); + $relativeUrl = $font->{'get'.\mb_strtoupper($format).'RelativeUrl'}(); if (null !== $file && null !== $relativeUrl) { $filename = $file->getPathname(); $fontResource = fopen($file->getPathname(), 'r'); @@ -159,7 +138,7 @@ public function upload(Font $font): void $relativeUrl, $fontResource ); - $font->{'set' . ucfirst($format) . 'File'}(null); + $font->{'set'.ucfirst($format).'File'}(null); fclose($fontResource); $this->logger->info('Font file uploaded', ['file' => $relativeUrl]); } diff --git a/src/Entity/Font.php b/src/Entity/Font.php index 39cc3de..ebb3316 100644 --- a/src/Entity/Font.php +++ b/src/Entity/Font.php @@ -18,11 +18,11 @@ */ #[ ORM\Entity(repositoryClass: FontRepository::class), - ORM\Table(name: "fonts"), - ORM\UniqueConstraint(columns: ["name", "variant"]), - ORM\Index(columns: ["created_at"], name: "font_created_at"), - ORM\Index(columns: ["updated_at"], name: "font_updated_at"), - UniqueEntity(fields: ["name", "variant"]) + ORM\Table(name: 'fonts'), + ORM\UniqueConstraint(columns: ['name', 'variant']), + ORM\Index(columns: ['created_at'], name: 'font_created_at'), + ORM\Index(columns: ['updated_at'], name: 'font_updated_at'), + UniqueEntity(fields: ['name', 'variant']) ] class Font extends AbstractDateTimed { @@ -54,7 +54,7 @@ class Font extends AbstractDateTimed public const MIME_EOT = 'application/vnd.ms-fontobject'; /** - * Get readable variant association + * Get readable variant association. * * @var array */ @@ -130,36 +130,30 @@ class Font extends AbstractDateTimed */ public function __construct() { - $this->folder = \mb_substr(hash("crc32b", date('YmdHi')), 0, 12); + $this->folder = \mb_substr(hash('crc32b', date('YmdHi')), 0, 12); $this->initAbstractDateTimed(); } /** * Get a readable string to describe current font variant. - * - * @return string */ public function getReadableVariant(): string { return static::$variantToHuman[$this->getVariant()]; } - /** - * @return int - */ public function getVariant(): int { return $this->variant; } /** - * @param int $variant - * * @return $this */ public function setVariant(int $variant): Font { $this->variant = $variant; + return $this; } @@ -171,7 +165,6 @@ public function setVariant(int $variant): Font * * weight * * @see https://developer.mozilla.org/fr/docs/Web/CSS/font-weight - * @return array */ public function getFontVariantInfos(): array { @@ -287,35 +280,27 @@ public function getFontVariantInfos(): array } } - /** - * @return string - */ public function getName(): string { return $this->name; } /** - * @param string $name * @return $this */ public function setName(string $name): Font { $this->name = $name; + return $this; } - /** - * @return string - */ public function getHash(): string { return $this->hash; } /** - * @param string $hash - * * @return $this */ public function setHash(string $hash): Font @@ -326,178 +311,137 @@ public function setHash(string $hash): Font } /** - * @param string $secret * @return $this */ public function generateHashWithSecret(string $secret): Font { - $this->hash = \mb_substr(hash("crc32b", $this->name . $secret), 0, 12); + $this->hash = \mb_substr(hash('crc32b', $this->name.$secret), 0, 12); return $this; } - /** - * @return string|null - */ public function getEOTRelativeUrl(): ?string { - return $this->getFolder() . '/' . $this->getEOTFilename(); + return $this->getFolder().'/'.$this->getEOTFilename(); } - /** - * @return string - */ public function getFolder(): string { return $this->folder; } - /** - * @return string|null - */ public function getEOTFilename(): ?string { return $this->eotFilename; } /** - * @param string|null $eotFilename * @return $this */ public function setEOTFilename(?string $eotFilename): Font { $this->eotFilename = StringHandler::cleanForFilename($eotFilename); + return $this; } - /** - * @return string|null - */ public function getWOFFRelativeUrl(): ?string { - return $this->getFolder() . '/' . $this->getWOFFFilename(); + return $this->getFolder().'/'.$this->getWOFFFilename(); } - /** - * @return string|null - */ public function getWOFFFilename(): ?string { return $this->woffFilename; } /** - * @param string|null $woffFilename * @return $this */ public function setWOFFFilename(?string $woffFilename): Font { $this->woffFilename = StringHandler::cleanForFilename($woffFilename); + return $this; } - /** - * @return string|null - */ public function getWOFF2RelativeUrl(): ?string { - return $this->getFolder() . '/' . $this->getWOFF2Filename(); + return $this->getFolder().'/'.$this->getWOFF2Filename(); } - /** - * @return string|null - */ public function getWOFF2Filename(): ?string { return $this->woff2Filename; } /** - * @param string|null $woff2Filename - * * @return $this */ public function setWOFF2Filename(?string $woff2Filename): Font { $this->woff2Filename = StringHandler::cleanForFilename($woff2Filename); + return $this; } - /** - * @return string|null - */ public function getOTFRelativeUrl(): ?string { - return $this->getFolder() . '/' . $this->getOTFFilename(); + return $this->getFolder().'/'.$this->getOTFFilename(); } - /** - * @return string|null - */ public function getOTFFilename(): ?string { return $this->otfFilename; } /** - * @param string|null $otfFilename * @return $this */ public function setOTFFilename(?string $otfFilename): Font { $this->otfFilename = StringHandler::cleanForFilename($otfFilename); + return $this; } - /** - * @return string|null - */ public function getSVGRelativeUrl(): ?string { - return $this->getFolder() . '/' . $this->getSVGFilename(); + return $this->getFolder().'/'.$this->getSVGFilename(); } - /** - * @return string|null - */ public function getSVGFilename(): ?string { return $this->svgFilename; } /** - * @param string|null $svgFilename * @return $this */ public function setSVGFilename(?string $svgFilename): Font { $this->svgFilename = StringHandler::cleanForFilename($svgFilename); + return $this; } - /** - * @return string|null - */ public function getDescription(): ?string { return $this->description; } /** - * @param string|null $description - * * @return $this */ public function setDescription(?string $description): Font { $this->description = $description; + return $this; } /** * Gets the value of eotFile. - * - * @return UploadedFile|null */ public function getEotFile(): ?UploadedFile { @@ -508,18 +452,16 @@ public function getEotFile(): ?UploadedFile * Sets the value of eotFile. * * @param UploadedFile|null $eotFile the eot file - * @return Font */ public function setEotFile(?UploadedFile $eotFile): Font { $this->eotFile = $eotFile; + return $this; } /** * Gets the value of woffFile. - * - * @return UploadedFile|null */ public function getWoffFile(): ?UploadedFile { @@ -530,18 +472,16 @@ public function getWoffFile(): ?UploadedFile * Sets the value of woffFile. * * @param UploadedFile|null $woffFile the woff file - * @return Font */ public function setWoffFile(?UploadedFile $woffFile): Font { $this->woffFile = $woffFile; + return $this; } /** * Gets the value of woff2File. - * - * @return UploadedFile|null */ public function getWoff2File(): ?UploadedFile { @@ -552,18 +492,16 @@ public function getWoff2File(): ?UploadedFile * Sets the value of woff2File. * * @param UploadedFile|null $woff2File the woff2 file - * @return Font */ public function setWoff2File(?UploadedFile $woff2File): Font { $this->woff2File = $woff2File; + return $this; } /** * Gets the value of otfFile. - * - * @return UploadedFile|null */ public function getOtfFile(): ?UploadedFile { @@ -574,18 +512,16 @@ public function getOtfFile(): ?UploadedFile * Sets the value of otfFile. * * @param UploadedFile|null $otfFile the otf file - * @return Font */ public function setOtfFile(?UploadedFile $otfFile): Font { $this->otfFile = $otfFile; + return $this; } /** * Gets the value of svgFile. - * - * @return UploadedFile|null */ public function getSvgFile(): ?UploadedFile { @@ -596,11 +532,11 @@ public function getSvgFile(): ?UploadedFile * Sets the value of svgFile. * * @param UploadedFile|null $svgFile the svg file - * @return Font */ public function setSvgFile(?UploadedFile $svgFile): Font { $this->svgFile = $svgFile; + return $this; } } diff --git a/src/Event/Font/FontEvent.php b/src/Event/Font/FontEvent.php index 18bc115..5513ce9 100644 --- a/src/Event/Font/FontEvent.php +++ b/src/Event/Font/FontEvent.php @@ -9,34 +9,22 @@ abstract class FontEvent extends Event { - /** - * @var Font|null - */ protected ?Font $font = null; - /** - * @param Font|null $font - */ public function __construct(?Font $font) { $this->font = $font; } - /** - * @return Font|null - */ public function getFont(): ?Font { return $this->font; } - /** - * @param Font|null $font - * @return FontEvent - */ public function setFont(?Font $font): FontEvent { $this->font = $font; + return $this; } } diff --git a/src/EventSubscriber/UpdateFontSubscriber.php b/src/EventSubscriber/UpdateFontSubscriber.php index dcda650..2d6328b 100644 --- a/src/EventSubscriber/UpdateFontSubscriber.php +++ b/src/EventSubscriber/UpdateFontSubscriber.php @@ -11,23 +11,17 @@ /** * Calls font life cycle methods when no data changed according to Doctrine. - * - * @package RZ\Roadiz\CoreBundle\Event */ -final class UpdateFontSubscriber implements EventSubscriberInterface +final readonly class UpdateFontSubscriber implements EventSubscriberInterface { - public function __construct(private readonly FontLifeCycleSubscriber $fontSubscriber) + public function __construct(private FontLifeCycleSubscriber $fontSubscriber) { } - /** - * @inheritDoc - */ public static function getSubscribedEvents(): array { return [ PreUpdatedFontEvent::class => 'onPreUpdatedFont', - '\RZ\Roadiz\Core\Events\Font\PreUpdatedFontEvent' => 'onPreUpdatedFont', ]; } diff --git a/src/Form/FontType.php b/src/Form/FontType.php index 9c86053..05ca43b 100644 --- a/src/Form/FontType.php +++ b/src/Form/FontType.php @@ -12,22 +12,15 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\File; -/** - * FontType. - */ class FontType extends AbstractType { - /** - * @param FormBuilderInterface $builder - * @param array $options - */ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('name', TextType::class, [ - 'label' => 'font.name', - 'empty_data' => '', - 'help' => 'font_name_should_be_the_same_for_all_variants', - ]) + 'label' => 'font.name', + 'empty_data' => '', + 'help' => 'font_name_should_be_the_same_for_all_variants', + ]) ->add('hash', TextType::class, [ 'label' => 'font.cssfamily', 'empty_data' => '', diff --git a/src/Form/FontVariantsType.php b/src/Form/FontVariantsType.php index 4a76fe6..c58f3cb 100644 --- a/src/Form/FontVariantsType.php +++ b/src/Form/FontVariantsType.php @@ -14,26 +14,18 @@ */ class FontVariantsType extends AbstractType { - /** - * {@inheritdoc} - * @param OptionsResolver $resolver [description] - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'choices' => array_flip(Font::$variantToHuman), ]); } - /** - * {@inheritdoc} - */ + public function getParent(): ?string { return ChoiceType::class; } - /** - * {@inheritdoc} - */ + public function getBlockPrefix(): string { return 'font_variants'; diff --git a/src/Repository/FontRepository.php b/src/Repository/FontRepository.php index de702bf..b53221e 100644 --- a/src/Repository/FontRepository.php +++ b/src/Repository/FontRepository.php @@ -18,7 +18,7 @@ final class FontRepository extends EntityRepository { public function __construct( ManagerRegistry $registry, - EventDispatcherInterface $dispatcher + EventDispatcherInterface $dispatcher, ) { parent::__construct($registry, Font::class, $dispatcher); }