Skip to content

Commit 1d8d057

Browse files
committed
TASK: Fix bugs detected by phpstan
1 parent 29c0b43 commit 1d8d057

3 files changed

Lines changed: 41 additions & 27 deletions

File tree

Classes/Eel/ColorBuilder.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ public function hsl(int $hue, int $saturatiom, int $lightness, int $alpha = 100)
5656
public function hex(string $hex): ?ColorHelper
5757
{
5858
if (preg_match(self::PATTERN_HEX_SHORT, $hex, $matches)) {
59-
$red = hexdec($matches['red'].$matches['red']);
60-
$green = hexdec($matches['green'].$matches['green']);
61-
$blue = hexdec($matches['blue'].$matches['blue']);
62-
$alpha = hexdec(isset($matches['alpha']) ? $matches['alpha'].$matches['alpha'] : 1.0);
59+
$red = (int)hexdec($matches['red'].$matches['red']);
60+
$green = (int)hexdec($matches['green'].$matches['green']);
61+
$blue = (int)hexdec($matches['blue'].$matches['blue']);
62+
$alpha = (int)hexdec(isset($matches['alpha']) ? $matches['alpha'].$matches['alpha'] : "ff");
6363

6464
return new ColorHelper(
6565
new RgbaColor($red, $green, $blue, $alpha)
6666
);
6767
} elseif (preg_match(self::PATTERN_HEX_LONG, $hex, $matches)) {
68-
$red = hexdec($matches['red']);
69-
$green = hexdec($matches['green']);
70-
$blue = hexdec($matches['blue']);
71-
$alpha = hexdec($matches['alpha'] ?? 1);
68+
$red = (int)hexdec($matches['red']);
69+
$green = (int)hexdec($matches['green']);
70+
$blue = (int)hexdec($matches['blue']);
71+
$alpha = (int)hexdec($matches['alpha'] ?? "ff");
7272

7373
return new ColorHelper(
7474
new RgbaColor($red, $green, $blue, $alpha)
@@ -88,19 +88,19 @@ public function hex(string $hex): ?ColorHelper
8888
public function css(string $colorString): ?ColorHelper
8989
{
9090
if (preg_match(self::PATTERN_HEX_SHORT, $colorString, $matches)) {
91-
$red = hexdec($matches['red'].$matches['red']);
92-
$green = hexdec($matches['green'].$matches['green']);
93-
$blue = hexdec($matches['blue'].$matches['blue']);
94-
$alpha = hexdec(isset($matches['alpha']) ? $matches['alpha'].$matches['alpha'] : 1.0);
91+
$red = (int)hexdec($matches['red'].$matches['red']);
92+
$green = (int)hexdec($matches['green'].$matches['green']);
93+
$blue = (int)hexdec($matches['blue'].$matches['blue']);
94+
$alpha = (int)hexdec(isset($matches['alpha']) ? $matches['alpha'].$matches['alpha'] : "ff");
9595

9696
return new ColorHelper(
9797
new RgbaColor($red, $green, $blue, $alpha)
9898
);
9999
} elseif (preg_match(self::PATTERN_HEX_LONG, $colorString, $matches)) {
100-
$red = hexdec($matches['red']);
101-
$green = hexdec($matches['green']);
102-
$blue = hexdec($matches['blue']);
103-
$alpha = hexdec($matches['alpha'] ?? 1);
100+
$red = (int)hexdec($matches['red']);
101+
$green = (int)hexdec($matches['green']);
102+
$blue = (int)hexdec($matches['blue']);
103+
$alpha = (int)hexdec($matches['alpha'] ? $matches['alpha'] : "ff");
104104

105105
return new ColorHelper(
106106
new RgbaColor($red, $green, $blue, $alpha)

Classes/Eel/ColorHelper.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,50 @@ public function __construct(ColorInterface $color)
2222
$this->color = $color;
2323
}
2424

25+
/**
26+
* @return ColorInterface
27+
*/
2528
public function getColor(): ColorInterface
2629
{
2730
return $this->color;
2831
}
2932

33+
/**
34+
* @return string
35+
*/
3036
public function __toString(): string
3137
{
3238
return $this->color->getHexString();
3339
}
3440

41+
/**
42+
* @return string
43+
*/
3544
public function rgb(): string
3645
{
3746
return $this->color->getRgbaString();
3847
}
3948

49+
/**
50+
* @return string
51+
*/
4052
public function hsl(): string
4153
{
4254
return $this->color->getHslaString();
4355
}
4456

57+
/**
58+
* @return string
59+
*/
4560
public function hex(): string
4661
{
4762
return $this->color->getHexString();
4863
}
4964

5065
/**
5166
* @param ColorHelper $color
52-
* @param int $weight between 0 and 100
53-
*
54-
* @return string
67+
* @param int $weight
68+
* @return ColorHelper
5569
*/
5670
public function mix(self $color, int $weight = 50): self
5771
{
@@ -61,7 +75,7 @@ public function mix(self $color, int $weight = 50): self
6175
/**
6276
* @param int $amount between 0 and 100
6377
*
64-
* @return string
78+
* @return ColorHelper
6579
*/
6680
public function lighten(int $amount = self::DEFAULT_ADJUSTMENT): self
6781
{
@@ -71,7 +85,7 @@ public function lighten(int $amount = self::DEFAULT_ADJUSTMENT): self
7185
/**
7286
* @param int $amount between 0 and 100
7387
*
74-
* @return string
88+
* @return ColorHelper
7589
*/
7690
public function darken(int $amount = self::DEFAULT_ADJUSTMENT): self
7791
{
@@ -83,7 +97,7 @@ public function darken(int $amount = self::DEFAULT_ADJUSTMENT): self
8397
*
8498
* @param int $amount degrees to rotate the color
8599
*
86-
* @return string
100+
* @return ColorHelper
87101
*/
88102
public function spin(int $amount): self
89103
{
@@ -93,7 +107,7 @@ public function spin(int $amount): self
93107
/**
94108
* @param int $amount to saturate the color
95109
*
96-
* @return string
110+
* @return ColorHelper
97111
*/
98112
public function saturate(int $amount = self::DEFAULT_ADJUSTMENT): self
99113
{
@@ -103,7 +117,7 @@ public function saturate(int $amount = self::DEFAULT_ADJUSTMENT): self
103117
/**
104118
* @param int $amount to desaturate the color
105119
*
106-
* @return string
120+
* @return ColorHelper
107121
*/
108122
public function desaturate(int $amount = self::DEFAULT_ADJUSTMENT): self
109123
{
@@ -113,7 +127,7 @@ public function desaturate(int $amount = self::DEFAULT_ADJUSTMENT): self
113127
/**
114128
* @param int $amount to desaturate the color
115129
*
116-
* @return string
130+
* @return ColorHelper
117131
*/
118132
public function fadein(int $amount = self::DEFAULT_ADJUSTMENT): self
119133
{
@@ -123,7 +137,7 @@ public function fadein(int $amount = self::DEFAULT_ADJUSTMENT): self
123137
/**
124138
* @param int $amount to desaturate the color
125139
*
126-
* @return string
140+
* @return ColorHelper
127141
*/
128142
public function fadeout(int $amount = self::DEFAULT_ADJUSTMENT): self
129143
{

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
],
3131
"test:phpstan": [
3232
"composer test:prepare",
33-
"Build/Travis/bin/phpstan analyse Build/Travis/Packages/Application/PackageFactory.ColorHelper/Classes"
33+
"Build/Travis/bin/phpstan analyse --level 8 Build/Travis/Packages/Application/PackageFactory.ColorHelper/Classes"
3434
],
3535
"test:unit": [
3636
"composer test:prepare",

0 commit comments

Comments
 (0)