Skip to content

Commit

Permalink
Refactor to PHP 8.1 code
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Nov 13, 2023
1 parent d5a7099 commit afd5c73
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/Geometry/Circle.php
Expand Up @@ -2,15 +2,16 @@

namespace Intervention\Image\Geometry;

use Intervention\Image\Interfaces\PointInterface;

class Circle extends Ellipse
{
public function __construct(
protected int $diameter,
protected ?Point $pivot = null
protected PointInterface $pivot = new Point()
) {
$this->setWidth($diameter);
$this->setHeight($diameter);
$this->pivot = $pivot ? $pivot : new Point();
}

public function diameter(int $diameter): self
Expand Down
5 changes: 3 additions & 2 deletions src/Geometry/Ellipse.php
Expand Up @@ -5,6 +5,7 @@
use Intervention\Image\Geometry\Traits\HasBackgroundColor;
use Intervention\Image\Geometry\Traits\HasBorder;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;

class Ellipse implements DrawableInterface
{
Expand All @@ -14,9 +15,9 @@ class Ellipse implements DrawableInterface
public function __construct(
protected int $width,
protected int $height,
protected ?Point $pivot = null
protected PointInterface $pivot = new Point()
) {
$this->pivot = $pivot ? $pivot : new Point();
//
}

public function size(int $width, int $height): self
Expand Down
9 changes: 5 additions & 4 deletions src/Geometry/Polygon.php
Expand Up @@ -10,6 +10,7 @@
use Intervention\Image\Geometry\Traits\HasBackgroundColor;
use Intervention\Image\Geometry\Traits\HasBorder;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;

class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface
{
Expand All @@ -18,9 +19,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte

public function __construct(
protected array $points = [],
protected ?Point $pivot = null
protected PointInterface $pivot = new Point()
) {
$this->pivot = $pivot ? $pivot : new Point();
//
}

public function getIterator(): Traversable
Expand All @@ -31,9 +32,9 @@ public function getIterator(): Traversable
/**
* Return current pivot point
*
* @return Point
* @return PointInterface
*/
public function getPivot(): Point
public function getPivot(): PointInterface
{
return $this->pivot;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Geometry/Rectangle.php
Expand Up @@ -17,9 +17,8 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface
public function __construct(
int $width,
int $height,
protected ?Point $pivot = null
protected PointInterface $pivot = new Point()
) {
$this->pivot = $pivot ? $pivot : new Point();
$this->addPoint(new Point($this->pivot->x(), $this->pivot->y()));
$this->addPoint(new Point($this->pivot->x() + $width, $this->pivot->y()));
$this->addPoint(new Point($this->pivot->x() + $width, $this->pivot->y() - $height));
Expand Down Expand Up @@ -62,7 +61,7 @@ public function setHeight(int $height): self
return $this;
}

public function pivot(): Point
public function pivot(): PointInterface
{
return $this->pivot;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Interfaces/PointInterface.php
Expand Up @@ -17,4 +17,13 @@ public function x(): int;
* @return int
*/
public function y(): int;

/**
* Set position of point
*
* @param int $x
* @param int $y
* @return PointInterface
*/
public function setPosition(int $x, int $y): PointInterface;
}

0 comments on commit afd5c73

Please sign in to comment.