1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-11 16:34:00 +02:00

Refactor to PHP 8.1 code

This commit is contained in:
Oliver Vogel
2023-11-13 17:42:36 +01:00
parent d5a7099d53
commit afd5c7395b
5 changed files with 22 additions and 11 deletions

View File

@@ -2,15 +2,16 @@
namespace Intervention\Image\Geometry; namespace Intervention\Image\Geometry;
use Intervention\Image\Interfaces\PointInterface;
class Circle extends Ellipse class Circle extends Ellipse
{ {
public function __construct( public function __construct(
protected int $diameter, protected int $diameter,
protected ?Point $pivot = null protected PointInterface $pivot = new Point()
) { ) {
$this->setWidth($diameter); $this->setWidth($diameter);
$this->setHeight($diameter); $this->setHeight($diameter);
$this->pivot = $pivot ? $pivot : new Point();
} }
public function diameter(int $diameter): self public function diameter(int $diameter): self

View File

@@ -5,6 +5,7 @@ namespace Intervention\Image\Geometry;
use Intervention\Image\Geometry\Traits\HasBackgroundColor; use Intervention\Image\Geometry\Traits\HasBackgroundColor;
use Intervention\Image\Geometry\Traits\HasBorder; use Intervention\Image\Geometry\Traits\HasBorder;
use Intervention\Image\Interfaces\DrawableInterface; use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;
class Ellipse implements DrawableInterface class Ellipse implements DrawableInterface
{ {
@@ -14,9 +15,9 @@ class Ellipse implements DrawableInterface
public function __construct( public function __construct(
protected int $width, protected int $width,
protected int $height, 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 public function size(int $width, int $height): self

View File

@@ -10,6 +10,7 @@ use IteratorAggregate;
use Intervention\Image\Geometry\Traits\HasBackgroundColor; use Intervention\Image\Geometry\Traits\HasBackgroundColor;
use Intervention\Image\Geometry\Traits\HasBorder; use Intervention\Image\Geometry\Traits\HasBorder;
use Intervention\Image\Interfaces\DrawableInterface; use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;
class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface
{ {
@@ -18,9 +19,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
public function __construct( public function __construct(
protected array $points = [], protected array $points = [],
protected ?Point $pivot = null protected PointInterface $pivot = new Point()
) { ) {
$this->pivot = $pivot ? $pivot : new Point(); //
} }
public function getIterator(): Traversable public function getIterator(): Traversable
@@ -31,9 +32,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
/** /**
* Return current pivot point * Return current pivot point
* *
* @return Point * @return PointInterface
*/ */
public function getPivot(): Point public function getPivot(): PointInterface
{ {
return $this->pivot; return $this->pivot;
} }

View File

@@ -17,9 +17,8 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface
public function __construct( public function __construct(
int $width, int $width,
int $height, 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(), $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()));
$this->addPoint(new Point($this->pivot->x() + $width, $this->pivot->y() - $height)); $this->addPoint(new Point($this->pivot->x() + $width, $this->pivot->y() - $height));
@@ -62,7 +61,7 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface
return $this; return $this;
} }
public function pivot(): Point public function pivot(): PointInterface
{ {
return $this->pivot; return $this->pivot;
} }

View File

@@ -17,4 +17,13 @@ interface PointInterface
* @return int * @return int
*/ */
public function y(): 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;
} }