Skip to content

Commit

Permalink
Merge pull request #1432 from franmomu/phpstan_level_5
Browse files Browse the repository at this point in the history
Increase PHPStan level to 6
  • Loading branch information
dbu committed Nov 22, 2021
2 parents fec3726 + 02ce085 commit 6ed7f68
Show file tree
Hide file tree
Showing 17 changed files with 676 additions and 51 deletions.
5 changes: 5 additions & 0 deletions .phpstan/baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ parameters:
- message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: ../src/Controller/ImagineController.php

# BC Layer for Symfony < 5.1
- message: "#^Parameter \\#2 \\$default of method Symfony\\\\Component\\\\HttpFoundation\\\\InputBag\\<string\\>\\:\\:get\\(\\) expects string\\|null, array given\\.$#"
count: 1
path: ../src/Controller/ImagineController.php
622 changes: 622 additions & 0 deletions .phpstan/iterable_types_baseline.neon

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
includes:
- .phpstan/baseline.neon
- .phpstan/iterable_types_baseline.neon
- vendor/phpstan/phpstan-symfony/extension.neon
parameters:
level: 4
level: 6
paths:
- src
treatPhpDocTypesAsCertain: false
Expand Down
6 changes: 6 additions & 0 deletions src/Binary/Loader/AbstractDoctrineLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ abstract class AbstractDoctrineLoader implements LoaderInterface
{
protected ObjectManager $manager;

/**
* @phpstan-var class-string
*/
protected string $modelClass;

/**
* @phpstan-param class-string $modelClass
*/
public function __construct(ObjectManager $manager, string $modelClass)
{
$this->manager = $manager;
Expand Down
19 changes: 10 additions & 9 deletions src/Binary/Loader/ChainLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,24 @@ public function find($path)
}

/**
* @param \Exception[] $exceptions
* @param array<string, LoaderInterface> $exceptions
* @param array<string, LoaderInterface> $loaders
*/
private static function getLoaderExceptionMessage(string $path, array $exceptions, array $loaders): string
{
array_walk($loaders, function (LoaderInterface &$loader, string $name): void {
$loader = sprintf('%s=[%s]', (new \ReflectionObject($loader))->getShortName(), $name);
});
$loaderMessages = array_map(static function (string $name, LoaderInterface $loader) {
return sprintf('%s=[%s]', (new \ReflectionObject($loader))->getShortName(), $name);
}, array_keys($loaders), $loaders);

array_walk($exceptions, function (LoaderInterface &$loader, string $message): void {
$loader = sprintf('%s=[%s]', (new \ReflectionObject($loader))->getShortName(), $message);
});
$exceptionMessages = array_map(static function (string $message, LoaderInterface $loader) {
return sprintf('%s=[%s]', (new \ReflectionObject($loader))->getShortName(), $message);
}, array_keys($exceptions), $exceptions);

return vsprintf('Source image not resolvable "%s" using "%s" %d loaders (internal exceptions: %s).', [
$path,
implode(', ', $loaders),
implode(', ', $loaderMessages),
\count($loaders),
implode(', ', $exceptions),
implode(', ', $exceptionMessages),
]);
}
}
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private function addLoadersSections(ArrayNodeDefinition $resolversPrototypeNode)
/**
* @param FactoryInterface[] $factories
*/
private function addConfigurationSections(array $factories, ArrayNodeDefinition $definition, $type): void
private function addConfigurationSections(array $factories, ArrayNodeDefinition $definition, string $type): void
{
foreach ($factories as $f) {
$f->addConfiguration($definition->children()->arrayNode($f->getName()));
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/LiipImagineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ private function createFilterSets(array $defaultFilterSets, array $filterSets):
}, $filterSets);
}

private function loadResolvers(array $config, ContainerBuilder $container)
private function loadResolvers(array $config, ContainerBuilder $container): void
{
$this->createFactories($this->resolversFactories, $config, $container);
}

private function loadLoaders(array $config, ContainerBuilder $container)
private function loadLoaders(array $config, ContainerBuilder $container): void
{
$this->createFactories($this->loadersFactories, $config, $container);
}

private function createFactories(array $factories, array $configurations, ContainerBuilder $container)
private function createFactories(array $factories, array $configurations, ContainerBuilder $container): void
{
foreach ($configurations as $name => $conf) {
$factories[key($conf)]->create($container, $name, $conf[key($conf)]);
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Config/Filter/Argument/PointFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
final class PointFactory
{
public function create($x = null, $y = null): Point
public function create(int $x = null, int $y = null): Point
{
return new Point($x, $y);
}
Expand Down
8 changes: 7 additions & 1 deletion src/Imagine/Cache/Resolver/AbstractFilesystemResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ public function remove(array $paths, array $filters): void
return;
}

$firstFilter = current($filters);

if (!\is_string($firstFilter) || '' === $firstFilter) {
return;
}

// TODO: this logic has to be refactored.
[$rootCachePath] = explode(current($filters), $this->getFilePath('whateverpath', current($filters)));
[$rootCachePath] = explode($firstFilter, $this->getFilePath('whateverpath', $firstFilter));

if (empty($paths)) {
$filtersCachePaths = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Imagine/Cache/Resolver/AwsS3Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function remove(array $paths, array $filters): void

if (empty($paths)) {
try {
$this->storage->deleteMatchingObjects($this->bucket, null, sprintf(
$this->storage->deleteMatchingObjects($this->bucket, '', sprintf(
'/%s/i',
implode('|', $filters)
));
Expand Down
4 changes: 2 additions & 2 deletions src/Imagine/Filter/Loader/FixedFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function load(ImageInterface $image, array $options = []): ImageInterface
// define filters
$resize = new Resize($size);
$origin = new Point(
floor(($size->getWidth() - $box->getWidth()) / 2),
floor(($size->getHeight() - $box->getHeight()) / 2)
(int) floor(($size->getWidth() - $box->getWidth()) / 2),
(int) floor(($size->getHeight() - $box->getHeight()) / 2)
);
$crop = new Crop($origin, $box);

Expand Down
2 changes: 1 addition & 1 deletion src/Imagine/Filter/Loader/ScaleFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function load(ImageInterface $image, array $options = []): ImageInterface
}

if ($this->isImageProcessable($ratio)) {
$filter = new Resize(new Box(round($origWidth * $ratio), round($origHeight * $ratio)));
$filter = new Resize(new Box((int) round($origWidth * $ratio), (int) round($origHeight * $ratio)));

return $filter->apply($image);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Imagine/Filter/RelativeResize.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
class RelativeResize implements FilterInterface
{
private string $method;

/**
* @var mixed
*/
private $parameter;

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Templating/LazyFilterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public function getFilters(): array
];
}

/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'liip_imagine_lazy';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Framework/SymfonyFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public static function isKernelLessThan(int $major, int $minor = null, int $patc

private static function kernelVersionCompare(string $operator, int $major, int $minor = null, int $patch = null): bool
{
return version_compare(Kernel::VERSION_ID, sprintf("%d%'.02d%'.02d", $major, $minor ?: 0, $patch ?: 0), $operator);
return version_compare((string) Kernel::VERSION_ID, sprintf("%d%'.02d%'.02d", $major, $minor ?: 0, $patch ?: 0), $operator);
}
}
26 changes: 7 additions & 19 deletions tests/Functional/AbstractSetupWebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,13 @@
*/
class AbstractSetupWebTestCase extends AbstractWebTestCase
{
/**
* @var KernelBrowser
*/
protected $client;

/**
* @var Filesystem
*/
protected $filesystem;

/**
* @var string
*/
protected $webRoot;

/**
* @var string
*/
protected $cacheRoot;
protected KernelBrowser $client;

protected Filesystem $filesystem;

protected string $webRoot;

protected string $cacheRoot;

protected function setUp(): void
{
Expand Down
9 changes: 2 additions & 7 deletions tests/Functional/AbstractWebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public static function getKernelClass(): string
return AppKernel::class;
}

/**
* @return object
*/
protected function getService(string $name)
protected function getService(string $name): ?object
{
if (property_exists($this, 'container')) {
return static::$container->get($name);
Expand All @@ -48,11 +45,9 @@ protected function getParameter(string $name)
}

/**
* @param object $object
*
* @return mixed
*/
protected function getPrivateProperty($object, string $name)
protected function getPrivateProperty(object $object, string $name)
{
$r = new \ReflectionObject($object);

Expand Down

0 comments on commit 6ed7f68

Please sign in to comment.