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

NestedModelValidator::validateValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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