Skip to content

Commit

Permalink
Merge pull request #254 from henriquemoody/HexRgbColor
Browse files Browse the repository at this point in the history
Remove unnecessary code from `hexRgbColor()` rule
  • Loading branch information
henriquemoody committed Jan 18, 2015
2 parents e2bdab4 + 10b58f8 commit 856d8fd
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions library/Rules/HexRgbColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,23 @@

use Respect\Validation\Validator as v;

class HexRgbColor extends AbstractRule
class HexRgbColor extends Xdigit
{
public function validate($input)
{
if (v::oneOf(v::object(), v::arr(), v::nullValue(), v::not(v::string()))->validate($input)) {
if (!is_string($input)) {
return false;
}

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

$length = strlen($input) - 1;

$length = strlen($input);
if ($length != 3 && $length != 6) {
return false;
}

$hexdec = hexdec(substr($input, 1));

return v::xdigit()->validate(substr($input, 1))
&& $hexdec < 16777216 && $hexdec >= 0;
return parent::validate($input);
}
}

0 comments on commit 856d8fd

Please sign in to comment.