ValidatorAwareTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addValidator() 0 5 1
A isValid() 0 9 3
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Session
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Session\Traits;
16
17
use Phossa2\Session\Interfaces\ValidatorInterface;
18
use Phossa2\Session\Interfaces\ValidatorAwareInterface;
19
20
/**
21
 * ValidatorAwareTrait
22
 *
23
 * @package Phossa2\Session
24
 * @author  Hong Zhang <[email protected]>
25
 * @see     ValidatorAwareInterface
26
 * @version 2.1.0
27
 * @since   2.1.0 added
28
 */
29
trait ValidatorAwareTrait
30
{
31
    /**
32
     * @var    ValidatorInterface[]
33
     * @access protected
34
     */
35
    protected $validators = [];
36
37
    /**
38
     * {@inheritDoc}
39
     */
40
    public function addValidator(ValidatorInterface $validator)
41
    {
42
        $this->validators[] = $validator;
43
        return $this;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function isValid()/*# : bool */
50
    {
51
        foreach ($this->validators as $val) {
52
            if (!$val->validate()) {
53
                return false;
54
            }
55
        }
56
        return true;
57
    }
58
}
59