mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Minor refactoring
This commit is contained in:
@@ -776,10 +776,7 @@ class Regex
|
|||||||
*/
|
*/
|
||||||
public static function getValidColorHexValue($color, $throwException = true)
|
public static function getValidColorHexValue($color, $throwException = true)
|
||||||
{
|
{
|
||||||
/*
|
// Not a scalar value?
|
||||||
* Not a scalar value?
|
|
||||||
* Nothing to do
|
|
||||||
*/
|
|
||||||
if (!is_scalar($color)) {
|
if (!is_scalar($color)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -787,10 +784,7 @@ class Regex
|
|||||||
$color = Miscellaneous::replace($color, '/#/', '');
|
$color = Miscellaneous::replace($color, '/#/', '');
|
||||||
$length = strlen($color);
|
$length = strlen($color);
|
||||||
|
|
||||||
/*
|
// Color hasn't 3 or 6 characters length?
|
||||||
* Color is not 3 or 6 characters long?
|
|
||||||
* Nothing to do
|
|
||||||
*/
|
|
||||||
if (3 !== $length && 6 !== $length) {
|
if (3 !== $length && 6 !== $length) {
|
||||||
if ($throwException) {
|
if ($throwException) {
|
||||||
throw new IncorrectColorHexLengthException($color);
|
throw new IncorrectColorHexLengthException($color);
|
||||||
@@ -799,10 +793,7 @@ class Regex
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Make the color 6 characters length, if has 3
|
||||||
* Color is 3 characters long?
|
|
||||||
* Let's make it 6 characters long
|
|
||||||
*/
|
|
||||||
if (3 === $length) {
|
if (3 === $length) {
|
||||||
$color = Miscellaneous::replace($color, '/(.)(.)(.)/', '$1$1$2$2$3$3');
|
$color = Miscellaneous::replace($color, '/(.)(.)(.)/', '$1$1$2$2$3$3');
|
||||||
}
|
}
|
||||||
@@ -810,19 +801,16 @@ class Regex
|
|||||||
$pattern = self::$patterns['color'];
|
$pattern = self::$patterns['color'];
|
||||||
$match = (bool)preg_match($pattern, $color);
|
$match = (bool)preg_match($pattern, $color);
|
||||||
|
|
||||||
/*
|
// It's not a valid color
|
||||||
* It's valid color
|
if (!$match) {
|
||||||
* Nothing to do more
|
if ($throwException) {
|
||||||
*/
|
throw new InvalidColorHexValueException($color);
|
||||||
if ($match) {
|
}
|
||||||
return strtolower($color);
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($throwException) {
|
return strtolower($color);
|
||||||
throw new InvalidColorHexValueException($color);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user