Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @symfony rules to PhpCsFixer #5

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'@Symfony' => true,
'declare_strict_types' => true,
'header_comment' => ['header' => $licence],
])
Expand Down
3 changes: 1 addition & 2 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sensiolabs\MinifyBundle\AssetMapper\MinifierCompiler;
use Sensiolabs\MinifyBundle\Command\MinifyInstallCommand;
use Sensiolabs\MinifyBundle\Command\MinifyAssetCommand;
use Sensiolabs\MinifyBundle\Command\MinifyInstallCommand;
use Sensiolabs\MinifyBundle\Minifier\MinifierInterface;
use Sensiolabs\MinifyBundle\Minify;
use Sensiolabs\MinifyBundle\MinifyFactory;
use Sensiolabs\MinifyBundle\MinifyInstaller;

return static function (ContainerConfigurator $container) {

$container->services()

->set('.sensiolabs_minify.minifier.minify_installer', MinifyInstaller::class)
Expand Down
5 changes: 2 additions & 3 deletions src/AssetMapper/MinifierCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
final class MinifierCompiler implements AssetCompilerInterface
{
/**
* @param MinifierInterface $minify
* @param list<string> $extensions
* @param list<string> $ignorePaths
*/
Expand Down Expand Up @@ -58,10 +57,10 @@ public function supports(MappedAsset $asset): bool

public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
{
$type = match($extension = $asset->publicExtension) {
$type = match ($extension = $asset->publicExtension) {
'css', 'scss' => 'css',
'js' => 'js',
default => throw new RuntimeException(sprintf('Invalid type "%s".', $extension))
default => throw new RuntimeException(sprintf('Invalid type "%s".', $extension)),
};

return $this->minify->minify($content, $type);
Expand Down
3 changes: 3 additions & 0 deletions src/Command/MinifyAssetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
if (!$fs->exists($inputArg)) {
$io->error(sprintf('Cannot read file "%s".', $inputArg));

return Command::FAILURE;
}

Expand All @@ -96,6 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (null === $outputArg) {
$io->text($output);

return Command::SUCCESS;
}

Expand All @@ -104,6 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$fs->dumpFile($outputArg, $output);
} catch (IOException) {
$io->error(sprintf('Cannot write to file "%s".', $outputArg));

return Command::FAILURE;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Minifier/MinifierInstallerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ interface MinifierInstallerInterface
public function install(string $version = self::VERSION_LATEST, bool $force = false): void;

/**
* @return bool Whether the binary is installed
* @return bool Whether the binary is installed
*/
public function isInstalled(): bool;

/**
* @return string The path to the installed binary
* @return string The path to the installed binary
*/
public function getInstallBinaryPath(): string;
}
2 changes: 0 additions & 2 deletions src/Minifier/MinifierInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ interface MinifierInterface
public const TYPE_JS = 'js';

/**
* @param string $input
* @param self::TYPE_CSS|self::TYPE_JS $type
* @return string
*/
public function minify(string $input, string $type): string;
}
1 change: 0 additions & 1 deletion src/MinifyInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,4 @@ private function getReleaseAsset(string $version): array

throw new InstallException(sprintf('Unable to find a binary for release "%s".', $version));
}

}
6 changes: 0 additions & 6 deletions src/SensiolabsMinifyBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@

namespace Sensiolabs\MinifyBundle;

use Sensiolabs\MinifyBundle\AssetMapper\MinifierCompiler;
use Sensiolabs\MinifyBundle\Command\MinifyAssetCommand;
use Sensiolabs\MinifyBundle\Command\MinifyInstallCommand;
use Sensiolabs\MinifyBundle\Minifier\MinifierInterface;
use Sensiolabs\MinifyBundle\Minifier\TraceableMinifier;
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

Expand Down
2 changes: 1 addition & 1 deletion tests/EventListener/PreAssetsCompileEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace Sensiolabs\MinifyBundle\Tests\EventListener;

use PHPUnit\Framework\Attributes\CoversClass;
use Sensiolabs\MinifyBundle\EventListener\PreAssetsCompileEventListener;
use PHPUnit\Framework\TestCase;
use Sensiolabs\MinifyBundle\EventListener\PreAssetsCompileEventListener;
use Sensiolabs\MinifyBundle\Minifier\MinifierInstallerInterface;
use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent;
use Symfony\Component\Console\Output\NullOutput;
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/MinifyBundleTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public function registerBundles(): iterable
return [
new FrameworkBundle(),
new SensiolabsMinifyBundle(),
new class () extends Bundle {
new class extends Bundle {
public function shutdown(): void
{
restore_exception_handler();
}
}
},
];
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Minifier/SystemUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace Sensiolabs\MinifyBundle\Tests\Minifier;

use PHPUnit\Framework\Attributes\CoversClass;
use Sensiolabs\MinifyBundle\Minifier\SystemUtils;
use PHPUnit\Framework\TestCase;
use Sensiolabs\MinifyBundle\Minifier\SystemUtils;

#[CoversClass(SystemUtils::class)]
class SystemUtilsTest extends TestCase
Expand Down Expand Up @@ -55,5 +55,4 @@ public function testMatchReturnsFalseForNonMatchingArchitecture()
$releaseUtils = new SystemUtils('linux', 'amd64');
$this->assertFalse($releaseUtils->match('linux-arm64'));
}

}
2 changes: 1 addition & 1 deletion tests/Minifier/TraceableMinifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
namespace Sensiolabs\MinifyBundle\Tests\Minifier;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Sensiolabs\MinifyBundle\Minifier\MinifierInterface;
use Sensiolabs\MinifyBundle\Minifier\TraceableMinifier;
use PHPUnit\Framework\TestCase;

#[CoversClass(TraceableMinifier::class)]
class TraceableMinifierTest extends TestCase
Expand Down