Skip to content

Commit 4669c42

Browse files
authored
Merge pull request #2 from PackageFactory/analysis-0gAgkj
Apply fixes from StyleCI
2 parents 1c464e1 + 268b1d3 commit 4669c42

7 files changed

Lines changed: 227 additions & 172 deletions

File tree

Classes/Domain/ValueObject/AbstractColor.php

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace PackageFactory\ColorHelper\Domain\ValueObject;
56

67
abstract class AbstractColor implements ColorInterface
78
{
8-
99
/**
1010
* @return string
1111
*/
@@ -17,20 +17,20 @@ public function __toString(): string
1717
/**
1818
* @return string
1919
*/
20-
public function getHexString():string
20+
public function getHexString(): string
2121
{
2222
$rgba = $this->asRgba();
2323
if ($rgba->getAlpha() == 255) {
2424
return '#'
25-
. str_pad(dechex($rgba->getRed()), 2, '0')
26-
. str_pad(dechex($rgba->getGreen()), 2, '0')
27-
. str_pad(dechex($rgba->getBlue()), 2, '0');
25+
.str_pad(dechex($rgba->getRed()), 2, '0')
26+
.str_pad(dechex($rgba->getGreen()), 2, '0')
27+
.str_pad(dechex($rgba->getBlue()), 2, '0');
2828
} else {
2929
return '#'
30-
. str_pad(dechex($rgba->getRed()), 2, '0')
31-
. str_pad(dechex($rgba->getGreen()), 2, '0')
32-
. str_pad(dechex($rgba->getBlue()), 2, '0')
33-
. str_pad(dechex($rgba->getAlpha()), 2, '0');
30+
.str_pad(dechex($rgba->getRed()), 2, '0')
31+
.str_pad(dechex($rgba->getGreen()), 2, '0')
32+
.str_pad(dechex($rgba->getBlue()), 2, '0')
33+
.str_pad(dechex($rgba->getAlpha()), 2, '0');
3434
}
3535
}
3636

@@ -62,6 +62,7 @@ public function getRgbaString(): string
6262

6363
/**
6464
* @param ColorInterface $color
65+
*
6566
* @return bool
6667
*/
6768
public function equals(ColorInterface $color): bool
@@ -71,13 +72,14 @@ public function equals(ColorInterface $color): bool
7172

7273
/**
7374
* @param ColorInterface $color
74-
* @param int $weight
75+
* @param int $weight
76+
*
7577
* @return RgbaColor
7678
*/
77-
public function withMixedColor (ColorInterface $color, int $weight = 50): ColorInterface
79+
public function withMixedColor(ColorInterface $color, int $weight = 50): ColorInterface
7880
{
79-
if ($weight < 0 || $weight > 100 ) {
80-
throw new \InvalidArgumentException('argument weight has to be an integer between 0 and 100, ' . $weight . ' was given.' );
81+
if ($weight < 0 || $weight > 100) {
82+
throw new \InvalidArgumentException('argument weight has to be an integer between 0 and 100, '.$weight.' was given.');
8183
}
8284

8385
$factorA = $weight / 100;
@@ -87,23 +89,28 @@ public function withMixedColor (ColorInterface $color, int $weight = 50): ColorI
8789
$rgbaColorB = $color->asRgba();
8890

8991
return new RgbaColor(
90-
(int)round(($rgbaColorA->getRed() * $factorA) + ($rgbaColorB->getRed() * $factorB)),
91-
(int)round(($rgbaColorA->getGreen() * $factorA) + ($rgbaColorB->getGreen() * $factorB)),
92-
(int)round(($rgbaColorA->getBlue() * $factorA) + ($rgbaColorB->getBlue() * $factorB)),
93-
(int)round(($rgbaColorA->getAlpha() * $factorA) + ($rgbaColorB->getAlpha() * $factorB))
92+
(int) round(($rgbaColorA->getRed() * $factorA) + ($rgbaColorB->getRed() * $factorB)),
93+
(int) round(($rgbaColorA->getGreen() * $factorA) + ($rgbaColorB->getGreen() * $factorB)),
94+
(int) round(($rgbaColorA->getBlue() * $factorA) + ($rgbaColorB->getBlue() * $factorB)),
95+
(int) round(($rgbaColorA->getAlpha() * $factorA) + ($rgbaColorB->getAlpha() * $factorB))
9496
);
9597
}
9698

9799
/**
98100
* @param int $delta
101+
*
99102
* @return ColorInterface
100103
*/
101104
public function withAdjustedLightness(int $delta): ColorInterface
102105
{
103106
$hslaColor = $this->asHsla();
104107
$lightness = $hslaColor->getLightness() + $delta;
105-
if ($lightness < 0) $lightness = 0;
106-
if ($lightness > 100) $lightness = 100;
108+
if ($lightness < 0) {
109+
$lightness = 0;
110+
}
111+
if ($lightness > 100) {
112+
$lightness = 100;
113+
}
107114

108115
return new HslaColor(
109116
$hslaColor->getHue(),
@@ -115,14 +122,19 @@ public function withAdjustedLightness(int $delta): ColorInterface
115122

116123
/**
117124
* @param int $delta
125+
*
118126
* @return ColorInterface
119127
*/
120128
public function withAdjustedSaturation(int $delta): ColorInterface
121129
{
122130
$hslaColor = $this->asHsla();
123131
$saturation = $hslaColor->getSaturation() + $delta;
124-
if ($saturation < 0) $saturation = 0;
125-
if ($saturation > 100) $saturation = 100;
132+
if ($saturation < 0) {
133+
$saturation = 0;
134+
}
135+
if ($saturation > 100) {
136+
$saturation = 100;
137+
}
126138

127139
return new HslaColor(
128140
$hslaColor->getHue(),
@@ -134,13 +146,16 @@ public function withAdjustedSaturation(int $delta): ColorInterface
134146

135147
/**
136148
* @param int $delta
149+
*
137150
* @return ColorInterface
138151
*/
139152
public function withAdjustedHue(int $delta): ColorInterface
140153
{
141154
$hslaColor = $this->asHsla();
142-
$hue = ($hslaColor->getHue() + $delta ) % 360;
143-
if ($hue < 0) $hue += 360;
155+
$hue = ($hslaColor->getHue() + $delta) % 360;
156+
if ($hue < 0) {
157+
$hue += 360;
158+
}
144159

145160
return new HslaColor(
146161
$hue,

Classes/Domain/ValueObject/ColorInterface.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace PackageFactory\ColorHelper\Domain\ValueObject;
56

6-
interface ColorInterface {
7-
7+
interface ColorInterface
8+
{
89
/**
910
* @return RgbaColor
1011
*/
@@ -17,9 +18,10 @@ public function asHsla(): HslaColor;
1718

1819
/**
1920
* @param ColorInterface $color
21+
*
2022
* @return bool
2123
*/
22-
public function equals(ColorInterface $color): bool;
24+
public function equals(self $color): bool;
2325

2426
/**
2527
* @return string
@@ -43,32 +45,37 @@ public function getRgbaString(): string;
4345

4446
/**
4547
* @param ColorInterface $color
46-
* @param int $weight 0 ... 100
48+
* @param int $weight 0 ... 100
49+
*
4750
* @return ColorInterface
4851
*/
49-
public function withMixedColor(ColorInterface $color, int $weight): ColorInterface;
52+
public function withMixedColor(self $color, int $weight): self;
5053

5154
/**
5255
* @param int $delta
56+
*
5357
* @return ColorInterface
5458
*/
55-
public function withAdjustedLightness(int $delta): ColorInterface;
59+
public function withAdjustedLightness(int $delta): self;
5660

5761
/**
5862
* @param int $delta
63+
*
5964
* @return ColorInterface
6065
*/
61-
public function withAdjustedSaturation(int $delta): ColorInterface;
66+
public function withAdjustedSaturation(int $delta): self;
6267

6368
/**
6469
* @param int $delta
70+
*
6571
* @return ColorInterface
6672
*/
67-
public function withAdjustedHue(int $delta): ColorInterface;
73+
public function withAdjustedHue(int $delta): self;
6874

6975
/**
7076
* @param int $delta
77+
*
7178
* @return ColorInterface
7279
*/
73-
public function withAdjustedAlpha(int $delta): ColorInterface;
80+
public function withAdjustedAlpha(int $delta): self;
7481
}

Classes/Domain/ValueObject/HslaColor.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace PackageFactory\ColorHelper\Domain\ValueObject;
56

67
class HslaColor extends AbstractColor implements ColorInterface
78
{
8-
99
/**
1010
* @var int
1111
*/
@@ -27,24 +27,25 @@ class HslaColor extends AbstractColor implements ColorInterface
2727

2828
/**
2929
* HslaColor constructor.
30+
*
3031
* @param int $hue
3132
* @param int $saturation
3233
* @param int $lightness
3334
* @param int $alpha
3435
*/
3536
public function __construct(int $hue, int $saturation, int $lightness, int $alpha = 255)
3637
{
37-
if ($hue < 0 || $hue > 359 ) {
38-
throw new \InvalidArgumentException('argument hue has to be an integer between 0 and 359, ' . $hue . ' was given.' );
38+
if ($hue < 0 || $hue > 359) {
39+
throw new \InvalidArgumentException('argument hue has to be an integer between 0 and 359, '.$hue.' was given.');
3940
}
40-
if ($saturation < 0 || $saturation > 100 ) {
41-
throw new \InvalidArgumentException('argument saturation has to be an integer between 0 and 100, ' . $saturation . ' was given.');
41+
if ($saturation < 0 || $saturation > 100) {
42+
throw new \InvalidArgumentException('argument saturation has to be an integer between 0 and 100, '.$saturation.' was given.');
4243
}
43-
if ($lightness < 0 || $lightness > 100 ) {
44-
throw new \InvalidArgumentException('argument luminosity has to be an integer between 0 and 100, ' . $lightness . ' was given.');
44+
if ($lightness < 0 || $lightness > 100) {
45+
throw new \InvalidArgumentException('argument luminosity has to be an integer between 0 and 100, '.$lightness.' was given.');
4546
}
46-
if ($alpha < 0 || $alpha > 255 ) {
47-
throw new \InvalidArgumentException('argument alpha has to be an integer between 0 and 255, ' . $alpha . ' was given');
47+
if ($alpha < 0 || $alpha > 255) {
48+
throw new \InvalidArgumentException('argument alpha has to be an integer between 0 and 255, '.$alpha.' was given');
4849
}
4950

5051
$this->hue = $hue;
@@ -93,7 +94,7 @@ public function asRgba(): RgbaColor
9394
$S = $this->saturation / 100;
9495
$L = $this->lightness / 100;
9596
$C = (1 - abs((2 * $L) - 1)) * $S;
96-
$X = $C * ( 1 - abs( (($this->hue / 60) % 2) - 1));
97+
$X = $C * (1 - abs((($this->hue / 60) % 2) - 1));
9798
$m = $L - ($C / 2);
9899

99100
if ($this->hue < 0) {
@@ -131,32 +132,37 @@ public function asRgba(): RgbaColor
131132
$B = ($b + $m) * 255;
132133

133134
return new RgbaColor(
134-
(int)round($R),
135-
(int)round($G),
136-
(int)round($B),
135+
(int) round($R),
136+
(int) round($G),
137+
(int) round($B),
137138
$this->alpha
138139
);
139140
}
140141

141142
/**
142143
* @return HslaColor
143144
*/
144-
public function asHsla(): HslaColor
145+
public function asHsla(): self
145146
{
146147
return $this;
147148
}
148149

149150
/**
150151
* @param int $delta
152+
*
151153
* @return ColorInterface
152154
*/
153155
public function withAdjustedAlpha(int $delta): ColorInterface
154156
{
155157
$alpha = $this->getAlpha() + $delta;
156-
if ($alpha < 0) $alpha = 0;
157-
if ($alpha > 255) $alpha = 255;
158+
if ($alpha < 0) {
159+
$alpha = 0;
160+
}
161+
if ($alpha > 255) {
162+
$alpha = 255;
163+
}
158164

159-
return new HslaColor(
165+
return new self(
160166
$this->hue,
161167
$this->saturation,
162168
$this->lightness,

0 commit comments

Comments
 (0)