11<?php
2+
23declare (strict_types=1 );
34
45namespace PackageFactory \ColorHelper \Domain \ValueObject ;
56
67abstract 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 ,
0 commit comments