Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c38e95b
Added missing type hints to classes in `Imagine\Cache` namespace
alongosz Jul 16, 2025
85cad42
Added missing type hints to `Imagine\Filter\FilterInterface` and its …
alongosz Jul 16, 2025
b58bb98
Added missing type hints Imagine Filter Loaders
alongosz Jul 16, 2025
f26b7a6
Added missing type hints to VariationHandler contract and its impleme…
alongosz Jul 16, 2025
39aef6e
Added missing type hints to PlaceholderProvider implementation
alongosz Jul 16, 2025
67ae896
Added missing type hints to Image alias cleaners
alongosz Jul 16, 2025
51bef0c
Added missing type hints to MVC\Symfony\Templating\Twig\Extension\Ima…
alongosz Jul 16, 2025
1753545
[Tests] Refactored Imagine\Cache ProxyResolverTest to use data provider
alongosz Jul 16, 2025
3ff8d77
[Tests] Added missing type hints to `Imagine\Cache` Resolver tests
alongosz Jul 16, 2025
122d372
[Tests] Added missing type hints and refactored Filter Loader tests
alongosz Jul 16, 2025
2157c06
[Tests] Added missing type hints to Imagine AliasCleanerTest
alongosz Jul 16, 2025
d56c9a2
[Tests] Added missing type hints to PlaceholderAlias tests
alongosz Jul 16, 2025
a7d14be
[Tests] Added missing type hints & refactored Placeholder provider tests
alongosz Jul 16, 2025
0b5d9bc
[Tests] Added missing type hints to ImageAsset AliasGeneratorTest
alongosz Jul 16, 2025
01b4c1d
[Tests] Added missing type hints to VariationPathGenerator tests
alongosz Jul 16, 2025
c2dbad9
[Tests] Added missing type hints and refactored AliasGeneratorTest
alongosz Jul 16, 2025
41eeb17
[Tests] Added missing type hints to BinaryLoaderTest
alongosz Jul 16, 2025
5a1342f
[PHPStan] Removed resolved issues from the baseline
alongosz Jul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,038 changes: 0 additions & 1,038 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/bundle/Core/Imagine/AliasCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine;

Expand All @@ -12,15 +13,14 @@

class AliasCleaner implements AliasCleanerInterface
{
/** @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */
private $aliasResolver;
private ResolverInterface $aliasResolver;

public function __construct(ResolverInterface $aliasResolver)
{
$this->aliasResolver = $aliasResolver;
}

public function removeAliases($originalPath)
public function removeAliases(string $originalPath): void
{
$this->aliasResolver->remove([$originalPath], []);
}
Expand Down
53 changes: 25 additions & 28 deletions src/bundle/Core/Imagine/AliasGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine;

use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
use Ibexa\Contracts\Core\FieldType\Value;
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidVariationException;
use Ibexa\Contracts\Core\Repository\Values\Content\Field;
Expand All @@ -17,7 +19,6 @@
use Ibexa\Core\FieldType\Image\Value as ImageValue;
use Ibexa\Core\MVC\Exception\SourceImageNotFoundException;
use Imagine\Exception\RuntimeException;
use InvalidArgumentException;
use Liip\ImagineBundle\Binary\BinaryInterface;
use Liip\ImagineBundle\Binary\Loader\LoaderInterface;
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
Expand All @@ -35,27 +36,21 @@
*/
class AliasGenerator implements VariationHandler
{
public const ALIAS_ORIGINAL = 'original';
public const string ALIAS_ORIGINAL = 'original';

/** @var \Psr\Log\LoggerInterface */
private $logger;
private LoggerInterface $logger;

/**
* Loader used to retrieve the original image.
* DataManager is not used to remain independent from ImagineBundle configuration.
*
* @var \Liip\ImagineBundle\Binary\Loader\LoaderInterface
*/
private $dataLoader;
private LoaderInterface $dataLoader;

/** @var \Liip\ImagineBundle\Imagine\Filter\FilterManager */
private $filterManager;
private FilterManager $filterManager;

/** @var \Liip\ImagineBundle\Imagine\Filter\FilterConfiguration */
private $filterConfiguration;
private FilterConfiguration $filterConfiguration;

/** @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */
private $ioResolver;
private ResolverInterface $ioResolver;

public function __construct(
LoaderInterface $dataLoader,
Expand All @@ -68,24 +63,20 @@ public function __construct(
$this->filterManager = $filterManager;
$this->ioResolver = $ioResolver;
$this->filterConfiguration = $filterConfiguration;
$this->logger = null !== $logger ? $logger : new NullLogger();
$this->logger = $logger ?? new NullLogger();
}

/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException If field value is not an instance of {@see \Ibexa\Core\FieldType\Image\Value}.
* @throws \Ibexa\Core\MVC\Exception\SourceImageNotFoundException If source image cannot be found.
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidVariationException If a problem occurs with generated variation.
*/
public function getVariation(Field $field, VersionInfo $versionInfo, string $variationName, array $parameters = []): Variation
{
/** @var \Ibexa\Core\FieldType\Image\Value $imageValue */
$imageValue = $field->value;
$fieldId = $field->id;
$fieldDefIdentifier = $field->fieldDefIdentifier;
if (!$this->supportsValue($imageValue)) {
throw new InvalidArgumentException("Value of Field with ID $fieldId ($fieldDefIdentifier) cannot be used for generating an image variation.");
throw new InvalidArgumentException(
'$field',
"Value of Field with ID $fieldId ($fieldDefIdentifier) cannot be used for generating an image variation."
);
}

$originalPath = $imageValue->id;
Expand All @@ -98,6 +89,17 @@ public function getVariation(Field $field, VersionInfo $versionInfo, string $var
} catch (NotLoadableException $e) {
throw new SourceImageNotFoundException((string)$originalPath, 0, $e);
}
if (!$originalBinary instanceof BinaryInterface) {
throw new InvalidArgumentException(
'$field',
sprintf(
'Data loader for \'%s\' path loaded %s instead of %s',
$originalPath,
get_debug_type($originalBinary),
BinaryInterface::class
)
);
}

$this->logger->debug("Generating '$variationName' variation on $originalPath, field #$fieldId ($fieldDefIdentifier)");

Expand Down Expand Up @@ -145,13 +147,8 @@ public function getVariation(Field $field, VersionInfo $versionInfo, string $var
* An Ibexa variation may have a "reference".
* In that case, reference's filters are applied first, recursively (a reference may also have another reference).
* Reference must be a valid variation name, configured in Ibexa or in LiipImagineBundle.
*
* @param \Liip\ImagineBundle\Binary\BinaryInterface $image
* @param string $variationName
*
* @return \Liip\ImagineBundle\Binary\BinaryInterface
*/
private function applyFilter(BinaryInterface $image, $variationName)
private function applyFilter(BinaryInterface $image, string $variationName): BinaryInterface
{
$filterConfig = $this->filterConfiguration->get($variationName);
// If the variation has a reference, we recursively call this method to apply reference's filters.
Expand Down
16 changes: 7 additions & 9 deletions src/bundle/Core/Imagine/BinaryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine;

use Exception;
use Ibexa\Core\IO\Exception\InvalidBinaryFileIdException;
use Ibexa\Core\IO\IOServiceInterface;
use Ibexa\Core\IO\Values\MissingBinaryFile;
use Liip\ImagineBundle\Binary\BinaryInterface;
use Liip\ImagineBundle\Binary\Loader\LoaderInterface;
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
use Liip\ImagineBundle\Model\Binary;
Expand All @@ -22,11 +24,9 @@
*/
class BinaryLoader implements LoaderInterface
{
/** @var \Ibexa\Core\IO\IOServiceInterface */
private $ioService;
private IOServiceInterface $ioService;

/** @var \Symfony\Component\Mime\MimeTypesInterface */
private $mimeTypes;
private MimeTypesInterface $mimeTypes;

public function __construct(IOServiceInterface $ioService, MimeTypesInterface $mimeTypes)
{
Expand All @@ -36,10 +36,8 @@ public function __construct(IOServiceInterface $ioService, MimeTypesInterface $m

/**
* @param string $path
*
* @return \Liip\ImagineBundle\Binary\BinaryInterface
*/
public function find($path)
public function find($path): BinaryInterface
{
try {
$binaryFile = $this->ioService->loadBinaryFile($path);
Expand All @@ -52,8 +50,8 @@ public function find($path)

return new Binary(
$this->ioService->getFileContents($binaryFile),
$mimeType,
$this->mimeTypes->getExtensions($mimeType)[0] ?? null
$mimeType ?? '',
$this->mimeTypes->getExtensions($mimeType ?? '')[0] ?? null
);
} catch (InvalidBinaryFileIdException $e) {
$message =
Expand Down
70 changes: 31 additions & 39 deletions src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine\Cache;

Expand All @@ -22,35 +23,24 @@
*/
class AliasGeneratorDecorator implements VariationHandler, SiteAccessAware
{
private const IMAGE_VARIATION_IDENTIFIER = 'image_variation';
private const IMAGE_VARIATION_SITEACCESS_IDENTIFIER = 'image_variation_siteaccess';
private const IMAGE_VARIATION_CONTENT_IDENTIFIER = 'image_variation_content';
private const IMAGE_VARIATION_FIELD_IDENTIFIER = 'image_variation_field';
private const IMAGE_VARIATION_NAME_IDENTIFIER = 'image_variation_name';
private const CONTENT_IDENTIFIER = 'content';
private const CONTENT_VERSION_IDENTIFIER = 'content_version';
private const string IMAGE_VARIATION_IDENTIFIER = 'image_variation';
private const string IMAGE_VARIATION_SITEACCESS_IDENTIFIER = 'image_variation_siteaccess';
private const string IMAGE_VARIATION_CONTENT_IDENTIFIER = 'image_variation_content';
private const string IMAGE_VARIATION_FIELD_IDENTIFIER = 'image_variation_field';
private const string IMAGE_VARIATION_NAME_IDENTIFIER = 'image_variation_name';
private const string CONTENT_IDENTIFIER = 'content';
private const string CONTENT_VERSION_IDENTIFIER = 'content_version';

/** @var \Ibexa\Contracts\Core\Variation\VariationHandler */
private $aliasGenerator;
private VariationHandler $aliasGenerator;

/** @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface */
private $cache;
private TagAwareAdapterInterface $cache;

/** @var \Ibexa\Core\MVC\Symfony\SiteAccess */
private $siteAccess;
private ?SiteAccess $siteAccess = null;

/** @var \Symfony\Component\Routing\RequestContext */
private $requestContext;
private RequestContext $requestContext;

/** @var \Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface */
private $cacheIdentifierGenerator;
private CacheIdentifierGeneratorInterface $cacheIdentifierGenerator;

/**
* @param \Ibexa\Contracts\Core\Variation\VariationHandler $aliasGenerator
* @param \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface $cache
* @param \Symfony\Component\Routing\RequestContext $requestContext
* @param \Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface $cacheIdentifierGenerator
*/
public function __construct(
VariationHandler $aliasGenerator,
TagAwareAdapterInterface $cache,
Expand All @@ -64,17 +54,18 @@ public function __construct(
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Field $field
* @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo
* @param string $variationName
* @param array $parameters
*
* @return \Ibexa\Contracts\Core\Variation\Values\Variation
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
* @throws \Psr\Cache\CacheException
* @throws \Psr\Cache\InvalidArgumentException
*/
public function getVariation(Field $field, VersionInfo $versionInfo, string $variationName, array $parameters = []): Variation
{
public function getVariation(
Field $field,
VersionInfo $versionInfo,
string $variationName,
array $parameters = []
): Variation {
$item = $this->cache->getItem($this->getCacheKey($field, $versionInfo, $variationName));
$image = $item->get();
if (!$item->isHit()) {
Expand All @@ -90,19 +81,15 @@ public function getVariation(Field $field, VersionInfo $versionInfo, string $var
/**
* @param \Ibexa\Core\MVC\Symfony\SiteAccess|null $siteAccess
*/
public function setSiteAccess(SiteAccess $siteAccess = null)
public function setSiteAccess(?SiteAccess $siteAccess = null): void
{
$this->siteAccess = $siteAccess;
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Field $field
* @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo
* @param string $variationName
*
* @return string
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
private function getCacheKey(Field $field, VersionInfo $versionInfo, $variationName): string
private function getCacheKey(Field $field, VersionInfo $versionInfo, string $variationName): string
{
return sprintf(
$this->cacheIdentifierGenerator->generateKey(self::IMAGE_VARIATION_IDENTIFIER, [], true) . '-%s-%s-%s-%d-%d-%d-%s-%s',
Expand All @@ -117,6 +104,11 @@ private function getCacheKey(Field $field, VersionInfo $versionInfo, $variationN
);
}

/**
* @return string[]
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
private function getTagsForVariation(Field $field, VersionInfo $versionInfo, string $variationName): array
{
$contentId = $versionInfo->getContentInfo()->id;
Expand Down
9 changes: 5 additions & 4 deletions src/bundle/Core/Imagine/Cache/Resolver/ProxyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine\Cache\Resolver;

Expand All @@ -14,14 +15,14 @@ class ProxyResolver extends ImagineProxyResolver
/**
* Replaces host with given proxy host.
*
* The original method from Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver:rewriteUrl()
* The original method from `\Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver::rewriteUrl()`
* doesn't behave correctly when working with domain and port or with host which contains trailing slash.
*
* @param string $url
* @see \Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver::rewriteUrl
*
* @return string
* @param string $url
*/
protected function rewriteUrl($url)
protected function rewriteUrl($url): string
{
if (empty($this->hosts)) {
return $url;
Expand Down
8 changes: 2 additions & 6 deletions src/bundle/Core/Imagine/Cache/Resolver/RelativeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine\Cache\Resolver;

Expand All @@ -15,9 +16,6 @@
*/
class RelativeResolver extends ImagineProxyResolver
{
/**
* @param \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface $resolver
*/
public function __construct(ResolverInterface $resolver)
{
parent::__construct($resolver, []);
Expand All @@ -27,10 +25,8 @@ public function __construct(ResolverInterface $resolver)
* Returns relative image path.
*
* @param $url string
*
* @return string
*/
protected function rewriteUrl($url)
protected function rewriteUrl($url): string
{
return parse_url($url, PHP_URL_PATH);
}
Expand Down
Loading
Loading