Completed
Push — master ( 6373f2...b930c3 )
by Dmitry
02:29
created

AttributeValidator::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
namespace hiapi\validators;
4
5
class AttributeValidator implements \hiapi\validators\NormalizerInterface
6
{
7
    /**
8
     * @var \yii\validators\Validator
9
     */
10
    private $realValidator;
11
12
    public function __construct($realValidator)
13
    {
14
        $this->realValidator = $realValidator;
15
    }
16
17
    public function validate($value)
18
    {
19
        $result = $this->realValidator->validate($value);
20
21
        if ($result !== true) {
22
            throw \hiapi\validators\AttributeValidationException::forValue($value, $result);
23
        }
24
    }
25
26
    public function normalize($value)
27
    {
28
        if ($this->realValidator instanceof \hiapi\validators\NormalizerInterface) {
29
            $value = $this->realValidator->normalize($value);
30
        }
31
32
        return $value;
33
    }
34
}
35