HexadecimalTrait::validateHexadecimal()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 10
cp 0.9
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2.004
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 14
    private function validateHexadecimal($value)
19
    {
20 14
        $isValid = filter_var(
21 14
            $value,
22 14
            FILTER_VALIDATE_REGEXP,
23
            array(
24 14
                "options" => array("regexp" => '`^[0-9A-Fa-f]+$`'),
25
            )
26 14
        );
27 14
        if ($isValid === false) {
28 9
            $this->throwInvalidArgumentMustBe("valid hexadecimal");
29
        }
30 5
    }
31
}
32