Skip to content

Commit

Permalink
Merge pull request #1611 from liip/2-to-3
Browse files Browse the repository at this point in the history
2 to 3
  • Loading branch information
dbu authored Sep 4, 2024
2 parents 342bbf2 + 08c39af commit 0b44562
Show file tree
Hide file tree
Showing 63 changed files with 165 additions and 163 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ for a given releases. Unreleased, upcoming changes will be updated here periodic

# 2.x

## [2.13.2](https://github.com/liip/LiipImagineBundle/tree/2.13.2)

- Remove deprecated spaceless filter from twig template ([JohJohan](https://github.com/liip/LiipImagineBundle/pull/1609))

## [2.13.1](https://github.com/liip/LiipImagineBundle/tree/2.13.1)

- Fix Json Manifest handling when manifest file does not exist yet ([AirBair](https://github.com/liip/LiipImagineBundle/pull/1600))
Expand Down
2 changes: 1 addition & 1 deletion src/Binary/Loader/AbstractDoctrineLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function find($path)
}

if (!$image) {
throw new NotLoadableException(sprintf('Source image was not found with id "%s"', $path));
throw new NotLoadableException(\sprintf('Source image was not found with id "%s"', $path));
}

return stream_get_contents($this->getStreamFromImage($image));
Expand Down
8 changes: 4 additions & 4 deletions src/Binary/Loader/ChainLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public function find($path)
*/
private static function getLoaderExceptionMessage(string $path, array $exceptions, array $loaders): string
{
$loaderMessages = array_map(static function (string $name, LoaderInterface $loader) {
return sprintf('%s=[%s]', (new \ReflectionObject($loader))->getShortName(), $name);
$loaderMessages = array_map(static function (string $name, LoaderInterface $loader): string {
return \sprintf('%s=[%s]', (new \ReflectionObject($loader))->getShortName(), $name);
}, array_keys($loaders), $loaders);

$exceptionMessages = array_map(static function (string $message, LoaderInterface $loader) {
return sprintf('%s=[%s]', (new \ReflectionObject($loader))->getShortName(), $message);
$exceptionMessages = array_map(static function (string $message, LoaderInterface $loader): string {
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).', [
Expand Down
2 changes: 1 addition & 1 deletion src/Binary/Loader/FileSystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FileSystemLoader implements LoaderInterface
public function __construct(
MimeTypeGuesserInterface $mimeGuesser,
MimeTypesInterface $extensionGuesser,
LocatorInterface $locator
LocatorInterface $locator,
) {
$this->mimeTypeGuesser = $mimeGuesser;
$this->extensionGuesser = $extensionGuesser;
Expand Down
2 changes: 1 addition & 1 deletion src/Binary/Loader/FlysystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
public function find($path)
{
if (false === $this->filesystem->has($path)) {
throw new NotLoadableException(sprintf('Source image "%s" not found.', $path));
throw new NotLoadableException(\sprintf('Source image "%s" not found.', $path));
}

$mimeType = $this->filesystem->getMimetype($path);
Expand Down
4 changes: 2 additions & 2 deletions src/Binary/Loader/FlysystemV2Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FlysystemV2Loader implements LoaderInterface

public function __construct(
MimeTypesInterface $extensionGuesser,
FilesystemOperator $filesystem
FilesystemOperator $filesystem,
) {
$this->extensionGuesser = $extensionGuesser;
$this->filesystem = $filesystem;
Expand All @@ -44,7 +44,7 @@ public function find($path)
$extension
);
} catch (FilesystemException $exception) {
throw new NotLoadableException(sprintf('Source image "%s" not found.', $path), 0, $exception);
throw new NotLoadableException(\sprintf('Source image "%s" not found.', $path), 0, $exception);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Binary/Loader/StreamLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function find($path)
* file_exists() is not used as not all wrappers support stat() to actually check for existing resources.
*/
if (($this->context && !$resource = @fopen($name, 'rb', false, $this->context)) || !$resource = @fopen($name, 'rb')) {
throw new NotLoadableException(sprintf('Source image %s not found.', $name));
throw new NotLoadableException(\sprintf('Source image %s not found.', $name));
}

// Closing the opened stream to avoid locking of the resource to find.
Expand All @@ -64,11 +64,11 @@ public function find($path)
try {
$content = file_get_contents($name, false, $this->context);
} catch (\Exception $e) {
throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $name), $e->getCode(), $e);
throw new NotLoadableException(\sprintf('Source image %s could not be loaded.', $name), $e->getCode(), $e);
}

if (false === $content) {
throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $name));
throw new NotLoadableException(\sprintf('Source image %s could not be loaded.', $name));
}

return $content;
Expand Down
10 changes: 5 additions & 5 deletions src/Binary/Locator/FileSystemLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function locate(string $path): string
return $this->sanitizeAbsolutePath($absolute);
}

throw new NotLoadableException(sprintf('Source image not resolvable "%s" in root path(s) "%s"', $path, implode(':', $this->roots)));
throw new NotLoadableException(\sprintf('Source image not resolvable "%s" in root path(s) "%s"', $path, implode(':', $this->roots)));
}

protected function generateAbsolutePath(string $root, string $path): ?string
Expand Down Expand Up @@ -77,7 +77,7 @@ private function locateUsingRootPlaceholder(string $path): ?string
return $this->generateAbsolutePath($this->roots[$match['name']], $match['path']);
}

throw new NotLoadableException(sprintf('Invalid root placeholder "@%s" for path "%s"', $match['name'], $match['path']));
throw new NotLoadableException(\sprintf('Invalid root placeholder "@%s" for path "%s"', $match['name'], $match['path']));
}

/**
Expand All @@ -93,7 +93,7 @@ private function sanitizeRootPath(string $path, bool $allowUnresolvable): ?strin
return null;
}

throw new InvalidArgumentException(sprintf('Root image path not resolvable "%s"', $path));
throw new InvalidArgumentException(\sprintf('Root image path not resolvable "%s"', $path));
}

/**
Expand All @@ -106,11 +106,11 @@ private function sanitizeAbsolutePath(string $path): string
});

if (0 === \count($roots)) {
throw new NotLoadableException(sprintf('Source image invalid "%s" as it is outside of the defined root path(s) "%s"', $path, implode(':', $this->roots)));
throw new NotLoadableException(\sprintf('Source image invalid "%s" as it is outside of the defined root path(s) "%s"', $path, implode(':', $this->roots)));
}

if (!is_readable($path)) {
throw new NotLoadableException(sprintf('Source image invalid "%s" as it is not readable', $path));
throw new NotLoadableException(\sprintf('Source image invalid "%s" as it is not readable', $path));
}

return $path;
Expand Down
2 changes: 1 addition & 1 deletion src/Binary/SimpleMimeTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(MimeTypesInterface $mimeTypeGuesser)
public function guess(string $binary): ?string
{
if (false === $tmpFile = tempnam(sys_get_temp_dir(), 'liip-imagine-bundle')) {
throw new \RuntimeException(sprintf('Temp file can not be created in "%s".', sys_get_temp_dir()));
throw new \RuntimeException(\sprintf('Temp file can not be created in "%s".', sys_get_temp_dir()));
}

try {
Expand Down
14 changes: 7 additions & 7 deletions src/Command/CacheCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,35 @@ private function outputCommandResult(array $images, array $filters, string $sing
{
if (!$this->outputMachineReadable) {
$wordPluralizer = function (int $count, string $singular) {
return 1 === $count ? $singular : sprintf('%ss', $singular);
return 1 === $count ? $singular : \sprintf('%ss', $singular);
};

$imagePathsSize = \count($images);
$filterSetsSize = \count($filters);
$allActionsSize = 0 === $imagePathsSize ? $filterSetsSize : ($filterSetsSize * $imagePathsSize) - $this->failures;
$allActionsWord = $wordPluralizer($allActionsSize, $singularAction);

$rootTextOutput = sprintf('Completed %d %s', $allActionsSize, $allActionsWord);
$rootTextOutput = \sprintf('Completed %d %s', $allActionsSize, $allActionsWord);

$detailTextFormat = '%d %s';

$detailTextsOutput = [];

if (0 !== $imagePathsSize) {
$detailTextsOutput[] = sprintf($detailTextFormat, $imagePathsSize, $wordPluralizer($imagePathsSize, 'image'));
$detailTextsOutput[] = \sprintf($detailTextFormat, $imagePathsSize, $wordPluralizer($imagePathsSize, 'image'));
}

if (0 !== $filterSetsSize) {
$detailTextsOutput[] = sprintf($detailTextFormat, $filterSetsSize, $wordPluralizer($filterSetsSize, 'filter'));
$detailTextsOutput[] = \sprintf($detailTextFormat, $filterSetsSize, $wordPluralizer($filterSetsSize, 'filter'));
}

if (!empty($detailTextsOutput)) {
$rootTextOutput = sprintf('%s (%s)', $rootTextOutput, implode(', ', $detailTextsOutput));
$rootTextOutput = \sprintf('%s (%s)', $rootTextOutput, implode(', ', $detailTextsOutput));
}

if ($this->failures) {
$this->io->critBlock(sprintf('%s %%s', $rootTextOutput), [
sprintf('[encountered %d failures]', $this->failures),
$this->io->critBlock(\sprintf('%s %%s', $rootTextOutput), [
\sprintf('[encountered %d failures]', $this->failures),
]);
} else {
$this->io->okayBlock($rootTextOutput);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ResolveCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function runCacheImageResolve(string $image, string $filter, bool $force
$this->io->status('cached', 'white');
}

$this->io->line(sprintf(' %s', $this->cacheManager->resolve($image, $filter)));
$this->io->line(\sprintf(' %s', $this->cacheManager->resolve($image, $filter)));
} catch (\Exception $e) {
++$this->failures;

Expand Down
8 changes: 4 additions & 4 deletions src/Component/Console/Style/ImagineStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public function newline(int $count = 1): self
public function status(string $status, ?string $fg = null): self
{
return $this->text(
sprintf('<fg=%2$s>(</><fg=%2$s;options=bold>%1$s</><fg=%2$s>)</>', $status, $fg ?: 'default')
\sprintf('<fg=%2$s>(</><fg=%2$s;options=bold>%1$s</><fg=%2$s>)</>', $status, $fg ?: 'default')
);
}

public function group(string $item, string $group, ?string $fg = null): self
{
$this->text(
sprintf('<fg=%3$s;options=bold>%1$s[</><fg=%3$s>%2$s</><fg=%3$s;options=bold>]</>', $item, $group, $fg ?: 'default')
\sprintf('<fg=%3$s;options=bold>%1$s[</><fg=%3$s>%2$s</><fg=%3$s;options=bold>]</>', $item, $group, $fg ?: 'default')
);

return $this->space();
Expand Down Expand Up @@ -116,7 +116,7 @@ private function block(string $string, ?string $type = null, ?string $fg = null,
return $this->plainBlock($string, $type);
}

$this->io->block($string, $type, sprintf('fg=%s;bg=%s', $fg ?: 'default', $bg ?: 'default'), $prefix ? sprintf(' %s ', $prefix) : ' ', $padding);
$this->io->block($string, $type, \sprintf('fg=%s;bg=%s', $fg ?: 'default', $bg ?: 'default'), $prefix ? \sprintf(' %s ', $prefix) : ' ', $padding);

return $this;
}
Expand Down Expand Up @@ -146,6 +146,6 @@ private function compileString(string $format, array $replacements = []): string
} catch (\ValueError $error) {
}

throw new InvalidArgumentException(sprintf('Invalid string format "%s" or replacements "%s".', $format, implode(', ', array_map(function ($replacement) { return var_export($replacement, true); }, $replacements))));
throw new InvalidArgumentException(\sprintf('Invalid string format "%s" or replacements "%s".', $format, implode(', ', array_map(function ($replacement) { return var_export($replacement, true); }, $replacements))));
}
}
2 changes: 1 addition & 1 deletion src/Config/Controller/ControllerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ControllerConfig
public function __construct(int $redirectResponseCode)
{
if (!\in_array($redirectResponseCode, self::REDIRECT_RESPONSE_CODES, true)) {
throw new InvalidArgumentException(sprintf('Invalid redirect response code "%s" (must be 201, 301, 302, 303, 307, or 308).', $redirectResponseCode));
throw new InvalidArgumentException(\sprintf('Invalid redirect response code "%s" (must be 201, 301, 302, 303, 307, or 308).', $redirectResponseCode));
}

$this->redirectResponseCode = $redirectResponseCode;
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Filter/Type/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
?string $color,
?string $transparency,
?string $position,
Size $size
Size $size,
) {
$this->color = $color;
$this->transparency = $transparency;
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Filter/Type/RelativeResize.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
?float $heighten = null,
?float $widen = null,
?float $increase = null,
?float $scale = null
?float $scale = null,
) {
$this->heighten = $heighten;
$this->widen = $widen;
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Filter/Type/Thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
Size $size,
?string $mode = null,
?bool $allowUpscale = null,
?string $filter = null
?string $filter = null,
) {
$this->size = $size;
$this->mode = $mode;
Expand Down
2 changes: 1 addition & 1 deletion src/Config/FilterFactoryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(FilterFactoryInterface ...$filterFactories)
public function getFilterFactoryByName(string $name): FilterFactoryInterface
{
if (!\array_key_exists($name, $this->filterFactories)) {
throw new NotFoundException(sprintf("Filter factory with name '%s' was not found.", $name));
throw new NotFoundException(\sprintf("Filter factory with name '%s' was not found.", $name));
}

return $this->filterFactories[$name];
Expand Down
10 changes: 5 additions & 5 deletions src/Controller/ImagineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
FilterService $filterService,
DataManager $dataManager,
SignerInterface $signer,
?ControllerConfig $controllerConfig
ControllerConfig $controllerConfig,
) {
$this->filterService = $filterService;
$this->dataManager = $dataManager;
Expand Down Expand Up @@ -89,7 +89,7 @@ public function filterRuntimeAction(Request $request, string $hash, string $path
$runtimeConfig = $request->query->all('filters');

if (true !== $this->signer->check($hash, $path, $runtimeConfig)) {
throw new BadRequestHttpException(sprintf('Signed url does not pass the sign check for path "%s" and filter "%s" and runtime config %s', $path, $filter, json_encode($runtimeConfig)));
throw new BadRequestHttpException(\sprintf('Signed url does not pass the sign check for path "%s" and filter "%s" and runtime config %s', $path, $filter, json_encode($runtimeConfig)));
}

return $this->createRedirectResponse(function () use ($path, $filter, $runtimeConfig, $resolver, $request) {
Expand All @@ -112,11 +112,11 @@ private function createRedirectResponse(\Closure $url, string $path, string $fil
return new RedirectResponse($this->dataManager->getDefaultImageUrl($filter));
}

throw new NotFoundHttpException(sprintf('Source image for path "%s" could not be found', $path), $exception);
throw new NotFoundHttpException(\sprintf('Source image for path "%s" could not be found', $path), $exception);
} catch (NonExistingFilterException $exception) {
throw new NotFoundHttpException(sprintf('Requested non-existing filter "%s"', $filter), $exception);
throw new NotFoundHttpException(\sprintf('Requested non-existing filter "%s"', $filter), $exception);
} catch (RuntimeException $exception) {
throw new \RuntimeException(vsprintf('Unable to create image for path "%s" and filter "%s". Message was "%s"', [$hash ? sprintf('%s/%s', $hash, $path) : $path, $filter, $exception->getMessage()]), 0, $exception);
throw new \RuntimeException(vsprintf('Unable to create image for path "%s" and filter "%s". Message was "%s"', [$hash ? \sprintf('%s/%s', $hash, $path) : $path, $filter, $exception->getMessage()]), 0, $exception);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/AbstractCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class AbstractCompilerPass implements CompilerPassInterface
*/
protected function log(ContainerBuilder $container, string $message, ...$replacements): void
{
$container->log($this, sprintf(
$container->log($this, \sprintf(
'[liip/imagine-bundle] %s', empty($replacements) ? $message : vsprintf($message, $replacements)
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/DriverCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function process(ContainerBuilder $container): void
$liipImagineDriver = $container->getParameter('liip_imagine.driver_service');

if (!$container->hasDefinition($liipImagineDriver)) {
throw new InvalidConfigurationException(sprintf("Specified driver '%s' is not defined.", $liipImagineDriver));
throw new InvalidConfigurationException(\sprintf("Specified driver '%s' is not defined.", $liipImagineDriver));
}
}
}
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public function getConfigTreeBuilder(): TreeBuilder
->arrayNode('controller')
->addDefaultsIfNotSet()
->children()
->scalarNode('filter_action')->defaultValue(sprintf('%s::filterAction', ImagineController::class))->end()
->scalarNode('filter_runtime_action')->defaultValue(sprintf('%s::filterRuntimeAction', ImagineController::class))->end()
->scalarNode('filter_action')->defaultValue(\sprintf('%s::filterAction', ImagineController::class))->end()
->scalarNode('filter_runtime_action')->defaultValue(\sprintf('%s::filterRuntimeAction', ImagineController::class))->end()
->integerNode('redirect_response_code')->defaultValue(302)
->validate()
->ifTrue(function ($redirectResponseCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class AbstractLoaderFactory implements LoaderFactoryInterface

final protected function getChildLoaderDefinition(?string $name = null): ChildDefinition
{
return new ChildDefinition(sprintf('%s.prototype.%s', static::$namePrefix, $name ?: $this->getName()));
return new ChildDefinition(\sprintf('%s.prototype.%s', static::$namePrefix, $name ?: $this->getName()));
}

final protected function setTaggedLoaderDefinition(string $name, Definition $definition, ContainerBuilder $container): string
Expand All @@ -33,7 +33,7 @@ final protected function setTaggedLoaderDefinition(string $name, Definition $def
$definition->setPublic(true);

$container->setDefinition(
$id = sprintf('%s.%s', static::$namePrefix, $name),
$id = \sprintf('%s.%s', static::$namePrefix, $name),
$definition
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function addConfiguration(ArrayNodeDefinition $builder): void
private function createLoaderReferences(array $loaders): array
{
return array_combine($loaders, array_map(function (string $name): Reference {
return new Reference(sprintf('liip_imagine.binary.loader.%s', $name));
return new Reference(\sprintf('liip_imagine.binary.loader.%s', $name));
}, $loaders));
}
}
Loading

0 comments on commit 0b44562

Please sign in to comment.