Skip to content

Commit 856d8fd

Browse files
committed
Merge pull request #254 from henriquemoody/HexRgbColor
Remove unnecessary code from `hexRgbColor()` rule
2 parents e2bdab4 + 10b58f8 commit 856d8fd

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

library/Rules/HexRgbColor.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,23 @@
33

44
use Respect\Validation\Validator as v;
55

6-
class HexRgbColor extends AbstractRule
6+
class HexRgbColor extends Xdigit
77
{
88
public function validate($input)
99
{
10-
if (v::oneOf(v::object(), v::arr(), v::nullValue(), v::not(v::string()))->validate($input)) {
10+
if (!is_string($input)) {
1111
return false;
1212
}
1313

14-
if (!v::startsWith('#')->validate($input)) {
15-
$input = '#'.$input;
14+
if (0 === strpos($input, '#')) {
15+
$input = substr($input, 1);
1616
}
1717

18-
$length = strlen($input) - 1;
19-
18+
$length = strlen($input);
2019
if ($length != 3 && $length != 6) {
2120
return false;
2221
}
2322

24-
$hexdec = hexdec(substr($input, 1));
25-
26-
return v::xdigit()->validate(substr($input, 1))
27-
&& $hexdec < 16777216 && $hexdec >= 0;
23+
return parent::validate($input);
2824
}
2925
}

0 commit comments

Comments
 (0)