Skip to content

Commit

Permalink
Replace Point::class type hints by PointInterface::class
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jun 9, 2024
1 parent a987f93 commit 79d12d9
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 88 deletions.
5 changes: 3 additions & 2 deletions src/Drivers/Imagick/Modifiers/TextModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Intervention\Image\Interfaces\FontInterface;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\PointInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\TextModifier as GenericTextModifier;
use Intervention\Image\Typography\Line;
Expand Down Expand Up @@ -112,14 +113,14 @@ private function imagickDrawStroke(ImageInterface $image, FontInterface $font):
* @param FrameInterface $frame
* @param Line $textline
* @param null|ImagickDraw $draw
* @param Point $offset
* @param PointInterface $offset
* @return void
*/
private function maybeDrawTextline(
FrameInterface $frame,
Line $textline,
?ImagickDraw $draw = null,
Point $offset = new Point(),
PointInterface $offset = new Point(),
): void {
if ($draw !== null) {
$frame->native()->annotateImage(
Expand Down
36 changes: 18 additions & 18 deletions src/Geometry/Bezier.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use Intervention\Image\Interfaces\PointInterface;

/**
* @implements IteratorAggregate<Point>
* @implements ArrayAccess<int, Point>
* @implements IteratorAggregate<PointInterface>
* @implements ArrayAccess<int, PointInterface>
*/
class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface
{
Expand All @@ -26,7 +26,7 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
/**
* Create new bezier instance
*
* @param array<Point> $points
* @param array<PointInterface> $points
* @param PointInterface $pivot
* @return void
*/
Expand All @@ -49,7 +49,7 @@ public function position(): PointInterface
/**
* Implement iteration through all points of bezier
*
* @return Traversable<Point>
* @return Traversable<PointInterface>
*/
public function getIterator(): Traversable
{
Expand All @@ -69,10 +69,10 @@ public function pivot(): PointInterface
/**
* Change pivot point to given point
*
* @param Point $pivot
* @param PointInterface $pivot
* @return Bezier
*/
public function setPivot(Point $pivot): self
public function setPivot(PointInterface $pivot): self
{
$this->pivot = $pivot;

Expand All @@ -82,9 +82,9 @@ public function setPivot(Point $pivot): self
/**
* Return first control point of bezier
*
* @return ?Point
* @return ?PointInterface
*/
public function first(): ?Point
public function first(): ?PointInterface
{
if ($point = reset($this->points)) {
return $point;
Expand All @@ -96,9 +96,9 @@ public function first(): ?Point
/**
* Return second control point of bezier
*
* @return ?Point
* @return ?PointInterface
*/
public function second(): ?Point
public function second(): ?PointInterface
{
if (array_key_exists(1, $this->points)) {
return $this->points[1];
Expand All @@ -110,9 +110,9 @@ public function second(): ?Point
/**
* Return third control point of bezier
*
* @return ?Point
* @return ?PointInterface
*/
public function third(): ?Point
public function third(): ?PointInterface
{
if (array_key_exists(2, $this->points)) {
return $this->points[2];
Expand All @@ -124,9 +124,9 @@ public function third(): ?Point
/**
* Return last control point of bezier
*
* @return ?Point
* @return ?PointInterface
*/
public function last(): ?Point
public function last(): ?PointInterface
{
if ($point = end($this->points)) {
return $point;
Expand Down Expand Up @@ -160,7 +160,7 @@ public function offsetExists($offset): bool
* Return point at given offset
*
* @param mixed $offset
* @return Point
* @return PointInterface
*/
public function offsetGet($offset): mixed
{
Expand All @@ -171,7 +171,7 @@ public function offsetGet($offset): mixed
* Set point at given offset
*
* @param mixed $offset
* @param Point $value
* @param PointInterface $value
* @return void
*/
public function offsetSet($offset, $value): void
Expand All @@ -193,10 +193,10 @@ public function offsetUnset($offset): void
/**
* Add given point to bezier
*
* @param Point $point
* @param PointInterface $point
* @return Bezier
*/
public function addPoint(Point $point): self
public function addPoint(PointInterface $point): self
{
$this->points[] = $point;

Expand Down
5 changes: 3 additions & 2 deletions src/Geometry/Factories/CircleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\DrawableFactoryInterface;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;

class CircleFactory implements DrawableFactoryInterface
{
Expand All @@ -16,12 +17,12 @@ class CircleFactory implements DrawableFactoryInterface
/**
* Create new factory instance
*
* @param Point $pivot
* @param PointInterface $pivot
* @param null|callable|Circle $init
* @return void
*/
public function __construct(
protected Point $pivot = new Point(),
protected PointInterface $pivot = new Point(),
null|callable|Circle $init = null,
) {
$this->circle = is_a($init, Circle::class) ? $init : new Circle(0, $pivot);
Expand Down
5 changes: 3 additions & 2 deletions src/Geometry/Factories/EllipseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\DrawableFactoryInterface;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;

class EllipseFactory implements DrawableFactoryInterface
{
Expand All @@ -16,12 +17,12 @@ class EllipseFactory implements DrawableFactoryInterface
/**
* Create new factory instance
*
* @param Point $pivot
* @param PointInterface $pivot
* @param null|callable|Ellipse $init
* @return void
*/
public function __construct(
protected Point $pivot = new Point(),
protected PointInterface $pivot = new Point(),
null|callable|Ellipse $init = null,
) {
$this->ellipse = is_a($init, Ellipse::class) ? $init : new Ellipse(0, 0, $pivot);
Expand Down
5 changes: 3 additions & 2 deletions src/Geometry/Factories/RectangleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\DrawableFactoryInterface;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;

class RectangleFactory implements DrawableFactoryInterface
{
Expand All @@ -16,12 +17,12 @@ class RectangleFactory implements DrawableFactoryInterface
/**
* Create new instance
*
* @param Point $pivot
* @param PointInterface $pivot
* @param null|callable|Rectangle $init
* @return void
*/
public function __construct(
protected Point $pivot = new Point(),
protected PointInterface $pivot = new Point(),
null|callable|Rectangle $init = null,
) {
$this->rectangle = is_a($init, Rectangle::class) ? $init : new Rectangle(0, 0, $pivot);
Expand Down
36 changes: 24 additions & 12 deletions src/Geometry/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class Line implements DrawableInterface
/**
* Create new line instance
*
* @param Point $start
* @param Point $end
* @param PointInterface $start
* @param PointInterface $end
* @param int $width
* @return void
*/
public function __construct(
protected Point $start,
protected Point $end,
protected PointInterface $start,
protected PointInterface $end,
protected int $width = 1
) {
}
Expand All @@ -39,6 +39,18 @@ public function position(): PointInterface
return $this->start;
}

/**
* {@inheritdoc}
*
* @see DrawableInterface::setPosition()
*/
public function setPosition(PointInterface $position): DrawableInterface
{
$this->start = $position;

return $this;
}

/**
* Return line width
*
Expand All @@ -65,30 +77,30 @@ public function setWidth(int $width): self
/**
* Get starting point of line
*
* @return Point
* @return PointInterface
*/
public function start(): Point
public function start(): PointInterface
{
return $this->start;
}

/**
* get end point of line
*
* @return Point
* @return PointInterface
*/
public function end(): Point
public function end(): PointInterface
{
return $this->end;
}

/**
* Set starting point of line
*
* @param Point $start
* @param PointInterface $start
* @return Line
*/
public function setStart(Point $start): self
public function setStart(PointInterface $start): self
{
$this->start = $start;

Expand Down Expand Up @@ -128,10 +140,10 @@ public function to(int $x, int $y): self
/**
* Set end point of line
*
* @param Point $end
* @param PointInterface $end
* @return Line
*/
public function setEnd(Point $end): self
public function setEnd(PointInterface $end): self
{
$this->end = $end;

Expand Down
Loading

0 comments on commit 79d12d9

Please sign in to comment.