mirror of
https://github.com/Intervention/image.git
synced 2025-01-16 19:58:14 +01:00
Refactor to meet PHPStan level 5 (#1334)
* Update phpstan level * Refactor to meet phpstan level 5
This commit is contained in:
parent
e922730019
commit
5464ca5ec7
@ -18,7 +18,7 @@ services:
|
||||
analysis:
|
||||
build: ./
|
||||
working_dir: /project
|
||||
command: bash -c "composer install && ./vendor/bin/phpstan analyze --memory-limit=512M --level=4 ./src"
|
||||
command: bash -c "composer install && ./vendor/bin/phpstan analyze --memory-limit=512M ./src"
|
||||
volumes:
|
||||
- ./:/project
|
||||
standards:
|
||||
|
@ -1,5 +1,5 @@
|
||||
parameters:
|
||||
level: 4
|
||||
level: 5
|
||||
paths:
|
||||
- src
|
||||
exceptions:
|
||||
|
@ -9,6 +9,7 @@ use Intervention\Image\Colors\Cmyk\Color as CmykColor;
|
||||
use Intervention\Image\Colors\Hsv\Color as HsvColor;
|
||||
use Intervention\Image\Colors\Hsl\Color as HslColor;
|
||||
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
|
||||
@ -36,9 +37,9 @@ class Colorspace implements ColorspaceInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ColorspaceInterface::importColor()
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
public function importColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
@ -50,8 +51,17 @@ class Colorspace implements ColorspaceInterface
|
||||
};
|
||||
}
|
||||
|
||||
protected function importRgbColor(RgbColor $color): CmykColor
|
||||
/**
|
||||
* @param ColorInterface $color
|
||||
* @return Color
|
||||
* @throws ColorException
|
||||
*/
|
||||
protected function importRgbColor(ColorInterface $color): CmykColor
|
||||
{
|
||||
if (!($color instanceof RgbColor)) {
|
||||
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
|
||||
}
|
||||
|
||||
$c = (255 - $color->red()->value()) / 255.0 * 100;
|
||||
$m = (255 - $color->green()->value()) / 255.0 * 100;
|
||||
$y = (255 - $color->blue()->value()) / 255.0 * 100;
|
||||
|
@ -8,6 +8,7 @@ use Intervention\Image\Colors\Cmyk\Color as CmykColor;
|
||||
use Intervention\Image\Colors\Rgb\Color as RgbColor;
|
||||
use Intervention\Image\Colors\Hsv\Color as HsvColor;
|
||||
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
|
||||
@ -33,6 +34,11 @@ class Colorspace implements ColorspaceInterface
|
||||
return new Color(...$values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
public function importColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
return match ($color::class) {
|
||||
@ -43,8 +49,17 @@ class Colorspace implements ColorspaceInterface
|
||||
};
|
||||
}
|
||||
|
||||
protected function importRgbColor(RgbColor $color): ColorInterface
|
||||
/**
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
protected function importRgbColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
if (!($color instanceof RgbColor)) {
|
||||
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
|
||||
}
|
||||
|
||||
// normalized values of rgb channels
|
||||
$values = array_map(function ($channel) {
|
||||
return $channel->normalize();
|
||||
@ -84,8 +99,17 @@ class Colorspace implements ColorspaceInterface
|
||||
);
|
||||
}
|
||||
|
||||
protected function importHsvColor(HsvColor $color): ColorInterface
|
||||
/**
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
protected function importHsvColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
if (!($color instanceof HsvColor)) {
|
||||
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
|
||||
}
|
||||
|
||||
// normalized values of hsv channels
|
||||
list($h, $s, $v) = array_map(function ($channel) {
|
||||
return $channel->normalize();
|
||||
|
@ -8,6 +8,7 @@ use Intervention\Image\Colors\Cmyk\Color as CmykColor;
|
||||
use Intervention\Image\Colors\Rgb\Color as RgbColor;
|
||||
use Intervention\Image\Colors\Hsl\Color as HslColor;
|
||||
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
|
||||
@ -34,9 +35,9 @@ class Colorspace implements ColorspaceInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ColorspaceInterface::importColor()
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
public function importColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
@ -48,8 +49,17 @@ class Colorspace implements ColorspaceInterface
|
||||
};
|
||||
}
|
||||
|
||||
protected function importRgbColor(RgbColor $color): ColorInterface
|
||||
/**
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
protected function importRgbColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
if (!($color instanceof RgbColor)) {
|
||||
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
|
||||
}
|
||||
|
||||
// normalized values of rgb channels
|
||||
$values = array_map(function ($channel) {
|
||||
return $channel->normalize();
|
||||
@ -89,8 +99,17 @@ class Colorspace implements ColorspaceInterface
|
||||
);
|
||||
}
|
||||
|
||||
protected function importHslColor(HslColor $color): ColorInterface
|
||||
/**
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
protected function importHslColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
if (!($color instanceof HslColor)) {
|
||||
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
|
||||
}
|
||||
|
||||
// normalized values of hsl channels
|
||||
list($h, $s, $l) = array_map(function ($channel) {
|
||||
return $channel->normalize();
|
||||
|
@ -7,6 +7,7 @@ namespace Intervention\Image\Colors\Rgb;
|
||||
use Intervention\Image\Colors\Hsv\Color as HsvColor;
|
||||
use Intervention\Image\Colors\Hsl\Color as HslColor;
|
||||
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
|
||||
@ -34,9 +35,9 @@ class Colorspace implements ColorspaceInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ColorspaceInterface::importColor()
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
public function importColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
@ -48,8 +49,17 @@ class Colorspace implements ColorspaceInterface
|
||||
};
|
||||
}
|
||||
|
||||
protected function importCmykColor(CmykColor $color): ColorInterface
|
||||
/**
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
protected function importCmykColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
if (!($color instanceof CmykColor)) {
|
||||
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
|
||||
}
|
||||
|
||||
return new Color(
|
||||
(int) (255 * (1 - $color->cyan()->normalize()) * (1 - $color->key()->normalize())),
|
||||
(int) (255 * (1 - $color->magenta()->normalize()) * (1 - $color->key()->normalize())),
|
||||
@ -57,8 +67,17 @@ class Colorspace implements ColorspaceInterface
|
||||
);
|
||||
}
|
||||
|
||||
protected function importHsvColor(HsvColor $color): ColorInterface
|
||||
/**
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
protected function importHsvColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
if (!($color instanceof HsvColor)) {
|
||||
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
|
||||
}
|
||||
|
||||
$chroma = $color->value()->normalize() * $color->saturation()->normalize();
|
||||
$hue = $color->hue()->normalize() * 6;
|
||||
$x = $chroma * (1 - abs(fmod($hue, 2) - 1));
|
||||
@ -83,8 +102,17 @@ class Colorspace implements ColorspaceInterface
|
||||
return $this->colorFromNormalized($values);
|
||||
}
|
||||
|
||||
protected function importHslColor(HslColor $color): ColorInterface
|
||||
/**
|
||||
* @param ColorInterface $color
|
||||
* @return ColorInterface
|
||||
* @throws ColorException
|
||||
*/
|
||||
protected function importHslColor(ColorInterface $color): ColorInterface
|
||||
{
|
||||
if (!($color instanceof HslColor)) {
|
||||
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
|
||||
}
|
||||
|
||||
// normalized values of hsl channels
|
||||
list($h, $s, $l) = array_map(function ($channel) {
|
||||
return $channel->normalize();
|
||||
|
@ -90,7 +90,7 @@ enum Format
|
||||
/**
|
||||
* Create an encoder instance that matches the format
|
||||
*
|
||||
* @param array $options
|
||||
* @param mixed $options
|
||||
* @return EncoderInterface
|
||||
*/
|
||||
public function encoder(mixed ...$options): EncoderInterface
|
||||
|
@ -113,17 +113,17 @@ class Point implements PointInterface
|
||||
* Rotate point ccw around pivot
|
||||
*
|
||||
* @param float $angle
|
||||
* @param Point $pivot
|
||||
* @param PointInterface $pivot
|
||||
* @return Point
|
||||
*/
|
||||
public function rotate(float $angle, self $pivot): self
|
||||
public function rotate(float $angle, PointInterface $pivot): self
|
||||
{
|
||||
$sin = round(sin(deg2rad($angle)), 6);
|
||||
$cos = round(cos(deg2rad($angle)), 6);
|
||||
|
||||
return $this->setPosition(
|
||||
intval($cos * ($this->x - $pivot->x) - $sin * ($this->y - $pivot->y) + $pivot->x),
|
||||
intval($sin * ($this->x - $pivot->x) + $cos * ($this->y - $pivot->y) + $pivot->y)
|
||||
intval($cos * ($this->x() - $pivot->x()) - $sin * ($this->y() - $pivot->y()) + $pivot->x()),
|
||||
intval($sin * ($this->x() - $pivot->x()) + $cos * ($this->y() - $pivot->y()) + $pivot->y())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user