Skip to content

Commit

Permalink
remove obsolete BC code and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jan 2, 2024
1 parent aa28313 commit 8e5b173
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/Binary/Locator/FileSystemLocator.php
Expand Up @@ -69,7 +69,7 @@ private function locateUsingRootPathsSearch(string $path): ?string

private function locateUsingRootPlaceholder(string $path): ?string
{
if (0 !== mb_strpos($path, '@') || 1 !== preg_match('{^@(?<name>[^:]+):(?<path>.+)$}', $path, $match)) {
if (!str_starts_with($path, '@') || 1 !== preg_match('{^@(?<name>[^:]+):(?<path>.+)$}', $path, $match)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Config/FilterFactoryCollection.php
Expand Up @@ -33,7 +33,7 @@ public function __construct(FilterFactoryInterface ...$filterFactories)
*/
public function getFilterFactoryByName(string $name): FilterFactoryInterface
{
if (!isset($this->filterFactories[$name])) {
if (!\array_key_exists($name, $this->filterFactories)) {
throw new NotFoundException(sprintf("Filter factory with name '%s' was not found.", $name));
}

Expand Down
Expand Up @@ -37,7 +37,7 @@ public function create(ContainerBuilder $container, string $name, array $config)
$resolverId = 'liip_imagine.cache.resolver.'.$name;
$container->setDefinition($resolverId, $resolverDefinition);

if (isset($config['cache_prefix'])) {
if (\array_key_exists('cache_prefix', $config)) {
$resolverDefinition->addMethodCall('setCachePrefix', [$config['cache_prefix']]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Config/Filter/Argument/PointFactory.php
Expand Up @@ -28,7 +28,7 @@ public function create(int $x = null, int $y = null): Point

public function createFromOptions(array $options, string $propertyName): Point
{
if (!isset($options[$propertyName])) {
if (!\array_key_exists($propertyName, $options)) {
return new Point();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Config/Filter/Argument/SizeFactory.php
Expand Up @@ -28,7 +28,7 @@ public function create(int $width = null, int $height = null): Size

public function createFromOptions(array $options, string $propertyName = 'size'): Size
{
if (!isset($options[$propertyName])) {
if (!\array_key_exists($propertyName, $options)) {
return new Size();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Config/Filter/DownscaleFactory.php
Expand Up @@ -38,7 +38,7 @@ public function getName(): string
public function create(array $options): FilterInterface
{
$max = $this->sizeFactory->createFromOptions($options, 'max');
$by = isset($options['by']) ? (float) $options['by'] : null;
$by = \array_key_exists('by', $options) ? (float) $options['by'] : null;

return new Downscale($max, $by);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Config/Filter/RotateFactory.php
Expand Up @@ -29,7 +29,7 @@ public function getName(): string

public function create(array $options): FilterInterface
{
$angle = isset($options['angle']) ? (int) $options['angle'] : 0;
$angle = \array_key_exists('angle', $options) ? (int) $options['angle'] : 0;

return new Rotate($angle);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Config/Filter/ScaleFactory.php
Expand Up @@ -38,7 +38,7 @@ public function getName(): string
public function create(array $options): FilterInterface
{
$dimensions = $this->sizeFactory->createFromOptions($options, 'dim');
$to = isset($options['to']) ? (float) $options['to'] : null;
$to = \array_key_exists('to', $options) ? (float) $options['to'] : null;

return new Scale($dimensions, $to);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Config/Filter/UpscaleFactory.php
Expand Up @@ -38,7 +38,7 @@ public function getName(): string
public function create(array $options): FilterInterface
{
$min = $this->sizeFactory->createFromOptions($options, 'min');
$by = isset($options['by']) ? (float) $options['by'] : null;
$by = \array_key_exists('by', $options) ? (float) $options['by'] : null;

return new Upscale($min, $by);
}
Expand Down
8 changes: 2 additions & 6 deletions src/Factory/Config/Filter/WatermarkFactory.php
Expand Up @@ -29,12 +29,8 @@ public function getName(): string

public function create(array $options): FilterInterface
{
$size = $options['size'] ?? null;
if (null !== $size) {
$size = (float) $size;
}

$position = isset($options['position']) ? $options['position'] : 'center';
$size = \array_key_exists('size', $options) ? (float) $options['size'] : null;
$position = $options['position'] ?? 'center';

return new Watermark($options['image'], $position, $size);
}
Expand Down
14 changes: 5 additions & 9 deletions src/Imagine/Cache/CacheManager.php
Expand Up @@ -194,7 +194,7 @@ public function remove($paths = null, $filters = null): void
foreach ($filters as $filter) {
$resolver = $this->getResolver($filter, null);

$list = isset($mapping[$resolver]) ? $mapping[$resolver] : [];
$list = $mapping[$resolver] ?? [];

$list[] = $filter;

Expand All @@ -213,18 +213,14 @@ public function remove($paths = null, $filters = null): void
*
* @throws \OutOfBoundsException If neither a specific nor a default resolver is available
*/
protected function getResolver(string $filter, ?string $resolver): ResolverInterface
protected function getResolver(string $filter, ?string $resolverName): ResolverInterface
{
// BC
if (!$resolver) {
if (!$resolverName) {
$config = $this->filterConfig->get($filter);

$resolverName = empty($config['cache']) ? $this->defaultResolver : $config['cache'];
} else {
$resolverName = $resolver;
$resolverName = $config['cache'] ?? $this->defaultResolver;
}

if (!isset($this->resolvers[$resolverName])) {
if (!\array_key_exists($resolverName, $this->resolvers)) {
throw new \OutOfBoundsException(sprintf('Could not find resolver "%s" for "%s" filter type', $resolverName, $filter));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Imagine/Data/DataManager.php
Expand Up @@ -69,7 +69,7 @@ public function getLoader(string $filter): LoaderInterface

$loaderName = empty($config['data_loader']) ? $this->defaultLoader : $config['data_loader'];

if (!isset($this->loaders[$loaderName])) {
if (!\array_key_exists($loaderName, $this->loaders)) {
throw new \InvalidArgumentException(sprintf('Could not find data loader "%s" for "%s" filter type', $loaderName, $filter));
}

Expand Down
10 changes: 5 additions & 5 deletions src/Imagine/Filter/FilterManager.php
Expand Up @@ -132,13 +132,13 @@ private function exportConfiguredImageBinary(BinaryInterface $binary, ImageInter
'quality' => $config['quality'],
];

if (isset($config['jpeg_quality'])) {
if (\array_key_exists('jpeg_quality', $config)) {
$options['jpeg_quality'] = $config['jpeg_quality'];
}
if (isset($config['png_compression_level'])) {
if (\array_key_exists('png_compression_level', $config)) {
$options['png_compression_level'] = $config['png_compression_level'];
}
if (isset($config['png_compression_filter'])) {
if (\array_key_exists('png_compression_filter', $config)) {
$options['png_compression_filter'] = $config['png_compression_filter'];
}

Expand Down Expand Up @@ -171,7 +171,7 @@ private function exportConfiguredImageBinary(BinaryInterface $binary, ImageInter
private function sanitizeFilters(array $filters): array
{
$sanitized = array_filter($filters, function (string $name): bool {
return isset($this->loaders[$name]);
return \array_key_exists($name, $this->loaders);
}, ARRAY_FILTER_USE_KEY);

if (\count($filters) !== \count($sanitized)) {
Expand All @@ -184,7 +184,7 @@ private function sanitizeFilters(array $filters): array
private function sanitizePostProcessors(array $processors): array
{
$sanitized = array_filter($processors, function (string $name): bool {
return isset($this->postProcessors[$name]);
return \array_key_exists($name, $this->postProcessors);
}, ARRAY_FILTER_USE_KEY);

if (\count($processors) !== \count($sanitized)) {
Expand Down
16 changes: 7 additions & 9 deletions src/Imagine/Filter/Loader/BackgroundFilterLoader.php
Expand Up @@ -28,17 +28,17 @@ public function __construct(ImagineInterface $imagine)
public function load(ImageInterface $image, array $options = []): ImageInterface
{
$background = $image->palette()->color(
isset($options['color']) ? $options['color'] : '#fff',
isset($options['transparency']) ? $options['transparency'] : null
$options['color'] ?? '#fff',
$options['transparency'] ?? null
);
$topLeft = new Point(0, 0);
$size = $image->getSize();

if (isset($options['size'])) {
$width = isset($options['size'][0]) ? $options['size'][0] : null;
$height = isset($options['size'][1]) ? $options['size'][1] : null;
if (\array_key_exists('size', $options)) {
$width = $options['size'][0] ?? null;
$height = $options['size'][1] ?? null;

$position = isset($options['position']) ? $options['position'] : 'center';
$position = $options['position'] ?? 'center';
switch ($position) {
case 'topleft':
$x = 0;
Expand Down Expand Up @@ -92,8 +92,6 @@ public function load(ImageInterface $image, array $options = []): ImageInterface
$topLeft = new Point($x, $y);
}

$canvas = $this->imagine->create($size, $background);

return $canvas->paste($image, $topLeft);
return $this->imagine->create($size, $background)->paste($image, $topLeft);
}
}
11 changes: 5 additions & 6 deletions src/Imagine/Filter/Loader/CropFilterLoader.php
Expand Up @@ -20,15 +20,14 @@ class CropFilterLoader implements LoaderInterface
{
public function load(ImageInterface $image, array $options = []): ImageInterface
{
$x = isset($options['start'][0]) ? $options['start'][0] : null;
$y = isset($options['start'][1]) ? $options['start'][1] : null;
$x = $options['start'][0] ?? null;
$y = $options['start'][1] ?? null;

$width = isset($options['size'][0]) ? $options['size'][0] : null;
$height = isset($options['size'][1]) ? $options['size'][1] : null;
$width = $options['size'][0] ?? null;
$height = $options['size'][1] ?? null;

$filter = new Crop(new Point($x, $y), new Box($width, $height));
$image = $filter->apply($image);

return $image;
return $filter->apply($image);
}
}
4 changes: 2 additions & 2 deletions src/Imagine/Filter/Loader/PasteFilterLoader.php
Expand Up @@ -32,8 +32,8 @@ public function __construct(ImagineInterface $imagine, string $projectDir)
*/
public function load(ImageInterface $image, array $options = []): ImageInterface
{
$x = isset($options['start'][0]) ? $options['start'][0] : null;
$y = isset($options['start'][1]) ? $options['start'][1] : null;
$x = $options['start'][0] ?? null;
$y = $options['start'][1] ?? null;

$destImage = $this->imagine->open($this->projectDir.'/'.$options['image']);

Expand Down
2 changes: 1 addition & 1 deletion src/Imagine/Filter/Loader/ResampleFilterLoader.php
Expand Up @@ -78,7 +78,7 @@ private function getImagineSaveOptions(array $options): array
'resolution-y' => $options['y'],
];

if (isset($options['filter'])) {
if (\array_key_exists('filter', $options)) {
$saveOptions['resampling-filter'] = $options['filter'];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Imagine/Filter/Loader/ResizeFilterLoader.php
Expand Up @@ -24,8 +24,8 @@ class ResizeFilterLoader implements LoaderInterface
{
public function load(ImageInterface $image, array $options = []): ImageInterface
{
$width = isset($options['size'][0]) ? $options['size'][0] : null;
$height = isset($options['size'][1]) ? $options['size'][1] : null;
$width = $options['size'][0] ?? null;
$height = $options['size'][1] ?? null;

$filter = new Resize(new Box($width, $height));

Expand Down
2 changes: 1 addition & 1 deletion src/Imagine/Filter/Loader/RotateFilterLoader.php
Expand Up @@ -22,7 +22,7 @@ class RotateFilterLoader implements LoaderInterface
{
public function load(ImageInterface $image, array $options = []): ImageInterface
{
$angle = isset($options['angle']) ? (int) $options['angle'] : 0;
$angle = \array_key_exists('angle', $options) ? (int) $options['angle'] : 0;

return 0 === $angle ? $image : $image->rotate($angle);
}
Expand Down
14 changes: 6 additions & 8 deletions src/Imagine/Filter/Loader/ScaleFilterLoader.php
Expand Up @@ -37,21 +37,17 @@ public function __construct(string $dimensionKey = 'dim', string $ratioKey = 'to

public function load(ImageInterface $image, array $options = []): ImageInterface
{
if (!isset($options[$this->dimensionKey]) && !isset($options[$this->ratioKey])) {
throw new \InvalidArgumentException("Missing $this->dimensionKey or $this->ratioKey option.");
}

$size = $image->getSize();
$origWidth = $size->getWidth();
$origHeight = $size->getHeight();
$ratio = 1;

if (isset($options[$this->ratioKey])) {
if (\array_key_exists($this->ratioKey, $options)) {
$ratio = $this->absoluteRatio ? $options[$this->ratioKey] : $this->calcAbsoluteRatio($options[$this->ratioKey]);
} elseif (isset($options[$this->dimensionKey])) {
} elseif (\array_key_exists($this->dimensionKey, $options)) {
$size = $options[$this->dimensionKey];
$width = isset($size[0]) ? $size[0] : null;
$height = isset($size[1]) ? $size[1] : null;
$width = $size[0] ?? null;
$height = $size[1] ?? null;

$widthRatio = $width / $origWidth;
$heightRatio = $height / $origHeight;
Expand All @@ -61,6 +57,8 @@ public function load(ImageInterface $image, array $options = []): ImageInterface
} else {
$ratio = ('min' === $this->dimensionKey) ? max($widthRatio, $heightRatio) : min($widthRatio, $heightRatio);
}
} else {
throw new \InvalidArgumentException("Missing $this->dimensionKey or $this->ratioKey option.");
}

if ($this->isImageProcessable($ratio)) {
Expand Down
6 changes: 3 additions & 3 deletions src/Imagine/Filter/Loader/ThumbnailFilterLoader.php
Expand Up @@ -25,14 +25,14 @@ public function load(ImageInterface $image, array $options = []): ImageInterface
}

if (!empty($options['filter'])) {
$filter = \constant('Imagine\Image\ImageInterface::FILTER_'.mb_strtoupper($options['filter']));
$filter = \constant(ImageInterface::class.'::FILTER_'.mb_strtoupper($options['filter']));
}
if (empty($filter)) {
$filter = ImageInterface::FILTER_UNDEFINED;
}

$width = isset($options['size'][0]) ? $options['size'][0] : null;
$height = isset($options['size'][1]) ? $options['size'][1] : null;
$width = $options['size'][0] ?? null;
$height = $options['size'][1] ?? null;

$size = $image->getSize();
$origWidth = $size->getWidth();
Expand Down
8 changes: 4 additions & 4 deletions src/Imagine/Filter/PostProcessor/AbstractPostProcessor.php
Expand Up @@ -36,19 +36,19 @@ protected function createProcess(array $arguments = [], array $options = []): Pr
{
$process = new Process($arguments);

if (!isset($options['process'])) {
if (!\array_key_exists('process', $options)) {
return $process;
}

if (isset($options['process']['timeout'])) {
if (\array_key_exists('timeout', $options['process'])) {
$process->setTimeout($options['process']['timeout']);
}

if (isset($options['process']['working_directory'])) {
if (\array_key_exists('working_directory', $options['process'])) {
$process->setWorkingDirectory($options['process']['working_directory']);
}

if (isset($options['process']['environment_variables']) && \is_array($options['process']['environment_variables'])) {
if (\array_key_exists('environment_variables', $options['process']) && \is_array($options['process']['environment_variables'])) {
$process->setEnv($options['process']['environment_variables']);
}

Expand Down

0 comments on commit 8e5b173

Please sign in to comment.