Skip to content

Commit

Permalink
fix bug & doc types color validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jturbide committed Feb 21, 2024
1 parent 9d1088d commit a24d5d5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Filter/Validation/Validator/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class Color extends AbstractValidator implements ValidatorInterface
protected $template = 'Field :field must be a valid color in hexadecimal format (e.g., #RRGGBB)';

/**
* Constructor
*
* @param array options = [
* @param array $options = [
* 'message' => '',
* 'template' => '',
* 'allowEmpty' => false
Expand All @@ -28,7 +26,7 @@ public function validate(Validation $validation, $field): bool
{
$value = $validation->getValue($field);

if (!$this->isValidColor($value)) {
if (!is_string($value) || !$this->isValidColor($value)) {

$validation->appendMessage(
$this->messageFactory($validation, $field)
Expand All @@ -43,7 +41,7 @@ public function validate(Validation $validation, $field): bool
/**
* Check if a given color is in a valid hexadecimal format.
*/
private function isValidColor(?string $color): bool
private function isValidColor(string $color): bool
{
// Hexadecimal color regex pattern (supports 3, 4, 6, or 8 digits)
$pattern = '/^#([A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/';
Expand Down

0 comments on commit a24d5d5

Please sign in to comment.