Length::isValid()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 3
nc 3
nop 2
crap 3
1
<?php
2
3
namespace WebStream\Annotation\Attributes\Ext\ValidateRule;
4
5
/**
6
 * Length
7
 * @author Ryuichi TANAKA.
8
 * @since 2015/03/30
9
 * @version 0.4
10
 */
11
class Length implements IValidate
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16 8
    public function isValid($value, string $rule)
17
    {
18 8
        $isValid = false;
19 8
        if (preg_match('/^length\[(0|[1-9]\d*)\]$/', $rule, $matches)) {
20 8
            $isValid = $value === null || mb_strlen($value, "UTF-8") === intval($matches[1]);
21
        }
22
23 8
        return $isValid;
24
    }
25
}
26