ModelValidator::validate()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 4
nop 0
dl 0
loc 20
rs 9.5555
c 0
b 0
f 0
1
<?php
2
3
namespace Charcoal\Model;
4
5
// From 'charcoal-core'
6
use Charcoal\Validator\AbstractValidator;
7
8
/**
9
 *
10
 */
11
class ModelValidator extends AbstractValidator
12
{
13
    /**
14
     * @return boolean
15
     */
16
    public function validate()
17
    {
18
        $model = $this->model;
19
20
        $props = $model->properties();
0 ignored issues
show
Bug introduced by
The method properties() does not exist on Charcoal\Validator\ValidatableInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Charcoal\Tests\Mock\ValidatableClass. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        /** @scrutinizer ignore-call */ 
21
        $props = $model->properties();
Loading history...
21
22
        $ret = true;
23
        foreach ($props as $ident => $p) {
24
            if (!$p ||  !$p->active()) {
25
                continue;
26
            }
27
            $valid = $p->validate();
28
            if ($valid === false) {
29
                $validator = $p->validator();
30
                $this->merge($validator, $ident);
31
                $ret = false;
32
            }
33
        }
34
35
        return $ret;
36
    }
37
}
38