From 5288425e8d9c7deeef289cd68f10bbcb35caf7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 14:52:32 +0100 Subject: [PATCH 1/9] Da bei allen Transformationen vom HSV-Farbmodell ausgegangen wird, ist es von Vorteil diese Klassen in einer abstrakten Klasse zusammenzufassen. --- .../AbstractHueSaturationValueToUtility.php | 56 +++++++++++++++++++ ...eSaturationValueToCyanMagentaYellowKey.php | 42 +------------- .../HueSaturationValueToRedGreenBlue.php | 39 +------------ 3 files changed, 61 insertions(+), 76 deletions(-) create mode 100644 src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php diff --git a/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php b/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php new file mode 100644 index 0000000..d237a04 --- /dev/null +++ b/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php @@ -0,0 +1,56 @@ +hue = $from_color->getHue(); + $this->hueAsPercentGrad = intval($this->hue * self::INTERVAL * 6.0); + $this->saturation = $from_color->getSaturation(); + $this->value = $from_color->getValue(); + } + + + protected function processConvert(): void + { + if ($this->saturation > 0.0) { + $this->splitColor(); + } + } + + abstract protected function splitColor(): void; + + protected function calcColorValue($reciprocal = false): float + { + // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' + $remainder_grad = $this->hueAsPercentGrad % self::INTERVAL; + // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' + $remainder = $remainder_grad / self::INTERVAL; + return $this->saturation * ($reciprocal ? (1 - $remainder) : $remainder); + } + +} \ No newline at end of file diff --git a/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php b/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php index a8e9d0a..bfced30 100644 --- a/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php +++ b/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php @@ -5,23 +5,9 @@ namespace TorstenHettstedt\Colors\Transformer\Utilities; use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey; -use TorstenHettstedt\Colors\ColorModels\HueSaturationValue; -class HueSaturationValueToCyanMagentaYellowKey +class HueSaturationValueToCyanMagentaYellowKey extends AbstractHueSaturationValueToUtility { - /** @var int : Größe des Intervals in 1/100 Grad */ - protected const INTERVAL = 60.0 * 100.0; - - // Daten für HSV - /** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */ - protected float $hue; - /** @var float : Anteil am Vollkreis in 1/100 Grad */ - protected float $hueAsPercentGrad; - /** @var float : Definition der Sättigung der Farbe */ - protected float $saturation; - /** @var float : Definition der Helligkeit der Farbe */ - protected float $value; - // Daten für CMYK /** @var float : Definition des Cyan-Anteil */ protected float $cyan = 0.0; @@ -32,19 +18,6 @@ class HueSaturationValueToCyanMagentaYellowKey /** @var float : Definition des Schwarzanteil */ protected float $key = 0.0; - /** - * HueSaturationValueToRedGreenBlue constructor. - * @param HueSaturationValue $from_color - * @noinspection PhpPureAttributeCanBeAddedInspection - */ - public function __construct(HueSaturationValue $from_color) - { - $this->hue = $from_color->getHue(); - $this->hueAsPercentGrad = intval($this->hue * self::INTERVAL * 6); - $this->saturation = $from_color->getSaturation(); - $this->value = $from_color->getValue(); - } - public function convert(): CyanMagentaYellowKey { $this->processConvert(); @@ -60,9 +33,7 @@ class HueSaturationValueToCyanMagentaYellowKey protected function processConvert(): void { $this->key = 1 - $this->value; - if ($this->saturation !== 0.0) { - $this->splitColor(); - } + parent::processConvert(); } protected function splitColor(): void @@ -98,13 +69,4 @@ class HueSaturationValueToCyanMagentaYellowKey } } - protected function calcColorValue($reciprocal = false): float - { - // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' - $remainder_grad = $this->hueAsPercentGrad % self::INTERVAL; - // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' - $remainder = $remainder_grad / self::INTERVAL; - return $this->saturation * ($reciprocal ? (1 - $remainder) : $remainder); - } - } \ No newline at end of file diff --git a/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php b/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php index 64fab92..30b473d 100644 --- a/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php +++ b/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php @@ -4,24 +4,10 @@ namespace TorstenHettstedt\Colors\Transformer\Utilities; -use TorstenHettstedt\Colors\ColorModels\HueSaturationValue; use TorstenHettstedt\Colors\ColorModels\RedGreenBlue; -class HueSaturationValueToRedGreenBlue +class HueSaturationValueToRedGreenBlue extends AbstractHueSaturationValueToUtility { - /** @var int : Größe des Intervals in 1/100 Grad */ - protected const INTERVAL = 60.0 * 100.0; - - // Daten für HSV - /** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */ - protected float $hue; - /** @var float : Anteil am Vollkreis in 1/100 Grad */ - protected float $hueAsPercentGrad; - /** @var float : Definition der Sättigung der Farbe */ - protected float $saturation; - /** @var float : Definition der Helligkeit der Farbe */ - protected float $value; - // Daten für RGB /** @var float : Definition des Rotanteil */ protected float $red = 1.0; @@ -30,19 +16,6 @@ class HueSaturationValueToRedGreenBlue /** @var float : Definition des Blauanteil */ protected float $blue = 1.0; - /** - * HueSaturationValueToRedGreenBlue constructor. - * @param HueSaturationValue $from_color - * @noinspection PhpPureAttributeCanBeAddedInspection - */ - public function __construct(HueSaturationValue $from_color) - { - $this->hue = $from_color->getHue(); - $this->hueAsPercentGrad = intval($this->hue * self::INTERVAL * 6); - $this->saturation = $from_color->getSaturation(); - $this->value = $from_color->getValue(); - } - public function convert(): RedGreenBlue { $this->processConvert(); @@ -57,9 +30,7 @@ class HueSaturationValueToRedGreenBlue protected function processConvert(): void { $this->red = $this->green = $this->blue = $this->value; - if ($this->saturation > 0.0) { - $this->splitColor(); - } + parent::processConvert(); } protected function splitColor(): void @@ -99,12 +70,8 @@ class HueSaturationValueToRedGreenBlue protected function calcColorValue($reciprocal = false): float { - // Rest-Anteil am Vollkreis in 1/100 Grad - $remainder_grad = $this->hueAsPercentGrad % self::INTERVAL; - // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' - $remainder = $remainder_grad / self::INTERVAL; $color_value = $this->value; - $color_value *= 1 - ($this->saturation * ($reciprocal ? (1 - $remainder) : $remainder)); + $color_value *= 1 - parent::calcColorValue($reciprocal); return $color_value; } -- 2.54.0 From c3aa3929978999e9973e93a1dc1d9267f68028f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 14:56:09 +0100 Subject: [PATCH 2/9] Es wurde eine Empfehlung von *PhpStorm* entsprochen. --- .../Utilities/CyanMagentaYellowKeyToHueSaturationValue.php | 2 ++ src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Transformer/Utilities/CyanMagentaYellowKeyToHueSaturationValue.php b/src/Transformer/Utilities/CyanMagentaYellowKeyToHueSaturationValue.php index 3a52c14..ae42ca4 100644 --- a/src/Transformer/Utilities/CyanMagentaYellowKeyToHueSaturationValue.php +++ b/src/Transformer/Utilities/CyanMagentaYellowKeyToHueSaturationValue.php @@ -2,6 +2,7 @@ namespace TorstenHettstedt\Colors\Transformer\Utilities; +use JetBrains\PhpStorm\Pure; use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey; use TorstenHettstedt\Colors\ColorModels\HueSaturationValue; @@ -72,6 +73,7 @@ class CyanMagentaYellowKeyToHueSaturationValue ->setValue($this->value); } + #[Pure] protected function buildHueAmount(): float { // Wenn beide Werte gleich sind, ist die Endfarbe Grau. diff --git a/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php b/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php index f74d781..b4b8f9b 100644 --- a/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php +++ b/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php @@ -2,6 +2,7 @@ namespace TorstenHettstedt\Colors\Transformer\Utilities; +use JetBrains\PhpStorm\Pure; use TorstenHettstedt\Colors\ColorModels\HueSaturationValue; use TorstenHettstedt\Colors\ColorModels\RedGreenBlue; @@ -70,6 +71,7 @@ class RedGreenBlueToHueSaturationValue ->setValue($this->value); } + #[Pure] protected function buildHueAmount(): float { // Wenn beide Werte gleich sind, ist die Endfarbe Grau. -- 2.54.0 From f890a9df676fafc146af4e55636231761e9717b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 15:13:13 +0100 Subject: [PATCH 3/9] Einbau von *PhpStan* --- composer.json | 3 ++- phpstan.neon | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index 8cce282..97d96bb 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "require-dev": { "codeception/codeception": "^4.1.18", "codeception/module-phpbrowser": "^1.0.0", - "codeception/module-asserts": "^1.0.0" + "codeception/module-asserts": "^1.0.0", + "phpstan/phpstan" : "^0.12.82" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..f117a55 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 6 + paths: + - src + - tests/unit \ No newline at end of file -- 2.54.0 From f7899d9f1ea79b7e0c0261180237ced4da5e8df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 15:45:03 +0100 Subject: [PATCH 4/9] =?UTF-8?q?Laut=20*PhpStan*=20hat=20die=20R=C3=BCckgab?= =?UTF-8?q?e=20von=20Methoden=20in=20Testklassen=20=20gefehlt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ColorModels/AbstractColorModelUnit.php | 2 +- .../ColorModels/CyanMagentaYellowKeyTest.php | 18 +++++++++--------- .../ColorModels/HueSaturationValueTest.php | 14 +++++++------- tests/unit/ColorModels/RedGreenBlueTest.php | 14 +++++++------- .../CyanMagentaYellowKeyTransformerTest.php | 6 +++--- .../HueSaturationValueTransformerTest.php | 6 +++--- .../RedGreenBlueTransformerTest.php | 6 +++--- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/unit/ColorModels/AbstractColorModelUnit.php b/tests/unit/ColorModels/AbstractColorModelUnit.php index 90fe58e..bf23ddd 100644 --- a/tests/unit/ColorModels/AbstractColorModelUnit.php +++ b/tests/unit/ColorModels/AbstractColorModelUnit.php @@ -8,7 +8,7 @@ use Codeception\Test\Unit; abstract class AbstractColorModelUnit extends Unit { - abstract public function testConstruct(); + abstract public function testConstruct(): void; /** * @return float[][] diff --git a/tests/unit/ColorModels/CyanMagentaYellowKeyTest.php b/tests/unit/ColorModels/CyanMagentaYellowKeyTest.php index bffb391..5529b8e 100644 --- a/tests/unit/ColorModels/CyanMagentaYellowKeyTest.php +++ b/tests/unit/ColorModels/CyanMagentaYellowKeyTest.php @@ -8,7 +8,7 @@ use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey; class CyanMagentaYellowKeyTest extends AbstractColorModelUnit { - public function testConstruct() + public function testConstruct(): void { $color = new CyanMagentaYellowKey(); @@ -23,7 +23,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetCyanWithValidValue(float $value) + public function testSetCyanWithValidValue(float $value): void { $color = new CyanMagentaYellowKey(); @@ -36,7 +36,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetMagentaWithValidValue(float $value) + public function testSetMagentaWithValidValue(float $value): void { $color = new CyanMagentaYellowKey(); @@ -49,7 +49,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetYellowWithValidValue(float $value) + public function testSetYellowWithValidValue(float $value): void { $color = new CyanMagentaYellowKey(); @@ -62,7 +62,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetKeyWithValidValue(float $value) + public function testSetKeyWithValidValue(float $value): void { $color = new CyanMagentaYellowKey(); @@ -75,7 +75,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetCyanWithInvalidValue(float $value) + public function testSetCyanWithInvalidValue(float $value): void { $color = new CyanMagentaYellowKey(); @@ -88,7 +88,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetMagentaWithInvalidValue(float $value) + public function testSetMagentaWithInvalidValue(float $value): void { $color = new CyanMagentaYellowKey(); @@ -101,7 +101,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetYellowWithInvalidValue(float $value) + public function testSetYellowWithInvalidValue(float $value): void { $color = new CyanMagentaYellowKey(); @@ -114,7 +114,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetKeyWithInvalidValue(float $value) + public function testSetKeyWithInvalidValue(float $value): void { $color = new CyanMagentaYellowKey(); diff --git a/tests/unit/ColorModels/HueSaturationValueTest.php b/tests/unit/ColorModels/HueSaturationValueTest.php index 6600266..e30ba79 100644 --- a/tests/unit/ColorModels/HueSaturationValueTest.php +++ b/tests/unit/ColorModels/HueSaturationValueTest.php @@ -8,7 +8,7 @@ use TorstenHettstedt\Colors\ColorModels\HueSaturationValue; class HueSaturationValueTest extends AbstractColorModelUnit { - public function testConstruct() + public function testConstruct(): void { $color = new HueSaturationValue(); @@ -22,7 +22,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetHueWithValidValue(float $value) + public function testSetHueWithValidValue(float $value): void { $color = new HueSaturationValue(); @@ -35,7 +35,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetHueWithInvalidValue(float $value) + public function testSetHueWithInvalidValue(float $value): void { $color = new HueSaturationValue(); @@ -48,7 +48,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetSaturationWithValidValue(float $value) + public function testSetSaturationWithValidValue(float $value): void { $color = new HueSaturationValue(); @@ -61,7 +61,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetSaturationWithInvalidValue(float $value) + public function testSetSaturationWithInvalidValue(float $value): void { $color = new HueSaturationValue(); @@ -74,7 +74,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetValueWithValidValue(float $value) + public function testSetValueWithValidValue(float $value): void { $color = new HueSaturationValue(); @@ -87,7 +87,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetValueWithInvalidValue(float $value) + public function testSetValueWithInvalidValue(float $value): void { $color = new HueSaturationValue(); diff --git a/tests/unit/ColorModels/RedGreenBlueTest.php b/tests/unit/ColorModels/RedGreenBlueTest.php index e8de492..f0af84d 100644 --- a/tests/unit/ColorModels/RedGreenBlueTest.php +++ b/tests/unit/ColorModels/RedGreenBlueTest.php @@ -8,7 +8,7 @@ use TorstenHettstedt\Colors\ColorModels\RedGreenBlue; class RedGreenBlueTest extends AbstractColorModelUnit { - public function testConstruct() + public function testConstruct(): void { $color = new RedGreenBlue(); @@ -22,7 +22,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetRedWithValidValue(float $value) + public function testSetRedWithValidValue(float $value): void { $color = new RedGreenBlue(); @@ -35,7 +35,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetRedWithInvalidValue(float $value) + public function testSetRedWithInvalidValue(float $value): void { $color = new RedGreenBlue(); @@ -47,7 +47,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetGreenWithValidValue(float $value) + public function testSetGreenWithValidValue(float $value): void { $color = new RedGreenBlue(); @@ -60,7 +60,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetGreenWithInvalidValue(float $value) + public function testSetGreenWithInvalidValue(float $value): void { $color = new RedGreenBlue(); @@ -73,7 +73,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit * * @dataProvider validValueProvider */ - public function testSetBlueWithValidValue(float $value) + public function testSetBlueWithValidValue(float $value): void { $color = new RedGreenBlue(); @@ -86,7 +86,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit * * @dataProvider invalidValueProvider */ - public function testSetBlueWithInvalidValue(float $value) + public function testSetBlueWithInvalidValue(float $value): void { $color = new RedGreenBlue(); diff --git a/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php b/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php index 36ad76e..5f014be 100644 --- a/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php +++ b/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php @@ -45,7 +45,7 @@ class CyanMagentaYellowKeyTransformerTest extends Unit * * @throws Exception */ - public function testToRedGreenBlue(array $cmyk, array $rgb) + public function testToRedGreenBlue(array $cmyk, array $rgb): void { $this->color = $this->make(CyanMagentaYellowKey::class, $cmyk); @@ -66,7 +66,7 @@ class CyanMagentaYellowKeyTransformerTest extends Unit * * @throws Exception */ - public function testToCyanMagentaYellowKey(array $cmyk) + public function testToCyanMagentaYellowKey(array $cmyk): void { $this->color = $this->make(CyanMagentaYellowKey::class, $cmyk); @@ -90,7 +90,7 @@ class CyanMagentaYellowKeyTransformerTest extends Unit * @dataProvider validHsvValuesProvider * */ - public function testToHueSaturationValue(array $cmyk, array $hsv) + public function testToHueSaturationValue(array $cmyk, array $hsv): void { $this->color = $this->make(CyanMagentaYellowKey::class, $cmyk); diff --git a/tests/unit/Transformer/HueSaturationValueTransformerTest.php b/tests/unit/Transformer/HueSaturationValueTransformerTest.php index 6d214ed..374528a 100644 --- a/tests/unit/Transformer/HueSaturationValueTransformerTest.php +++ b/tests/unit/Transformer/HueSaturationValueTransformerTest.php @@ -45,7 +45,7 @@ class HueSaturationValueTransformerTest extends Unit * * @throws Exception */ - public function testToRedGreenBlue(array $hsv, array $rgb) + public function testToRedGreenBlue(array $hsv, array $rgb): void { $this->color = $this->make(HueSaturationValue::class, $hsv); @@ -67,7 +67,7 @@ class HueSaturationValueTransformerTest extends Unit * @dataProvider validCmykValuesProvider * */ - public function testToCyanMagentaYellowKey(array $hsv, array $cmyk) + public function testToCyanMagentaYellowKey(array $hsv, array $cmyk): void { $this->color = $this->make(HueSaturationValue::class, $hsv); @@ -88,7 +88,7 @@ class HueSaturationValueTransformerTest extends Unit * @throws Exception * @dataProvider validCmykValuesProvider */ - public function testToHueSaturationValue(array $hsv) + public function testToHueSaturationValue(array $hsv): void { $this->color = $this->make(HueSaturationValue::class, $hsv); diff --git a/tests/unit/Transformer/RedGreenBlueTransformerTest.php b/tests/unit/Transformer/RedGreenBlueTransformerTest.php index d2f40a3..c50c07e 100644 --- a/tests/unit/Transformer/RedGreenBlueTransformerTest.php +++ b/tests/unit/Transformer/RedGreenBlueTransformerTest.php @@ -44,7 +44,7 @@ class RedGreenBlueTransformerTest extends Unit * * @throws Exception */ - public function testToRedGreenBlue(array $rgb) + public function testToRedGreenBlue(array $rgb): void { $this->color = $this->make(RedGreenBlue::class, $rgb); @@ -66,7 +66,7 @@ class RedGreenBlueTransformerTest extends Unit * @dataProvider validCmykValuesProvider * */ - public function testToCyanMagentaYellowKey(array $rgb, array $cmyk) + public function testToCyanMagentaYellowKey(array $rgb, array $cmyk): void { $this->color = $this->make(RedGreenBlue::class, $rgb); @@ -88,7 +88,7 @@ class RedGreenBlueTransformerTest extends Unit * @throws Exception * @dataProvider validHsvValuesProvider */ - public function testToHueSaturationValue(array $rgb, array $hsv) + public function testToHueSaturationValue(array $rgb, array $hsv): void { $this->color = $this->make(RedGreenBlue::class, $rgb); -- 2.54.0 From b363c269846277db29bec28847130a694102e44e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 15:55:38 +0100 Subject: [PATCH 5/9] =?UTF-8?q?Die=20selbstgeschriebene=20Hilfsklasse=20wi?= =?UTF-8?q?rd=20mit=20=C3=BCberpr=C3=BCft.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpstan.neon | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index f117a55..c1923db 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,4 +2,5 @@ parameters: level: 6 paths: - src - - tests/unit \ No newline at end of file + - tests/unit + - tests/_support/Helper \ No newline at end of file -- 2.54.0 From 15b425aa22ea3920f3519128cb3abb866ba253f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 15:57:30 +0100 Subject: [PATCH 6/9] =?UTF-8?q?Definition=20der=20Parameter=20=20und=20R?= =?UTF-8?q?=C3=BCckgaben=20im=20*PhpDoc*-Text=20wurde=20nach=20Hinweisen?= =?UTF-8?q?=20von=20*PhpStan*=20angepasst.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/_support/Helper/ValidColorValuesProvider.php | 8 ++++++++ .../CyanMagentaYellowKeyTransformerTest.php | 14 +++++++------- .../HueSaturationValueTransformerTest.php | 14 +++++++------- .../Transformer/RedGreenBlueTransformerTest.php | 14 +++++++------- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/tests/_support/Helper/ValidColorValuesProvider.php b/tests/_support/Helper/ValidColorValuesProvider.php index 352e669..58680d7 100644 --- a/tests/_support/Helper/ValidColorValuesProvider.php +++ b/tests/_support/Helper/ValidColorValuesProvider.php @@ -11,6 +11,9 @@ class ValidColorValuesProvider const RGB = 'rgb'; const HSV = 'hsv'; + /** + * @var array[]> + */ protected array $definitions = [ 'weiß' => [ self::CMYK => [ @@ -302,6 +305,11 @@ class ValidColorValuesProvider ], ]; + /** + * @param array $order + * + * @return array[]> + */ public function getValidColorValues(array $order): array { $values = []; diff --git a/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php b/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php index 5f014be..26a00db 100644 --- a/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php +++ b/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php @@ -16,7 +16,7 @@ class CyanMagentaYellowKeyTransformerTest extends Unit protected CyanMagentaYellowKey $color; /** - * @return float[][][] + * @return array[]> */ public function validRgbValuesProvider(): array { @@ -27,7 +27,7 @@ class CyanMagentaYellowKeyTransformerTest extends Unit } /** - * @return float[][][] + * @return array[]> */ public function validHsvValuesProvider(): array { @@ -38,8 +38,8 @@ class CyanMagentaYellowKeyTransformerTest extends Unit } /** - * @param array $cmyk - * @param array $rgb + * @param array $cmyk + * @param array $rgb * * @dataProvider validRgbValuesProvider * @@ -60,7 +60,7 @@ class CyanMagentaYellowKeyTransformerTest extends Unit } /** - * @param array $cmyk + * @param array $cmyk * * @dataProvider validRgbValuesProvider * @@ -82,8 +82,8 @@ class CyanMagentaYellowKeyTransformerTest extends Unit } /** - * @param array $cmyk - * @param array $hsv + * @param array $cmyk + * @param array $hsv * * @throws Exception * diff --git a/tests/unit/Transformer/HueSaturationValueTransformerTest.php b/tests/unit/Transformer/HueSaturationValueTransformerTest.php index 374528a..4f2633a 100644 --- a/tests/unit/Transformer/HueSaturationValueTransformerTest.php +++ b/tests/unit/Transformer/HueSaturationValueTransformerTest.php @@ -16,7 +16,7 @@ class HueSaturationValueTransformerTest extends Unit protected HueSaturationValue $color; /** - * @return float[][][] + * @return array[]> */ public function validCmykValuesProvider(): array { @@ -27,7 +27,7 @@ class HueSaturationValueTransformerTest extends Unit } /** - * @return float[][][] + * @return array[]> */ public function validRgbValuesProvider(): array { @@ -38,8 +38,8 @@ class HueSaturationValueTransformerTest extends Unit } /** - * @param array $hsv - * @param array $rgb + * @param array $hsv + * @param array $rgb * * @dataProvider validRgbValuesProvider * @@ -60,8 +60,8 @@ class HueSaturationValueTransformerTest extends Unit } /** - * @param array $hsv - * @param array $cmyk + * @param array $hsv + * @param array $cmyk * * @throws Exception * @dataProvider validCmykValuesProvider @@ -83,7 +83,7 @@ class HueSaturationValueTransformerTest extends Unit } /** - * @param array $hsv + * @param array $hsv * * @throws Exception * @dataProvider validCmykValuesProvider diff --git a/tests/unit/Transformer/RedGreenBlueTransformerTest.php b/tests/unit/Transformer/RedGreenBlueTransformerTest.php index c50c07e..b42b4cd 100644 --- a/tests/unit/Transformer/RedGreenBlueTransformerTest.php +++ b/tests/unit/Transformer/RedGreenBlueTransformerTest.php @@ -16,7 +16,7 @@ class RedGreenBlueTransformerTest extends Unit protected RedGreenBlue $color; /** - * @return float[][][] + * @return array[]> */ public function validCmykValuesProvider(): array { @@ -27,7 +27,7 @@ class RedGreenBlueTransformerTest extends Unit } /** - * @return float[][][] + * @return array[]> */ public function validHsvValuesProvider(): array { @@ -38,7 +38,7 @@ class RedGreenBlueTransformerTest extends Unit } /** - * @param array $rgb + * @param array $rgb * * @dataProvider validCmykValuesProvider * @@ -59,8 +59,8 @@ class RedGreenBlueTransformerTest extends Unit } /** - * @param array $rgb - * @param array $cmyk + * @param array $rgb + * @param array $cmyk * * @throws Exception * @dataProvider validCmykValuesProvider @@ -82,8 +82,8 @@ class RedGreenBlueTransformerTest extends Unit } /** - * @param array $rgb - * @param array $hsv + * @param array $rgb + * @param array $hsv * * @throws Exception * @dataProvider validHsvValuesProvider -- 2.54.0 From 6a26eb46080a41469a156d35312ff82e373554e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 16:12:35 +0100 Subject: [PATCH 7/9] =?UTF-8?q?R=C3=BCckgaben=20nach=20Hinweisen=20von=20*?= =?UTF-8?q?PhpStan*=20angepasst.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ColorModels/AbstractColorModel.php | 2 +- .../Utilities/AbstractHueSaturationValueToUtility.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ColorModels/AbstractColorModel.php b/src/ColorModels/AbstractColorModel.php index 5db61f3..4e85a57 100644 --- a/src/ColorModels/AbstractColorModel.php +++ b/src/ColorModels/AbstractColorModel.php @@ -8,7 +8,7 @@ use InvalidArgumentException; abstract class AbstractColorModel { - protected function checkValue(float $value) + protected function checkValue(float $value): void { if ($value > 1.0) { throw new InvalidArgumentException('Ein Wert größer als 1 ist nicht definierbar.'); diff --git a/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php b/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php index d237a04..d578fe5 100644 --- a/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php +++ b/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php @@ -44,6 +44,11 @@ abstract class AbstractHueSaturationValueToUtility abstract protected function splitColor(): void; + /** + * @param bool $reciprocal + * + * @return float + */ protected function calcColorValue($reciprocal = false): float { // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' -- 2.54.0 From 0e033b1fbeeb041d4d693b750e0e30cd7a718dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 16:13:30 +0100 Subject: [PATCH 8/9] =?UTF-8?q?Nutzung=20der=20Methode=20'intdiv'=20nach?= =?UTF-8?q?=20Hinweisen=20von=20*PhpStan*=20=C3=BCberdacht.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Utilities/HueSaturationValueToCyanMagentaYellowKey.php | 4 ++-- .../Utilities/HueSaturationValueToRedGreenBlue.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php b/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php index bfced30..c66e963 100644 --- a/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php +++ b/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php @@ -39,9 +39,9 @@ class HueSaturationValueToCyanMagentaYellowKey extends AbstractHueSaturationValu protected function splitColor(): void { // ID des zu nutzenden Interval - $interval_id = intdiv($this->hueAsPercentGrad , self::INTERVAL); + $interval_id = $this->hueAsPercentGrad / self::INTERVAL; - switch ($interval_id) { + switch ((int)$interval_id) { case 1: // Yellow $this->cyan = $this->calcColorValue(); $this->yellow = $this->saturation; diff --git a/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php b/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php index 30b473d..3520d92 100644 --- a/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php +++ b/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php @@ -36,11 +36,11 @@ class HueSaturationValueToRedGreenBlue extends AbstractHueSaturationValueToUtili protected function splitColor(): void { // ID des zu nutzenden Interval - $interval_id = intdiv($this->hueAsPercentGrad , self::INTERVAL); + $interval_id = $this->hueAsPercentGrad / self::INTERVAL; // Ist der Wert der entgegen gesetzten Farbe. $opposite_color_value = $this->value * ( 1 - $this->saturation); - - switch ($interval_id) { + + switch ((int)$interval_id) { case 1: $this->red = $this->calcColorValue(); $this->blue = $opposite_color_value; -- 2.54.0 From 0642ffe48a5fe6ab320aa13e86bb5d4270d4989d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 16:14:37 +0100 Subject: [PATCH 9/9] Die Attribute von *PhpStorm* werden auch von *PhpStan* gefunden. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 97d96bb..7e8f131 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ }, "require": { "php": "^8.0", - "phpunit/php-code-coverage": "^9.2" + "phpunit/php-code-coverage": "^9.2", + "jetbrains/phpstorm-attributes": "^1.0.0" }, "require-dev": { "codeception/codeception": "^4.1.18", -- 2.54.0