Completed
Pull Request — master (#2)
by Štefan
03:07
created

HexadecimalTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateHexadecimal() 0 13 2
1
<?php
2
3
4
namespace Webcore\Validation\Rules;
5
6
7
use Webcore\Validation\AbstractRuleTrait;
8
9
trait HexadecimalTrait
10
{
11
    use AbstractRuleTrait;
12
13
    /**
14
     * Allowed characters: 0-9, a-f, A-F
15
     *
16
     * @param $value
17
     */
18
    private function validateHexadecimal($value)
19
    {
20
        $isValid = filter_var(
21
            $value,
22
            FILTER_VALIDATE_REGEXP,
23
            array(
24
                "options" => array("regexp" => '`^[0-9A-Fa-f]+$`')
25
            )
26
        );
27
        if ($isValid === false) {
28
            $this->throwInvalidArgumentMustBe("valid hexadecimal");
29
        }
30
    }
31
}
32