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

AttributeValidator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 30
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 8 2
A normalize() 0 8 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