ValidHexColor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 16
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A message() 0 3 1
A passes() 0 3 1
1
<?php
2
3
namespace Milwad\LaravelValidate\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class ValidHexColor implements Rule
8
{
9
    /**
10
     * Check hex color is valid.
11
     */
12
    public function passes($attribute, $value): bool
13
    {
14
        return preg_match('/^#?(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/', $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match('/^#?(...A-F0-9]{3})$/', $value) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
15
    }
16
17
    /**
18
     * Get the validation error message.
19
     */
20
    public function message(): string
21
    {
22
        return __('validate.hex-color');
23
    }
24
}
25