Completed
Push — master ( fad2ec...a017dd )
by Dmitry
03:58
created

NestedModelValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 19
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 12 3
1
<?php
2
3
namespace hiapi\validators;
4
5
use yii\base\InvalidParamException;
6
use yii\base\Model;
7
use yii\validators\Validator;
8
9
class NestedModelValidator extends Validator
10
{
11
    /**
12
     * @param Model $model
13
     * @return array|null
14
     */
15
    protected function validateValue($model)
16
    {
17
        if (!$model instanceof Model) {
18
            throw new InvalidParamException('Passed value must be instance of Model');
19
        }
20
21
        if (!$model->validate()) {
22
            return [reset($model->getFirstErrors()), []]; // todo: return more than one error
0 ignored issues
show
Bug introduced by
$model->getFirstErrors() cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
23
        }
24
25
        return null;
26
    }
27
}
28