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

AttributeValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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