Skip to content

Commit

Permalink
Add type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Nov 11, 2021
1 parent f95f788 commit f3f5a91
Show file tree
Hide file tree
Showing 46 changed files with 126 additions and 369 deletions.
2 changes: 2 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ been removed.

- __[BC BREAK]__ Argument 4 of `ImagineController` is a mandatory instance of `ControllerConfig`

- __[BC BREAK]__ Argument 2 of `AbstractDoctrineLoader` is mandatory now, you MUST pass the model class name.

## 2.3.0 - 2.7.0

- __[Deprecated]__ As `doctrine/cache` has been deprecated, the `Liip\ImagineBundle\Imagine\Resolver\CacheResolver`
Expand Down
15 changes: 3 additions & 12 deletions src/Binary/BinaryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,9 @@

interface BinaryInterface
{
/**
* @return string
*/
public function getContent();
public function getContent(): string;

/**
* @return string
*/
public function getMimeType();
public function getMimeType(): ?string;

/**
* @return string
*/
public function getFormat();
public function getFormat(): ?string;
}
5 changes: 1 addition & 4 deletions src/Binary/FileBinaryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@

interface FileBinaryInterface extends BinaryInterface
{
/**
* @return string
*/
public function getPath();
public function getPath(): string;
}
33 changes: 9 additions & 24 deletions src/Binary/Loader/AbstractDoctrineLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,34 @@

namespace Liip\ImagineBundle\Binary\Loader;

use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Persistence\ObjectManager;
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;

abstract class AbstractDoctrineLoader implements LoaderInterface
{
/**
* @var ObjectManager|LegacyObjectManager
*/
protected $manager;
protected ObjectManager $manager;

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

/**
* @param ObjectManager|LegacyObjectManager $manager
* @param string $class
*/
public function __construct($manager, $class = null)
public function __construct(ObjectManager $manager, string $modelClass)
{
$this->manager = $manager;
$this->class = $class;
$this->modelClass = $modelClass;
}

/**
* {@inheritdoc}
*/
public function find($path)
{
$image = $this->manager->find($this->class, $this->mapPathToId($path));
$image = $this->manager->find($this->modelClass, $this->mapPathToId($path));

if (!$image) {
// try to find the image without extension
$info = pathinfo($path);
$name = $info['dirname'].'/'.$info['filename'];

$image = $this->manager->find($this->class, $this->mapPathToId($name));
$image = $this->manager->find($this->modelClass, $this->mapPathToId($name));
}

if (!$image) {
Expand All @@ -62,18 +51,14 @@ public function find($path)
/**
* Map the requested path (ie. subpath in the URL) to an id that can be used to lookup the image in the Doctrine store.
*
* @param string $path
*
* @return string
* @return string|int
*/
abstract protected function mapPathToId($path);
abstract protected function mapPathToId(string $path);

/**
* Return a stream resource from the Doctrine entity/document with the image content.
*
* @param object $image
*
* @return resource
*/
abstract protected function getStreamFromImage($image);
abstract protected function getStreamFromImage(object $image);
}
2 changes: 1 addition & 1 deletion src/Binary/Loader/ChainLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ChainLoader implements LoaderInterface
/**
* @var LoaderInterface[]
*/
private $loaders;
private array $loaders;

/**
* @param LoaderInterface[] $loaders
Expand Down
15 changes: 3 additions & 12 deletions src/Binary/Loader/FileSystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,11 @@

class FileSystemLoader implements LoaderInterface
{
/**
* @var MimeTypeGuesserInterface
*/
protected $mimeTypeGuesser;
protected MimeTypeGuesserInterface $mimeTypeGuesser;

/**
* @var MimeTypesInterface
*/
protected $extensionGuesser;
protected MimeTypesInterface $extensionGuesser;

/**
* @var LocatorInterface
*/
protected $locator;
protected LocatorInterface $locator;

public function __construct(
MimeTypeGuesserInterface $mimeGuesser,
Expand Down
10 changes: 2 additions & 8 deletions src/Binary/Loader/FlysystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@

class FlysystemLoader implements LoaderInterface
{
/**
* @var FilesystemInterface
*/
protected $filesystem;
protected FilesystemInterface $filesystem;

/**
* @var MimeTypesInterface
*/
protected $extensionGuesser;
protected MimeTypesInterface $extensionGuesser;

public function __construct(
MimeTypesInterface $extensionGuesser,
Expand Down
10 changes: 2 additions & 8 deletions src/Binary/Loader/FlysystemV2Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@

class FlysystemV2Loader implements LoaderInterface
{
/**
* @var FilesystemOperator
*/
protected $filesystem;
protected FilesystemOperator $filesystem;

/**
* @var MimeTypesInterface
*/
protected $extensionGuesser;
protected MimeTypesInterface $extensionGuesser;

public function __construct(
MimeTypesInterface $extensionGuesser,
Expand Down
7 changes: 2 additions & 5 deletions src/Binary/Loader/StreamLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class StreamLoader implements LoaderInterface
{
/**
* The wrapper prefix to append to the path to be loaded.
*
* @var string
*/
protected $wrapperPrefix;
protected string $wrapperPrefix;

/**
* A stream context resource to use.
Expand All @@ -30,12 +28,11 @@ class StreamLoader implements LoaderInterface
protected $context;

/**
* @param string $wrapperPrefix
* @param resource|null $context
*
* @throws \InvalidArgumentException
*/
public function __construct($wrapperPrefix, $context = null)
public function __construct(string $wrapperPrefix, $context = null)
{
$this->wrapperPrefix = $wrapperPrefix;

Expand Down
2 changes: 1 addition & 1 deletion src/Binary/Locator/FileSystemLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FileSystemLocator implements LocatorInterface
/**
* @var string[]
*/
private $roots = [];
private array $roots = [];

/**
* @param string[] $roots
Expand Down
2 changes: 1 addition & 1 deletion src/Binary/MimeTypeGuesserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ interface MimeTypeGuesserInterface
*
* @return string|null mime type or null if it could be not be guessed
*/
public function guess($binary);
public function guess(string $binary): ?string;
}
7 changes: 2 additions & 5 deletions src/Binary/SimpleMimeTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

class SimpleMimeTypeGuesser implements MimeTypeGuesserInterface
{
/**
* @var MimeTypesInterface
*/
protected $mimeTypeGuesser;
protected MimeTypesInterface $mimeTypeGuesser;

public function __construct(MimeTypesInterface $mimeTypeGuesser)
{
Expand All @@ -28,7 +25,7 @@ public function __construct(MimeTypesInterface $mimeTypeGuesser)
/**
* {@inheritdoc}
*/
public function guess($binary)
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()));
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Controller/ControllerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class ControllerConfig
{
public const REDIRECT_RESPONSE_CODES = [201, 301, 302, 303, 307, 308];

private $redirectResponseCode;
private int $redirectResponseCode;

public function __construct(int $redirectResponseCode)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Config/Filter/Argument/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@
*/
final class Point
{
/**
* @var int
*/
private $x;
private ?int $x;

/**
* @var int
*/
private $y;
private ?int $y;

public function __construct(int $x = null, int $y = null)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Config/Filter/Argument/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@
*/
final class Size
{
/**
* @var int
*/
private $width;
private ?int $width;

/**
* @var int
*/
private $height;
private ?int $height;

/**
* To allow keeping aspect ratio, it is allowed to only specify one of width or height.
Expand Down
26 changes: 7 additions & 19 deletions src/Config/Filter/Type/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,23 @@ final class Background extends FilterAbstract
{
public const NAME = 'background';

/**
* @var string
*/
private $color;
private ?string $color;

/**
* @var string
*/
private $transparency;
private ?string $transparency;

/**
* @var string
*/
private $position;
private ?string $position;

/**
* @var Size
*/
private $size;
private Size $size;

/**
* @param string|null $color background color HEX value
* @param string|null $transparency possible values 0..100
* @param string|null $position position of the input image on the newly created background image. Valid values: topleft, top, topright, left, center, right, bottomleft, bottom, and bottomright
*/
public function __construct(
string $color = null,
string $transparency = null,
string $position = null,
?string $color,
?string $transparency,
?string $position,
Size $size
) {
$this->color = $color;
Expand Down
12 changes: 3 additions & 9 deletions src/Config/Filter/Type/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ final class Crop extends FilterAbstract
{
public const NAME = 'crop';

/**
* @var Point
*/
private $startPoint;

/**
* @var Size
*/
private $size;
private Point $startPoint;

private Size $size;

public function __construct(Point $startPoint, Size $size)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Config/Filter/Type/Downscale.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ final class Downscale extends FilterAbstract
{
public const NAME = 'downscale';

/**
* @var Size
*/
private $max;
private ?Size $max;

/**
* @var float
*/
private $by;
private ?float $by;

/**
* @param float|null $by sets the "ratio multiple" which initiates a proportional scale operation computed by multiplying all image sides by this value
Expand Down
5 changes: 1 addition & 4 deletions src/Config/Filter/Type/Flip.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ final class Flip extends FilterAbstract
{
public const NAME = 'flip';

/**
* @var string
*/
private $axis;
private string $axis;

/**
* @param string $axis possible values are: "x", "horizontal", "y", or "vertical"
Expand Down
5 changes: 1 addition & 4 deletions src/Config/Filter/Type/Interlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ final class Interlace extends FilterAbstract
{
public const NAME = 'interlace';

/**
* @var string
*/
private $mode;
private string $mode;

public function __construct(string $mode)
{
Expand Down
Loading

0 comments on commit f3f5a91

Please sign in to comment.