From 48efba949667d4d8badca33bc29f8cda9127e95c Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Fri, 12 Nov 2021 11:57:20 +0100 Subject: [PATCH 1/2] Bump PHPStan to level 4 --- .phpstan/baseline.neon | 10 ++++++++++ composer.json | 3 ++- phpstan.neon.dist | 6 +++++- src/DependencyInjection/Configuration.php | 10 +++++++--- .../LiipImagineExtension.php | 4 ++-- src/Events/CacheResolveEvent.php | 2 -- .../Resolver/AbstractFilesystemResolver.php | 4 ++-- .../Filter/Loader/BackgroundFilterLoader.php | 1 - .../Filter/Loader/ResampleFilterLoader.php | 20 ++++--------------- .../Filter/Loader/WatermarkFilterLoader.php | 1 - .../PostProcessor/PngquantPostProcessor.php | 2 +- 11 files changed, 33 insertions(+), 30 deletions(-) diff --git a/.phpstan/baseline.neon b/.phpstan/baseline.neon index de5c60e00..19e3469fd 100644 --- a/.phpstan/baseline.neon +++ b/.phpstan/baseline.neon @@ -3,3 +3,13 @@ parameters: - message: '#^Access to undefined constant static\(Liip\\ImagineBundle\\Config\\Filter\\Type\\FilterAbstract\)::NAME\.$#' paths: - ../src/Config/Filter/Type/FilterAbstract.php + + # BC Layer for Symfony < 5.1 + - message: "#^Call to function is_array\\(\\) with string will always evaluate to false\\.$#" + count: 1 + path: ../src/Controller/ImagineController.php + + # BC Layer for Symfony < 5.1 + - message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: ../src/Controller/ImagineController.php diff --git a/composer.json b/composer.json index 5a329916a..ce4515342 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "aws/aws-sdk-php": "^2.4", "doctrine/persistence": "^1.3|^2.0", "league/flysystem": "^1.0|^2.0", - "phpstan/phpstan": "^0.12.64", + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-symfony": "^1.0", "psr/cache": "^1.0|^2.0|^3.0", "psr/log": "^1.0", "symfony/browser-kit": "^4.4|^5.3|^6.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b55095793..3c5904a42 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,10 +1,14 @@ includes: - .phpstan/baseline.neon + - vendor/phpstan/phpstan-symfony/extension.neon parameters: - level: 1 + level: 4 paths: - src + treatPhpDocTypesAsCertain: false scanFiles: - .phpstan/stubs/AdapterInterface.stub - .phpstan/stubs/FilesystemInterface.stub - .phpstan/stubs/ReadInterface.stub + dynamicConstantNames: + - Symfony\Component\HttpKernel\Kernel::VERSION diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index b232f20f4..2f1ea60ec 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -26,12 +26,12 @@ class Configuration implements ConfigurationInterface /** * @var ResolverFactoryInterface[] */ - protected $resolversFactories; + protected array $resolversFactories; /** * @var LoaderFactoryInterface[] */ - protected $loadersFactories; + protected array $loadersFactories; /** * @param ResolverFactoryInterface[] $resolversFactories @@ -251,7 +251,11 @@ private function addConfigurationSections(array $factories, ArrayNodeDefinition $f->addConfiguration($definition->children()->arrayNode($f->getName())); } - $definition->end() + $nodeDefinition = $definition->end(); + + \assert($nodeDefinition instanceof ArrayNodeDefinition); + + $nodeDefinition ->validate() ->ifTrue(function ($array) use ($type) { foreach ($array as $name => $element) { diff --git a/src/DependencyInjection/LiipImagineExtension.php b/src/DependencyInjection/LiipImagineExtension.php index 334d5b31c..3ea73abc3 100644 --- a/src/DependencyInjection/LiipImagineExtension.php +++ b/src/DependencyInjection/LiipImagineExtension.php @@ -32,12 +32,12 @@ class LiipImagineExtension extends Extension implements PrependExtensionInterfac /** * @var ResolverFactoryInterface[] */ - private $resolversFactories = []; + private array $resolversFactories = []; /** * @var LoaderFactoryInterface[] */ - private $loadersFactories = []; + private array $loadersFactories = []; public function addResolverFactory(ResolverFactoryInterface $resolverFactory): void { diff --git a/src/Events/CacheResolveEvent.php b/src/Events/CacheResolveEvent.php index e108c825a..dcec6ef32 100644 --- a/src/Events/CacheResolveEvent.php +++ b/src/Events/CacheResolveEvent.php @@ -58,8 +58,6 @@ public function getPath(): string /** * Sets filter name. - * - * @param $filter */ public function setFilter(string $filter): void { diff --git a/src/Imagine/Cache/Resolver/AbstractFilesystemResolver.php b/src/Imagine/Cache/Resolver/AbstractFilesystemResolver.php index d841da286..bdbfd8cde 100644 --- a/src/Imagine/Cache/Resolver/AbstractFilesystemResolver.php +++ b/src/Imagine/Cache/Resolver/AbstractFilesystemResolver.php @@ -28,7 +28,7 @@ abstract class AbstractFilesystemResolver implements ResolverInterface, CacheMan protected int $folderPermissions = 0777; - private Request $request; + private ?Request $request = null; /** * Constructs a filesystem based cache resolver. @@ -112,7 +112,7 @@ public function remove(array $paths, array $filters): void */ protected function getRequest(): Request { - if (false === $this->request) { + if (null === $this->request) { throw new \LogicException('The request was not injected, inject it before using resolver.'); } diff --git a/src/Imagine/Filter/Loader/BackgroundFilterLoader.php b/src/Imagine/Filter/Loader/BackgroundFilterLoader.php index 4fa9136d5..41d306970 100644 --- a/src/Imagine/Filter/Loader/BackgroundFilterLoader.php +++ b/src/Imagine/Filter/Loader/BackgroundFilterLoader.php @@ -89,7 +89,6 @@ public function load(ImageInterface $image, array $options = []): ImageInterface break; default: throw new \InvalidArgumentException("Unexpected position '{$position}'"); - break; } $size = new Box($width, $height); diff --git a/src/Imagine/Filter/Loader/ResampleFilterLoader.php b/src/Imagine/Filter/Loader/ResampleFilterLoader.php index 121235b02..b025c4a49 100644 --- a/src/Imagine/Filter/Loader/ResampleFilterLoader.php +++ b/src/Imagine/Filter/Loader/ResampleFilterLoader.php @@ -49,13 +49,9 @@ public function load(ImageInterface $image, array $options = []): ImageInterface } /** - * @param string $path - * * @throws \RuntimeException - * - * @return string */ - private function getTemporaryFile($path) + private function getTemporaryFile(string $path): string { if (!is_dir($path) || false === $file = tempnam($path, 'liip-imagine-bundle')) { throw new \RuntimeException(sprintf('Unable to create temporary file in "%s" base path.', $path)); @@ -65,21 +61,16 @@ private function getTemporaryFile($path) } /** - * @param $file - * * @throws \RuntimeException */ - private function delTemporaryFile($file) + private function delTemporaryFile(string $file): void { if (file_exists($file)) { unlink($file); } } - /** - * @return array - */ - private function getImagineSaveOptions(array $options) + private function getImagineSaveOptions(array $options): array { $saveOptions = [ 'resolution-units' => $options['unit'], @@ -94,10 +85,7 @@ private function getImagineSaveOptions(array $options) return $saveOptions; } - /** - * @return array - */ - private function resolveOptions(array $options) + private function resolveOptions(array $options): array { $resolver = new OptionsResolver(); diff --git a/src/Imagine/Filter/Loader/WatermarkFilterLoader.php b/src/Imagine/Filter/Loader/WatermarkFilterLoader.php index 8a5eccd8e..048d00a45 100644 --- a/src/Imagine/Filter/Loader/WatermarkFilterLoader.php +++ b/src/Imagine/Filter/Loader/WatermarkFilterLoader.php @@ -110,7 +110,6 @@ public function load(ImageInterface $image, array $options = []): ImageInterface break; default: throw new \InvalidArgumentException("Unexpected position '{$options['position']}'"); - break; } return $image->paste($watermark, new Point($x, $y)); diff --git a/src/Imagine/Filter/PostProcessor/PngquantPostProcessor.php b/src/Imagine/Filter/PostProcessor/PngquantPostProcessor.php index 172113568..ea97085d7 100644 --- a/src/Imagine/Filter/PostProcessor/PngquantPostProcessor.php +++ b/src/Imagine/Filter/PostProcessor/PngquantPostProcessor.php @@ -42,7 +42,7 @@ public function __construct(string $executablePath = '/usr/bin/pngquant', $quali $this->quality = $quality; } - /* + /** * @throws ProcessFailedException */ public function process(BinaryInterface $binary, array $options = []): BinaryInterface From c10c2da50adbb1aac34adb3fe1f4f71472022cac Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Fri, 12 Nov 2021 11:59:49 +0100 Subject: [PATCH 2/2] Fix composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ce4515342..b0f026ea5 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "symfony/console": "^4.4|^5.3|^6.0", "symfony/dependency-injection": "^4.4|^5.3|^6.0", "symfony/form": "^4.4|^5.3|^6.0", - "symfony/messenger": "^4.4|^5.3|^6.0, + "symfony/messenger": "^4.4|^5.3|^6.0", "symfony/phpunit-bridge": "^5.3|^6.0", "symfony/templating": "^4.4|^5.3|^6.0", "symfony/validator": "^4.4|^5.3|^6.0",