@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function setAttributes(array $attributes) : AttributeCollection |
79 | 79 | { |
80 | - foreach($attributes as $name => $value) |
|
80 | + foreach ($attributes as $name => $value) |
|
81 | 81 | { |
82 | 82 | $this->attr($name, $value); |
83 | 83 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | return $this; |
86 | 86 | } |
87 | 87 | |
88 | - public function getAttribute(string $name, string $default='') : string |
|
88 | + public function getAttribute(string $name, string $default = '') : string |
|
89 | 89 | { |
90 | 90 | return $this->attributes[$name] ?? $default; |
91 | 91 | } |
@@ -94,14 +94,14 @@ discard block |
||
94 | 94 | * @param array<string,string|number|bool|NULL|Interface_Stringable|StringBuilder_Interface> $attributes |
95 | 95 | * @return AttributeCollection |
96 | 96 | */ |
97 | - public static function create(array $attributes=array()) : AttributeCollection |
|
97 | + public static function create(array $attributes = array()) : AttributeCollection |
|
98 | 98 | { |
99 | 99 | return new AttributeCollection($attributes); |
100 | 100 | } |
101 | 101 | |
102 | - public function prop(string $name, bool $enabled=true) : AttributeCollection |
|
102 | + public function prop(string $name, bool $enabled = true) : AttributeCollection |
|
103 | 103 | { |
104 | - if($enabled) |
|
104 | + if ($enabled) |
|
105 | 105 | { |
106 | 106 | return $this->attr($name, $name); |
107 | 107 | } |
@@ -118,23 +118,23 @@ discard block |
||
118 | 118 | { |
119 | 119 | $string = Filtering::value2string($value); |
120 | 120 | |
121 | - if($name === 'class') |
|
121 | + if ($name === 'class') |
|
122 | 122 | { |
123 | 123 | return $this->addClasses(ConvertHelper::explodeTrim(' ', $string)); |
124 | 124 | } |
125 | 125 | |
126 | - if($name === 'style') |
|
126 | + if ($name === 'style') |
|
127 | 127 | { |
128 | 128 | $this->styles->parseStylesString($string); |
129 | 129 | return $this; |
130 | 130 | } |
131 | 131 | |
132 | - if($string !== '') |
|
132 | + if ($string !== '') |
|
133 | 133 | { |
134 | 134 | $this->attributes[$name] = $string; |
135 | 135 | |
136 | 136 | // remove it from the empty stack if it was empty before. |
137 | - if(in_array($name, $this->empty, true)) { |
|
137 | + if (in_array($name, $this->empty, true)) { |
|
138 | 138 | $this->empty = array_remove_values($this->empty, array($name)); |
139 | 139 | } |
140 | 140 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | { |
160 | 160 | $this->attr($name, $value); |
161 | 161 | |
162 | - if(isset($this->attributes[$name])) |
|
162 | + if (isset($this->attributes[$name])) |
|
163 | 163 | { |
164 | 164 | $this->attributes[$name] = Filtering::quotes($this->attributes[$name]); |
165 | 165 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | public function remove(string $name) : AttributeCollection |
176 | 176 | { |
177 | - if(isset($this->attributes[$name])) |
|
177 | + if (isset($this->attributes[$name])) |
|
178 | 178 | { |
179 | 179 | unset($this->attributes[$name]); |
180 | 180 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | |
197 | 197 | private function getRenderer() : AttributesRenderer |
198 | 198 | { |
199 | - if(isset($this->renderer)) |
|
199 | + if (isset($this->renderer)) |
|
200 | 200 | { |
201 | 201 | return $this->renderer; |
202 | 202 | } |
@@ -230,12 +230,12 @@ discard block |
||
230 | 230 | $attributes = $this->attributes; |
231 | 231 | |
232 | 232 | // Are there any empty attributes to keep? |
233 | - if(!empty($this->keepEmpty)) |
|
233 | + if (!empty($this->keepEmpty)) |
|
234 | 234 | { |
235 | 235 | $names = array_keys($this->keepEmpty); |
236 | 236 | |
237 | - foreach($names as $name) { |
|
238 | - if(in_array($name, $this->empty, true)) { |
|
237 | + foreach ($names as $name) { |
|
238 | + if (in_array($name, $this->empty, true)) { |
|
239 | 239 | $attributes[$name] = ''; |
240 | 240 | } |
241 | 241 | } |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | return $attributes; |
245 | 245 | } |
246 | 246 | |
247 | - public function setKeepIfEmpty(string $name, bool $keep=true) : self |
|
247 | + public function setKeepIfEmpty(string $name, bool $keep = true) : self |
|
248 | 248 | { |
249 | - if($keep === true) |
|
249 | + if ($keep === true) |
|
250 | 250 | { |
251 | 251 | $this->keepEmpty[$name] = true; |
252 | 252 | } |
253 | - else if(isset($this->keepEmpty[$name])) |
|
253 | + else if (isset($this->keepEmpty[$name])) |
|
254 | 254 | { |
255 | 255 | unset($this->keepEmpty[$name]); |
256 | 256 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | |
300 | 300 | public const TARGET_BLANK = '_blank'; |
301 | 301 | |
302 | - public function target(string $value=self::TARGET_BLANK) : AttributeCollection |
|
302 | + public function target(string $value = self::TARGET_BLANK) : AttributeCollection |
|
303 | 303 | { |
304 | 304 | return $this->attr('target', $value); |
305 | 305 | } |
@@ -137,8 +137,7 @@ discard block |
||
137 | 137 | if(in_array($name, $this->empty, true)) { |
138 | 138 | $this->empty = array_remove_values($this->empty, array($name)); |
139 | 139 | } |
140 | - } |
|
141 | - else |
|
140 | + } else |
|
142 | 141 | { |
143 | 142 | unset($this->attributes[$name]); |
144 | 143 | |
@@ -249,8 +248,7 @@ discard block |
||
249 | 248 | if($keep === true) |
250 | 249 | { |
251 | 250 | $this->keepEmpty[$name] = true; |
252 | - } |
|
253 | - else if(isset($this->keepEmpty[$name])) |
|
251 | + } else if(isset($this->keepEmpty[$name])) |
|
254 | 252 | { |
255 | 253 | unset($this->keepEmpty[$name]); |
256 | 254 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param bool $selfClosing |
55 | 55 | * @return $this |
56 | 56 | */ |
57 | - public function setSelfClosing(bool $selfClosing=true) : self |
|
57 | + public function setSelfClosing(bool $selfClosing = true) : self |
|
58 | 58 | { |
59 | 59 | $this->selfClosing = $selfClosing; |
60 | 60 | return $this; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param bool $allowed |
70 | 70 | * @return $this |
71 | 71 | */ |
72 | - public function setEmptyAllowed(bool $allowed=true) : self |
|
72 | + public function setEmptyAllowed(bool $allowed = true) : self |
|
73 | 73 | { |
74 | 74 | $this->allowEmpty = $allowed; |
75 | 75 | return $this; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | public function isEmptyAllowed() : bool |
79 | 79 | { |
80 | - if($this->isSelfClosing()) |
|
80 | + if ($this->isSelfClosing()) |
|
81 | 81 | { |
82 | 82 | return true; |
83 | 83 | } |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | return $this->allowEmpty; |
86 | 86 | } |
87 | 87 | |
88 | - public static function create(string $name, ?AttributeCollection $attributes=null) : HTMLTag |
|
88 | + public static function create(string $name, ?AttributeCollection $attributes = null) : HTMLTag |
|
89 | 89 | { |
90 | - if($attributes === null) |
|
90 | + if ($attributes === null) |
|
91 | 91 | { |
92 | 92 | $attributes = AttributeCollection::create(); |
93 | 93 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | public function render() : string |
115 | 115 | { |
116 | - if(!$this->isEmptyAllowed() && $this->isEmpty()) |
|
116 | + if (!$this->isEmptyAllowed() && $this->isEmpty()) |
|
117 | 117 | { |
118 | 118 | return ''; |
119 | 119 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | public static function getGlobalOptions() : GlobalOptions |
128 | 128 | { |
129 | - if(!isset(self::$globalOptions)) |
|
129 | + if (!isset(self::$globalOptions)) |
|
130 | 130 | { |
131 | 131 | self::$globalOptions = new GlobalOptions(); |
132 | 132 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | public function getSelfClosingChar() : string |
138 | 138 | { |
139 | - if($this->selfClosing && self::getGlobalOptions()->getSelfCloseStyle() === self::SELF_CLOSE_STYLE_SLASH) |
|
139 | + if ($this->selfClosing && self::getGlobalOptions()->getSelfCloseStyle() === self::SELF_CLOSE_STYLE_SLASH) |
|
140 | 140 | { |
141 | 141 | return '/'; |
142 | 142 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | public function renderClose() : string |
158 | 158 | { |
159 | - if($this->selfClosing) |
|
159 | + if ($this->selfClosing) |
|
160 | 160 | { |
161 | 161 | return ''; |
162 | 162 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | |
201 | 201 | public function renderContent() : string |
202 | 202 | { |
203 | - if($this->selfClosing) |
|
203 | + if ($this->selfClosing) |
|
204 | 204 | { |
205 | 205 | return ''; |
206 | 206 | } |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | * @param bool $keepIfEmpty |
220 | 220 | * @return $this |
221 | 221 | */ |
222 | - public function attr(string $name, string $value, bool $keepIfEmpty=false) : self |
|
222 | + public function attr(string $name, string $value, bool $keepIfEmpty = false) : self |
|
223 | 223 | { |
224 | 224 | $this->attributes->attr($name, $value); |
225 | 225 | |
226 | - if($keepIfEmpty) { |
|
226 | + if ($keepIfEmpty) { |
|
227 | 227 | $this->attributes->setKeepIfEmpty($name); |
228 | 228 | } |
229 | 229 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @param bool $enabled |
236 | 236 | * @return $this |
237 | 237 | */ |
238 | - public function prop(string $name, bool $enabled=true) : self |
|
238 | + public function prop(string $name, bool $enabled = true) : self |
|
239 | 239 | { |
240 | 240 | $this->attributes->prop($name, $enabled); |
241 | 241 | return $this; |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | * @param bool $forceNew |
13 | 13 | * @return NumberInfo |
14 | 14 | */ |
15 | -function parseNumber($value, bool $forceNew=false) |
|
15 | +function parseNumber($value, bool $forceNew = false) |
|
16 | 16 | { |
17 | - if($value instanceof NumberInfo && $forceNew !== true) { |
|
17 | + if ($value instanceof NumberInfo && $forceNew !== true) { |
|
18 | 18 | return $value; |
19 | 19 | } |
20 | 20 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $args = func_get_args(); |
110 | 110 | |
111 | 111 | // is the localization package installed? |
112 | - if(function_exists('\AppLocalize\t')) |
|
112 | + if (function_exists('\AppLocalize\t')) |
|
113 | 113 | { |
114 | 114 | return call_user_func_array('\AppLocalize\t', $args); |
115 | 115 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @param bool $initial The initial boolean value to use. |
125 | 125 | * @return Value_Bool |
126 | 126 | */ |
127 | -function valBool(bool $initial=false) : Value_Bool |
|
127 | +function valBool(bool $initial = false) : Value_Bool |
|
128 | 128 | { |
129 | 129 | return new Value_Bool($initial); |
130 | 130 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param bool $initial |
138 | 138 | * @return Value_Bool_True |
139 | 139 | */ |
140 | -function valBoolTrue(bool $initial=false) : Value_Bool_True |
|
140 | +function valBoolTrue(bool $initial = false) : Value_Bool_True |
|
141 | 141 | { |
142 | 142 | return new Value_Bool_True($initial); |
143 | 143 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @param bool $initial |
151 | 151 | * @return Value_Bool_False |
152 | 152 | */ |
153 | -function valBoolFalse(bool $initial=true) : Value_Bool_False |
|
153 | +function valBoolFalse(bool $initial = true) : Value_Bool_False |
|
154 | 154 | { |
155 | 155 | return new Value_Bool_False($initial); |
156 | 156 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @param bool $strict |
183 | 183 | * @return array<mixed> |
184 | 184 | */ |
185 | -function array_remove_values(array $haystack, array $values, bool $strict=true) : array |
|
185 | +function array_remove_values(array $haystack, array $values, bool $strict = true) : array |
|
186 | 186 | { |
187 | 187 | return array_filter( |
188 | 188 | $haystack, |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | */ |
198 | 198 | function init() : void |
199 | 199 | { |
200 | - if(!class_exists('\AppLocalize\Localization')) { |
|
200 | + if (!class_exists('\AppLocalize\Localization')) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | |
25 | 25 | $attributes = $this->compileAttributes(); |
26 | 26 | |
27 | - if(empty($attributes)) |
|
27 | + if (empty($attributes)) |
|
28 | 28 | { |
29 | 29 | return ''; |
30 | 30 | } |
31 | 31 | |
32 | - foreach($attributes as $name => $value) |
|
32 | + foreach ($attributes as $name => $value) |
|
33 | 33 | { |
34 | - if($value === '' && !$this->collection->isKeepIfEmpty($name)) |
|
34 | + if ($value === '' && !$this->collection->isKeepIfEmpty($name)) |
|
35 | 35 | { |
36 | 36 | continue; |
37 | 37 | } |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | { |
54 | 54 | $attributes = $this->collection->getRawAttributes(); |
55 | 55 | |
56 | - if($this->collection->hasClasses()) |
|
56 | + if ($this->collection->hasClasses()) |
|
57 | 57 | { |
58 | 58 | $attributes['class'] = $this->collection->classesToString(); |
59 | 59 | } |
60 | 60 | |
61 | - if($this->collection->hasStyles()) |
|
61 | + if ($this->collection->hasStyles()) |
|
62 | 62 | { |
63 | 63 | $attributes['style'] = $this->collection->getStyles() |
64 | 64 | ->configureForInline() |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | private function renderAttribute(string $name, string $value) : string |
72 | 72 | { |
73 | - if($name === $value) |
|
73 | + if ($name === $value) |
|
74 | 74 | { |
75 | 75 | return $name; |
76 | 76 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public function __construct(string $datetime, DateTimeZone $timeZone) |
42 | 42 | { |
43 | - if(stripos($datetime, 'T') !== false) { |
|
43 | + if (stripos($datetime, 'T') !== false) { |
|
44 | 44 | $datetime = $this->parseISO8601($datetime); |
45 | 45 | } |
46 | 46 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | { |
53 | 53 | preg_match('/([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}:[0-9]{2})\.([0-9]+)Z/', $datetime, $matches); |
54 | 54 | |
55 | - if(!empty($matches[0])) { |
|
55 | + if (!empty($matches[0])) { |
|
56 | 56 | return sprintf( |
57 | 57 | '%s %s.%s', |
58 | 58 | $matches[1], |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public static function getPresetsManager() : PresetsManager |
50 | 50 | { |
51 | - if(!isset(self::$presets)) |
|
51 | + if (!isset(self::$presets)) |
|
52 | 52 | { |
53 | 53 | self::$presets = new PresetsManager(); |
54 | 54 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param string $name |
65 | 65 | * @return RGBAColor |
66 | 66 | */ |
67 | - public static function create(ColorChannel $red, ColorChannel $green, ColorChannel $blue, ?ColorChannel $alpha=null, string $name='') : RGBAColor |
|
67 | + public static function create(ColorChannel $red, ColorChannel $green, ColorChannel $blue, ?ColorChannel $alpha = null, string $name = '') : RGBAColor |
|
68 | 68 | { |
69 | 69 | return new RGBAColor($red, $green, $blue, $alpha, $name); |
70 | 70 | } |
@@ -88,31 +88,31 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public static function createAuto($subject) : ?RGBAColor |
90 | 90 | { |
91 | - if($subject instanceof RGBAColor) |
|
91 | + if ($subject instanceof RGBAColor) |
|
92 | 92 | { |
93 | 93 | return $subject; |
94 | 94 | } |
95 | 95 | |
96 | - if(is_array($subject)) |
|
96 | + if (is_array($subject)) |
|
97 | 97 | { |
98 | 98 | return self::createFrom8BitArray($subject); |
99 | 99 | } |
100 | 100 | |
101 | 101 | $hexOrPreset = (string)$subject; |
102 | 102 | |
103 | - if($hexOrPreset === '') |
|
103 | + if ($hexOrPreset === '') |
|
104 | 104 | { |
105 | 105 | return null; |
106 | 106 | } |
107 | 107 | |
108 | 108 | $manager = self::getPresetsManager(); |
109 | 109 | |
110 | - if($manager->hasPreset($hexOrPreset)) |
|
110 | + if ($manager->hasPreset($hexOrPreset)) |
|
111 | 111 | { |
112 | 112 | return $manager->getPreset($hexOrPreset); |
113 | 113 | } |
114 | 114 | |
115 | - if(preg_match('/[a-f0-9]{3,8}/i', $hexOrPreset)) |
|
115 | + if (preg_match('/[a-f0-9]{3,8}/i', $hexOrPreset)) |
|
116 | 116 | { |
117 | 117 | return self::createFromHEX($hexOrPreset); |
118 | 118 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | { |
161 | 161 | $color = FormatsConverter::array2associative($color); |
162 | 162 | |
163 | - if(!isset($color[RGBAColor::CHANNEL_ALPHA])) |
|
163 | + if (!isset($color[RGBAColor::CHANNEL_ALPHA])) |
|
164 | 164 | { |
165 | 165 | $color[RGBAColor::CHANNEL_ALPHA] = 0; |
166 | 166 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @see RGBAColor::ERROR_INVALID_COLOR_COMPONENT |
186 | 186 | * @see RGBAColor::ERROR_INVALID_PERCENTAGE_VALUE |
187 | 187 | */ |
188 | - public static function createFromHEX(string $hex, string $name='') : RGBAColor |
|
188 | + public static function createFromHEX(string $hex, string $name = '') : RGBAColor |
|
189 | 189 | { |
190 | 190 | return FormatsConverter::hex2color($hex, $name); |
191 | 191 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @param string $name |
211 | 211 | * @return RGBAColor |
212 | 212 | */ |
213 | - public static function createPercent(float $red, float $green, float $blue, float $alpha=0, string $name='') : RGBAColor |
|
213 | + public static function createPercent(float $red, float $green, float $blue, float $alpha = 0, string $name = '') : RGBAColor |
|
214 | 214 | { |
215 | 215 | return new RGBAColor( |
216 | 216 | ColorChannel::percent($red), |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @param string $name |
233 | 233 | * @return RGBAColor |
234 | 234 | */ |
235 | - public static function createCSS(int $red, int $green, int $blue, float $alpha=0, string $name='') : RGBAColor |
|
235 | + public static function createCSS(int $red, int $green, int $blue, float $alpha = 0, string $name = '') : RGBAColor |
|
236 | 236 | { |
237 | 237 | return self::create( |
238 | 238 | ColorChannel::eightBit($red), |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * @param string $name |
255 | 255 | * @return RGBAColor |
256 | 256 | */ |
257 | - public static function create8Bit(int $red, int $green, int $blue, int $alpha=0, string $name='') : RGBAColor |
|
257 | + public static function create8Bit(int $red, int $green, int $blue, int $alpha = 0, string $name = '') : RGBAColor |
|
258 | 258 | { |
259 | 259 | return self::create( |
260 | 260 | ColorChannel::eightBit($red), |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @param string $name |
278 | 278 | * @return RGBAColor |
279 | 279 | */ |
280 | - public static function createGD(int $red, int $green, int $blue, int $alpha=0, string $name='') : RGBAColor |
|
280 | + public static function createGD(int $red, int $green, int $blue, int $alpha = 0, string $name = '') : RGBAColor |
|
281 | 281 | { |
282 | 282 | return self::create( |
283 | 283 | ColorChannel::eightBit($red), |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $color = imagecolorsforindex($img, $colorIndex); |
300 | 300 | |
301 | 301 | // it seems imagecolorsforindex() may return false (undocumented, unproven) |
302 | - if(is_array($color)) { |
|
302 | + if (is_array($color)) { |
|
303 | 303 | return self::create( |
304 | 304 | ColorChannel::eightBit($color['red']), |
305 | 305 | ColorChannel::eightBit($color['green']), |
@@ -322,10 +322,10 @@ discard block |
||
322 | 322 | * @param float|AlphaChannel|NULL $alpha 0 to 1 or NULL if none. |
323 | 323 | * @return HSVColor |
324 | 324 | */ |
325 | - public static function createHSV($hue, $saturation, $brightness, $alpha=null) : HSVColor |
|
325 | + public static function createHSV($hue, $saturation, $brightness, $alpha = null) : HSVColor |
|
326 | 326 | { |
327 | 327 | $alphaChannel = null; |
328 | - if($alpha !== null) { |
|
328 | + if ($alpha !== null) { |
|
329 | 329 | $alphaChannel = ColorChannel::alpha($alpha); |
330 | 330 | } |
331 | 331 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | $brightness = $hsv['brightness'] ?? $hsv[2] ?? null; |
362 | 362 | $alpha = $hsv['alpha'] ?? $hsv[3] ?? null; |
363 | 363 | |
364 | - if($hue !== null && $saturation !== null && $brightness !== null) { |
|
364 | + if ($hue !== null && $saturation !== null && $brightness !== null) { |
|
365 | 365 | return self::createHSV( |
366 | 366 | $hue, |
367 | 367 | $saturation, |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | public static function color2HEX(RGBAColor $color) : string |
43 | 43 | { |
44 | 44 | $hex = |
45 | - UnitsConverter::int2hex($color->getRed()->get8Bit()) . |
|
46 | - UnitsConverter::int2hex($color->getGreen()->get8Bit()) . |
|
45 | + UnitsConverter::int2hex($color->getRed()->get8Bit()). |
|
46 | + UnitsConverter::int2hex($color->getGreen()->get8Bit()). |
|
47 | 47 | UnitsConverter::int2hex($color->getBlue()->get8Bit()); |
48 | 48 | |
49 | - if($color->hasTransparency()) |
|
49 | + if ($color->hasTransparency()) |
|
50 | 50 | { |
51 | 51 | $hex .= UnitsConverter::int2hex($color->getAlpha()->get8Bit()); |
52 | 52 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public static function color2CSS(RGBAColor $color) : string |
64 | 64 | { |
65 | - if($color->hasTransparency()) |
|
65 | + if ($color->hasTransparency()) |
|
66 | 66 | { |
67 | 67 | return sprintf( |
68 | 68 | 'rgba(%s, %s, %s, %s)', |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public static function requireValidColorArray(array $color) : void |
99 | 99 | { |
100 | - if(self::isColorArray($color)) |
|
100 | + if (self::isColorArray($color)) |
|
101 | 101 | { |
102 | 102 | return; |
103 | 103 | } |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | RGBAColor::CHANNEL_BLUE |
130 | 130 | ); |
131 | 131 | |
132 | - foreach($keys as $key) |
|
132 | + foreach ($keys as $key) |
|
133 | 133 | { |
134 | - if(!isset($color[$key])) |
|
134 | + if (!isset($color[$key])) |
|
135 | 135 | { |
136 | 136 | return false; |
137 | 137 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public static function color2readable(RGBAColor $color) : string |
152 | 152 | { |
153 | - if($color->hasTransparency()) |
|
153 | + if ($color->hasTransparency()) |
|
154 | 154 | { |
155 | 155 | return sprintf( |
156 | 156 | 'RGBA(%s %s %s %s)', |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * @throws ColorException |
189 | 189 | * @see RGBAColor::ERROR_INVALID_HEX_LENGTH |
190 | 190 | */ |
191 | - public static function hex2color(string $hex, string $name='') : RGBAColor |
|
191 | + public static function hex2color(string $hex, string $name = '') : RGBAColor |
|
192 | 192 | { |
193 | - if(!isset(self::$hexParser)) |
|
193 | + if (!isset(self::$hexParser)) |
|
194 | 194 | { |
195 | 195 | self::$hexParser = new HEXParser(); |
196 | 196 | } |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | { |
243 | 243 | // If one associative key is present, we assume |
244 | 244 | // that the color array is already correct. |
245 | - if(isset($color[RGBAColor::CHANNEL_RED])) |
|
245 | + if (isset($color[RGBAColor::CHANNEL_RED])) |
|
246 | 246 | { |
247 | 247 | return $color; |
248 | 248 | } |
@@ -250,15 +250,15 @@ discard block |
||
250 | 250 | $values = array_values($color); |
251 | 251 | $result = array(); |
252 | 252 | |
253 | - foreach(self::$keys as $idx => $def) |
|
253 | + foreach (self::$keys as $idx => $def) |
|
254 | 254 | { |
255 | - if(isset($values[$idx])) |
|
255 | + if (isset($values[$idx])) |
|
256 | 256 | { |
257 | 257 | $result[$def['key']] = $values[$idx]; |
258 | 258 | continue; |
259 | 259 | } |
260 | 260 | |
261 | - if(!$def['mandatory']) |
|
261 | + if (!$def['mandatory']) |
|
262 | 262 | { |
263 | 263 | continue; |
264 | 264 | } |
@@ -363,23 +363,23 @@ discard block |
||
363 | 363 | public static function hsv2rgb(float $hue, float $saturation, float $brightness) : array |
364 | 364 | { |
365 | 365 | |
366 | - if($hue < 0) { $hue = 0.0; } // Hue: |
|
367 | - if($hue > 360) { $hue = 360.0; } // 0.0 to 360.0 |
|
368 | - if($saturation < 0) { $saturation = 0.0; } // Saturation: |
|
369 | - if($saturation > 100) { $saturation = 100.0; } // 0.0 to 100.0 |
|
370 | - if($brightness < 0) { $brightness = 0.0; } // Brightness: |
|
371 | - if($brightness > 100) { $brightness = 100.0; } // 0.0 to 100.0 |
|
372 | - |
|
373 | - $dS = $saturation/100.0; // Saturation: 0.0 to 1.0 |
|
374 | - $dV = $brightness/100.0; // Brightness: 0.0 to 1.0 |
|
375 | - $dC = $dV*$dS; // Chroma: 0.0 to 1.0 |
|
376 | - $dH = $hue/60.0; // H-Prime: 0.0 to 6.0 |
|
366 | + if ($hue < 0) { $hue = 0.0; } // Hue: |
|
367 | + if ($hue > 360) { $hue = 360.0; } // 0.0 to 360.0 |
|
368 | + if ($saturation < 0) { $saturation = 0.0; } // Saturation: |
|
369 | + if ($saturation > 100) { $saturation = 100.0; } // 0.0 to 100.0 |
|
370 | + if ($brightness < 0) { $brightness = 0.0; } // Brightness: |
|
371 | + if ($brightness > 100) { $brightness = 100.0; } // 0.0 to 100.0 |
|
372 | + |
|
373 | + $dS = $saturation / 100.0; // Saturation: 0.0 to 1.0 |
|
374 | + $dV = $brightness / 100.0; // Brightness: 0.0 to 1.0 |
|
375 | + $dC = $dV * $dS; // Chroma: 0.0 to 1.0 |
|
376 | + $dH = $hue / 60.0; // H-Prime: 0.0 to 6.0 |
|
377 | 377 | $dT = $dH; // Temp variable |
378 | 378 | |
379 | - while($dT >= 2.0) { $dT -= 2.0; } // php modulus does not work with float |
|
380 | - $dX = $dC*(1-abs($dT-1)); // as used in the Wikipedia link |
|
379 | + while ($dT >= 2.0) { $dT -= 2.0; } // php modulus does not work with float |
|
380 | + $dX = $dC * (1 - abs($dT - 1)); // as used in the Wikipedia link |
|
381 | 381 | |
382 | - switch(floor($dH)) { |
|
382 | + switch (floor($dH)) { |
|
383 | 383 | case 0: |
384 | 384 | $dR = $dC; $dG = $dX; $dB = 0.0; break; |
385 | 385 | case 1: |
@@ -330,12 +330,10 @@ |
||
330 | 330 | if ($R === $minRGB) |
331 | 331 | { |
332 | 332 | $h = 3 - (($G - $B) / $chroma); |
333 | - } |
|
334 | - elseif ($B === $minRGB) |
|
333 | + } elseif ($B === $minRGB) |
|
335 | 334 | { |
336 | 335 | $h = 1 - (($R - $G) / $chroma); |
337 | - } |
|
338 | - else |
|
336 | + } else |
|
339 | 337 | { // $G == $minRGB |
340 | 338 | $h = 5 - (($B - $R) / $chroma); |
341 | 339 | } |
@@ -135,7 +135,7 @@ |
||
135 | 135 | */ |
136 | 136 | public static function percent2Alpha(float $percent) : float |
137 | 137 | { |
138 | - return round($percent/100, self::$floatPrecision); |
|
138 | + return round($percent / 100, self::$floatPrecision); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | { |
40 | 40 | $value = (float)$value; |
41 | 41 | |
42 | - if($value < self::VALUE_MIN) { $value = self::VALUE_MIN; } |
|
43 | - if($value > self::VALUE_MAX) { $value = self::VALUE_MAX; } |
|
42 | + if ($value < self::VALUE_MIN) { $value = self::VALUE_MIN; } |
|
43 | + if ($value > self::VALUE_MAX) { $value = self::VALUE_MAX; } |
|
44 | 44 | |
45 | 45 | $this->value = $value; |
46 | 46 | } |
@@ -72,6 +72,6 @@ discard block |
||
72 | 72 | |
73 | 73 | public function invert() : PercentChannel |
74 | 74 | { |
75 | - return ColorChannel::percent(100-$this->value); |
|
75 | + return ColorChannel::percent(100 - $this->value); |
|
76 | 76 | } |
77 | 77 | } |