Skip to content

Commit

Permalink
Merge pull request #1416 from franmomu/phpstan1
Browse files Browse the repository at this point in the history
Bump PHPStan to level 4
  • Loading branch information
dbu authored Nov 12, 2021
2 parents afcbc92 + c10c2da commit fec3726
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 31 deletions.
10 changes: 10 additions & 0 deletions .phpstan/baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@
"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",
"symfony/cache": "^4.4|^5.3|^6.0",
"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",
Expand Down
6 changes: 5 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/LiipImagineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 0 additions & 2 deletions src/Events/CacheResolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public function getPath(): string

/**
* Sets filter name.
*
* @param $filter
*/
public function setFilter(string $filter): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Imagine/Cache/Resolver/AbstractFilesystemResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.');
}

Expand Down
1 change: 0 additions & 1 deletion src/Imagine/Filter/Loader/BackgroundFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 4 additions & 16 deletions src/Imagine/Filter/Loader/ResampleFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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'],
Expand All @@ -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();

Expand Down
1 change: 0 additions & 1 deletion src/Imagine/Filter/Loader/WatermarkFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/Imagine/Filter/PostProcessor/PngquantPostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fec3726

Please sign in to comment.