VoterAbstract   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 68
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A addConditions() 0 8 2
A addCondition() 0 6 1
A getConditions() 0 4 1
A removeCondition() 0 6 1
1
<?php
2
3
namespace Vivait\Voter\Voter;
4
5
use Psr\Log\LoggerInterface;
6
use Psr\Log\NullLogger;
7
use Vivait\Voter\Model\ConditionInterface;
8
use Vivait\Voter\Model\VoterInterface;
9
10
abstract class VoterAbstract implements VoterInterface {
11
12
    /**
13
     * @var \SplObjectStorage|\Vivait\Voter\Model\ConditionInterface[]
14
     */
15
    protected $conditions;
16
17
    /**
18
     * @var LoggerInterface
19
     */
20
    protected $logger;
21
22
    public function __construct(array $conditions = array(), LoggerInterface $logger = null)
23
    {
24
        $this->conditions = new \SplObjectStorage();
25
        $this->addConditions($conditions);
26
27
        if (!$logger) {
28
            $logger = new NullLogger();
29
        }
30
31
        $this->logger = $logger;
32
    }
33
34
    /**
35
     * @param array $conditions
36
     * @return $this
37
     */
38
    public function addConditions(array $conditions)
39
    {
40
        foreach ($conditions as $condition) {
41
            $this->addCondition($condition);
42
        }
43
44
        return $this;
45
    }
46
47
    /**
48
     * @param ConditionInterface $condition
49
     * @return $this
50
     */
51
    public function addCondition(ConditionInterface $condition)
52
    {
53
        $this->conditions->attach($condition, $condition->requires());
54
55
        return $this;
56
    }
57
58
    /**
59
     * @return \SplObjectStorage|\Vivait\Voter\Model\ConditionInterface[]
60
     */
61
    public function getConditions()
62
    {
63
        return $this->conditions;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->conditions; of type SplObjectStorage|Vivait\...el\ConditionInterface[] adds the type Vivait\Voter\Model\ConditionInterface[] to the return on line 63 which is incompatible with the return type declared by the interface Vivait\Voter\Model\VoterInterface::getConditions of type SplObjectStorage|Vivait\...er\ConditionInterface[].
Loading history...
64
    }
65
66
    /**
67
     * @param ConditionInterface $condition
68
     * @return $this
69
     */
70
    public function removeCondition(ConditionInterface $condition)
71
    {
72
        $this->conditions->detach($condition);
73
74
        return $this;
75
    }
76
77
}
78