Skip to content

Commit

Permalink
Fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Sep 17, 2021
1 parent 0b5fa50 commit cf8e108
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Sulu\Twig\Extensions\ImageExtension:
$defaultAdditionalTypes:
webp: 'image/webp'
$aspectRatio: true
$imageFormatConfiguration: '%sulu_media.image.formats''
$imageFormatConfiguration: '%sulu_media.image.formats%'
```

## Usage
Expand Down Expand Up @@ -272,5 +272,5 @@ The feature will automatically add a width and height attribute to the rendered
```

The `$imageFormatConfiguration` parameter is optional. Without it will try to
guess the format by the given format key so it will then only work with format keys
guess the format by the given format key. It will then only work with format keys
like 100x, x100, 100x@2x, 100x100-inset and similars.
19 changes: 17 additions & 2 deletions src/ImageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,28 @@ class ImageExtension extends AbstractExtension
private $aspectRatio = false;

/**
* @var mixed[]|null
* @var array<string, array{
* scale: array{
* x: int|null,
* y: int|null,
* mode: int,
* retina: bool,
* },
* }>|null
*/
private $imageFormatConfiguration = null;

/**
* @param string[] $defaultAttributes
* @param string[] $defaultAdditionalTypes
* @param array<string, array{
* scale: array{
* x: int|null,
* y: int|null,
* mode: int,
* retina: bool,
* },
* }>|null $imageFormatConfiguration
*/
public function __construct(
?string $placeholderPath = null,
Expand Down Expand Up @@ -446,7 +461,7 @@ private function guessAspectRatio($media, array $attributes): array
$isInset = \in_array($this->imageFormatConfiguration[$src]['scale']['mode'], [
1,
'inset',
]);
], true);
$x = $this->imageFormatConfiguration[$src]['scale']['x'];
$y = $this->imageFormatConfiguration[$src]['scale']['y'];
$width = $x ? (int) round($x * $scale) : null;
Expand Down

0 comments on commit cf8e108

Please sign in to comment.