1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-13 09:24:05 +02:00

Change typehints

Change the typing. “callable” is too general, as classes are also
included here. “Closure” is actually sufficient, but “callable” was left
in the outer interface so as not to create a breaking change. In the
underlying factories, however, only “Closure” is still possible.
This commit is contained in:
Oliver Vogel
2024-06-09 11:59:28 +02:00
parent 36ca199d1b
commit 27512eedb3
10 changed files with 54 additions and 43 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories; namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Bezier; use Intervention\Image\Geometry\Bezier;
use Intervention\Image\Interfaces\DrawableFactoryInterface; use Intervention\Image\Interfaces\DrawableFactoryInterface;
@@ -16,10 +17,10 @@ class BezierFactory implements DrawableFactoryInterface
/** /**
* Create new factory instance * Create new factory instance
* *
* @param null|callable|Bezier $init * @param null|Closure|Bezier $init
* @return void * @return void
*/ */
public function __construct(null|callable|Bezier $init = null) public function __construct(null|Closure|Bezier $init = null)
{ {
$this->bezier = is_a($init, Bezier::class) ? $init : new Bezier([]); $this->bezier = is_a($init, Bezier::class) ? $init : new Bezier([]);
@@ -33,7 +34,7 @@ class BezierFactory implements DrawableFactoryInterface
* *
* @see DrawableFactoryInterface::init() * @see DrawableFactoryInterface::init()
*/ */
public static function init(null|callable|DrawableInterface $init = null): self public static function init(null|Closure|DrawableInterface $init = null): self
{ {
return new self($init); return new self($init);
} }

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories; namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Circle; use Intervention\Image\Geometry\Circle;
use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\DrawableFactoryInterface; use Intervention\Image\Interfaces\DrawableFactoryInterface;
@@ -18,12 +19,12 @@ class CircleFactory implements DrawableFactoryInterface
* Create new factory instance * Create new factory instance
* *
* @param PointInterface $pivot * @param PointInterface $pivot
* @param null|callable|Circle $init * @param null|Closure|Circle $init
* @return void * @return void
*/ */
public function __construct( public function __construct(
protected PointInterface $pivot = new Point(), protected PointInterface $pivot = new Point(),
null|callable|Circle $init = null, null|Closure|Circle $init = null,
) { ) {
$this->circle = is_a($init, Circle::class) ? $init : new Circle(0); $this->circle = is_a($init, Circle::class) ? $init : new Circle(0);
$this->circle->setPosition($pivot); $this->circle->setPosition($pivot);
@@ -38,7 +39,7 @@ class CircleFactory implements DrawableFactoryInterface
* *
* @see DrawableFactoryInterface::init() * @see DrawableFactoryInterface::init()
*/ */
public static function init(null|callable|DrawableInterface $init = null): self public static function init(null|Closure|DrawableInterface $init = null): self
{ {
return new self(init: $init); return new self(init: $init);
} }

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories; namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Ellipse; use Intervention\Image\Geometry\Ellipse;
use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\DrawableFactoryInterface; use Intervention\Image\Interfaces\DrawableFactoryInterface;
@@ -18,12 +19,12 @@ class EllipseFactory implements DrawableFactoryInterface
* Create new factory instance * Create new factory instance
* *
* @param PointInterface $pivot * @param PointInterface $pivot
* @param null|callable|Ellipse $init * @param null|Closure|Ellipse $init
* @return void * @return void
*/ */
public function __construct( public function __construct(
protected PointInterface $pivot = new Point(), protected PointInterface $pivot = new Point(),
null|callable|Ellipse $init = null, null|Closure|Ellipse $init = null,
) { ) {
$this->ellipse = is_a($init, Ellipse::class) ? $init : new Ellipse(0, 0); $this->ellipse = is_a($init, Ellipse::class) ? $init : new Ellipse(0, 0);
$this->ellipse->setPosition($pivot); $this->ellipse->setPosition($pivot);
@@ -38,7 +39,7 @@ class EllipseFactory implements DrawableFactoryInterface
* *
* @see DrawableFactoryInterface::init() * @see DrawableFactoryInterface::init()
*/ */
public static function init(null|callable|DrawableInterface $init = null): self public static function init(null|Closure|DrawableInterface $init = null): self
{ {
return new self(init: $init); return new self(init: $init);
} }

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories; namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Line; use Intervention\Image\Geometry\Line;
use Intervention\Image\Interfaces\DrawableFactoryInterface; use Intervention\Image\Interfaces\DrawableFactoryInterface;
@@ -16,10 +17,10 @@ class LineFactory implements DrawableFactoryInterface
/** /**
* Create the factory instance * Create the factory instance
* *
* @param null|callable|Line $init * @param null|Closure|Line $init
* @return void * @return void
*/ */
public function __construct(null|callable|Line $init = null) public function __construct(null|Closure|Line $init = null)
{ {
$this->line = is_a($init, Line::class) ? $init : new Line(new Point(), new Point()); $this->line = is_a($init, Line::class) ? $init : new Line(new Point(), new Point());
@@ -33,7 +34,7 @@ class LineFactory implements DrawableFactoryInterface
* *
* @see DrawableFactoryInterface::init() * @see DrawableFactoryInterface::init()
*/ */
public static function init(null|callable|DrawableInterface $init = null): self public static function init(null|Closure|DrawableInterface $init = null): self
{ {
return new self($init); return new self($init);
} }

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories; namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Polygon; use Intervention\Image\Geometry\Polygon;
use Intervention\Image\Interfaces\DrawableFactoryInterface; use Intervention\Image\Interfaces\DrawableFactoryInterface;
@@ -16,10 +17,10 @@ class PolygonFactory implements DrawableFactoryInterface
/** /**
* Create new factory instance * Create new factory instance
* *
* @param null|callable|Polygon $init * @param null|Closure|Polygon $init
* @return void * @return void
*/ */
public function __construct(null|callable|Polygon $init = null) public function __construct(null|Closure|Polygon $init = null)
{ {
$this->polygon = is_a($init, Polygon::class) ? $init : new Polygon([]); $this->polygon = is_a($init, Polygon::class) ? $init : new Polygon([]);
@@ -33,7 +34,7 @@ class PolygonFactory implements DrawableFactoryInterface
* *
* @see DrawableFactoryInterface::init() * @see DrawableFactoryInterface::init()
*/ */
public static function init(null|callable|DrawableInterface $init = null): self public static function init(null|Closure|DrawableInterface $init = null): self
{ {
return new self($init); return new self($init);
} }

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories; namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\DrawableFactoryInterface; use Intervention\Image\Interfaces\DrawableFactoryInterface;
@@ -18,12 +19,12 @@ class RectangleFactory implements DrawableFactoryInterface
* Create new instance * Create new instance
* *
* @param PointInterface $pivot * @param PointInterface $pivot
* @param null|callable|Rectangle $init * @param null|Closure|Rectangle $init
* @return void * @return void
*/ */
public function __construct( public function __construct(
protected PointInterface $pivot = new Point(), protected PointInterface $pivot = new Point(),
null|callable|Rectangle $init = null, null|Closure|Rectangle $init = null,
) { ) {
$this->rectangle = is_a($init, Rectangle::class) ? $init : new Rectangle(0, 0, $pivot); $this->rectangle = is_a($init, Rectangle::class) ? $init : new Rectangle(0, 0, $pivot);
$this->rectangle->setPosition($pivot); $this->rectangle->setPosition($pivot);
@@ -38,7 +39,7 @@ class RectangleFactory implements DrawableFactoryInterface
* *
* @see DrawableFactoryInterface::init() * @see DrawableFactoryInterface::init()
*/ */
public static function init(null|callable|DrawableInterface $init = null): self public static function init(null|Closure|DrawableInterface $init = null): self
{ {
return new self(init: $init); return new self(init: $init);
} }

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image; namespace Intervention\Image;
use Closure;
use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Exceptions\RuntimeException;
use Traversable; use Traversable;
use Intervention\Image\Analyzers\ColorspaceAnalyzer; use Intervention\Image\Analyzers\ColorspaceAnalyzer;
@@ -618,7 +619,7 @@ final class Image implements ImageInterface
* *
* @see ImageInterface::text() * @see ImageInterface::text()
*/ */
public function text(string $text, int $x, int $y, callable|FontInterface $font): ImageInterface public function text(string $text, int $x, int $y, callable|Closure|FontInterface $font): ImageInterface
{ {
return $this->modify( return $this->modify(
new TextModifier( new TextModifier(
@@ -816,7 +817,7 @@ final class Image implements ImageInterface
* *
* @see ImageInterface::drawRectangle() * @see ImageInterface::drawRectangle()
*/ */
public function drawRectangle(int $x, int $y, callable|Rectangle $init): ImageInterface public function drawRectangle(int $x, int $y, callable|Closure|Rectangle $init): ImageInterface
{ {
return $this->modify( return $this->modify(
new DrawRectangleModifier( new DrawRectangleModifier(
@@ -830,7 +831,7 @@ final class Image implements ImageInterface
* *
* @see ImageInterface::drawEllipse() * @see ImageInterface::drawEllipse()
*/ */
public function drawEllipse(int $x, int $y, callable|Ellipse $init): ImageInterface public function drawEllipse(int $x, int $y, callable|Closure|Ellipse $init): ImageInterface
{ {
return $this->modify( return $this->modify(
new DrawEllipseModifier( new DrawEllipseModifier(
@@ -844,7 +845,7 @@ final class Image implements ImageInterface
* *
* @see ImageInterface::drawCircle() * @see ImageInterface::drawCircle()
*/ */
public function drawCircle(int $x, int $y, callable|Circle $init): ImageInterface public function drawCircle(int $x, int $y, callable|Closure|Circle $init): ImageInterface
{ {
return $this->modify( return $this->modify(
new DrawEllipseModifier( new DrawEllipseModifier(
@@ -858,7 +859,7 @@ final class Image implements ImageInterface
* *
* @see ImageInterface::drawPolygon() * @see ImageInterface::drawPolygon()
*/ */
public function drawPolygon(callable|Polygon $init): ImageInterface public function drawPolygon(callable|Closure|Polygon $init): ImageInterface
{ {
return $this->modify( return $this->modify(
new DrawPolygonModifier( new DrawPolygonModifier(
@@ -872,7 +873,7 @@ final class Image implements ImageInterface
* *
* @see ImageInterface::drawLine() * @see ImageInterface::drawLine()
*/ */
public function drawLine(callable|Line $init): ImageInterface public function drawLine(callable|Closure|Line $init): ImageInterface
{ {
return $this->modify( return $this->modify(
new DrawLineModifier( new DrawLineModifier(
@@ -886,7 +887,7 @@ final class Image implements ImageInterface
* *
* @see ImageInterface::drawBezier() * @see ImageInterface::drawBezier()
*/ */
public function drawBezier(callable|Bezier $init): ImageInterface public function drawBezier(callable|Closure|Bezier $init): ImageInterface
{ {
return $this->modify( return $this->modify(
new DrawBezierModifier( new DrawBezierModifier(

View File

@@ -4,15 +4,17 @@ declare(strict_types=1);
namespace Intervention\Image\Interfaces; namespace Intervention\Image\Interfaces;
use Closure;
interface DrawableFactoryInterface interface DrawableFactoryInterface
{ {
/** /**
* Create a new factory instance statically * Create a new factory instance statically
* *
* @param null|callable|DrawableInterface $init * @param null|Closure|DrawableInterface $init
* @return DrawableFactoryInterface * @return DrawableFactoryInterface
*/ */
public static function init(null|callable|DrawableInterface $init = null): self; public static function init(null|Closure|DrawableInterface $init = null): self;
/** /**
* Create the end product of the factory * Create the end product of the factory

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Interfaces; namespace Intervention\Image\Interfaces;
use Closure;
use Countable; use Countable;
use Intervention\Image\Encoders\AutoEncoder; use Intervention\Image\Encoders\AutoEncoder;
use Intervention\Image\Exceptions\AnimationException; use Intervention\Image\Exceptions\AnimationException;
@@ -453,11 +454,11 @@ interface ImageInterface extends IteratorAggregate, Countable
* @param string $text * @param string $text
* @param int $x * @param int $x
* @param int $y * @param int $y
* @param callable|FontInterface $font * @param callable|Closure|FontInterface $font
* @throws RuntimeException * @throws RuntimeException
* @return ImageInterface * @return ImageInterface
*/ */
public function text(string $text, int $x, int $y, callable|FontInterface $font): self; public function text(string $text, int $x, int $y, callable|Closure|FontInterface $font): self;
/** /**
* Resize image to the given width and/or height * Resize image to the given width and/or height
@@ -705,11 +706,11 @@ interface ImageInterface extends IteratorAggregate, Countable
* @link https://image.intervention.io/v3/modifying/drawing#drawing-a-rectangle * @link https://image.intervention.io/v3/modifying/drawing#drawing-a-rectangle
* @param int $x * @param int $x
* @param int $y * @param int $y
* @param callable|Rectangle $init * @param callable|Closure|Rectangle $init
* @throws RuntimeException * @throws RuntimeException
* @return ImageInterface * @return ImageInterface
*/ */
public function drawRectangle(int $x, int $y, callable|Rectangle $init): self; public function drawRectangle(int $x, int $y, callable|Closure|Rectangle $init): self;
/** /**
* Draw ellipse on the current image * Draw ellipse on the current image
@@ -717,11 +718,11 @@ interface ImageInterface extends IteratorAggregate, Countable
* @link https://image.intervention.io/v3/modifying/drawing#drawing-ellipses * @link https://image.intervention.io/v3/modifying/drawing#drawing-ellipses
* @param int $x * @param int $x
* @param int $y * @param int $y
* @param callable|Ellipse $init * @param callable|Closure|Ellipse $init
* @throws RuntimeException * @throws RuntimeException
* @return ImageInterface * @return ImageInterface
*/ */
public function drawEllipse(int $x, int $y, callable|Ellipse $init): self; public function drawEllipse(int $x, int $y, callable|Closure|Ellipse $init): self;
/** /**
* Draw circle on the current image * Draw circle on the current image
@@ -729,41 +730,41 @@ interface ImageInterface extends IteratorAggregate, Countable
* @link https://image.intervention.io/v3/modifying/drawing#drawing-a-circle * @link https://image.intervention.io/v3/modifying/drawing#drawing-a-circle
* @param int $x * @param int $x
* @param int $y * @param int $y
* @param callable|Circle $init * @param callable|Closure|Circle $init
* @throws RuntimeException * @throws RuntimeException
* @return ImageInterface * @return ImageInterface
*/ */
public function drawCircle(int $x, int $y, callable|Circle $init): self; public function drawCircle(int $x, int $y, callable|Closure|Circle $init): self;
/** /**
* Draw a polygon on the current image * Draw a polygon on the current image
* *
* @link https://image.intervention.io/v3/modifying/drawing#drawing-a-polygon * @link https://image.intervention.io/v3/modifying/drawing#drawing-a-polygon
* @param callable|Polygon $init * @param callable|Closure|Polygon $init
* @throws RuntimeException * @throws RuntimeException
* @return ImageInterface * @return ImageInterface
*/ */
public function drawPolygon(callable|Polygon $init): self; public function drawPolygon(callable|Closure|Polygon $init): self;
/** /**
* Draw a line on the current image * Draw a line on the current image
* *
* @link https://image.intervention.io/v3/modifying/drawing#drawing-a-line * @link https://image.intervention.io/v3/modifying/drawing#drawing-a-line
* @param callable|Line $init * @param callable|Closure|Line $init
* @throws RuntimeException * @throws RuntimeException
* @return ImageInterface * @return ImageInterface
*/ */
public function drawLine(callable|Line $init): self; public function drawLine(callable|Closure|Line $init): self;
/** /**
* Draw a bezier curve on the current image * Draw a bezier curve on the current image
* *
* @link https://image.intervention.io/v3/modifying/drawing#draw-bezier-curves * @link https://image.intervention.io/v3/modifying/drawing#draw-bezier-curves
* @param callable|Bezier $init * @param callable|Closure|Bezier $init
* @throws RuntimeException * @throws RuntimeException
* @return ImageInterface * @return ImageInterface
*/ */
public function drawBezier(callable|Bezier $init): self; public function drawBezier(callable|Closure|Bezier $init): self;
/** /**
* Encode image to given media (mime) type. If no type is given the image * Encode image to given media (mime) type. If no type is given the image

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Typography; namespace Intervention\Image\Typography;
use Closure;
use Intervention\Image\Exceptions\FontException; use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Interfaces\FontInterface; use Intervention\Image\Interfaces\FontInterface;
@@ -14,11 +15,11 @@ class FontFactory
/** /**
* Create new instance * Create new instance
* *
* @param callable|FontInterface $init * @param Closure|FontInterface $init
* @throws FontException * @throws FontException
* @return void * @return void
*/ */
public function __construct(callable|FontInterface $init) public function __construct(callable|Closure|FontInterface $init)
{ {
$this->font = is_a($init, FontInterface::class) ? $init : new Font(); $this->font = is_a($init, FontInterface::class) ? $init : new Font();