Skip to content

Commit

Permalink
refactor: Use friendsofphp/php-cs-fixer instead of squizlabs/php_code…
Browse files Browse the repository at this point in the history
…sniffer (#22)
  • Loading branch information
roadiz-ci committed Nov 6, 2024
1 parent c23ae55 commit 65c7c83
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 242 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions Makefile

This file was deleted.

1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"roadiz/documents": "2.4.x-dev",
"roadiz/entity-generator": "2.4.x-dev",
"roadiz/rozier-bundle": "2.4.x-dev",
"squizlabs/php_codesniffer": "^3.5",
"symfony/browser-kit": "6.4.*",
"symfony/phpunit-bridge": "^7.0",
"symfony/stopwatch": "6.4.*"
Expand Down
13 changes: 0 additions & 13 deletions phpcs.xml.dist

This file was deleted.

63 changes: 12 additions & 51 deletions src/Controller/Admin/FontsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,121 +27,82 @@ class FontsController extends AbstractAdminController
public function __construct(
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
Expand All @@ -151,37 +112,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);
}

Expand Down
25 changes: 8 additions & 17 deletions src/Controller/FontFaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 5 additions & 15 deletions src/DependencyInjection/Compiler/DoctrineMigrationCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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;
Expand All @@ -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'];
Expand Down
5 changes: 1 addition & 4 deletions src/DependencyInjection/RoadizFontExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Loading

0 comments on commit 65c7c83

Please sign in to comment.