AndVoter   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 54
Duplicated Lines 27.78 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 11
c 4
b 2
f 1
lcom 1
cbo 2
dl 15
loc 54
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A result() 15 15 4
B supports() 0 22 5
A getRequirements() 0 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Vivait\Voter\Voter;
4
5
class AndVoter extends VoterAbstract
6
{
7 View Code Duplication
    public function result($entity)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
    {
9
        foreach ($this->conditions as $condition) {
10
            $result = $condition->result($entity);
11
            $this->logger->debug(
12
              sprintf('Condition "%s" returned result: %s', (string)$condition, $result ? 'true' : 'false')
13
            );
14
15
            if ($result == false) {
16
                return false;
17
            }
18
        }
19
20
        return true;
21
    }
22
23
    public function supports($entities)
24
    {
25
        if (!is_array($entities)) {
26
            $entities = [$entities];
27
        }
28
29
        $requirements = $this->getRequirements();
30
31
        // Loop through each requirement
32
        foreach ($requirements as $requirement) {
33
34
            foreach ($entities as $entity) {
35
                if ($entity instanceOf $requirement) {
36
                    continue 2;
37
                }
38
            }
39
40
            return false;
41
        }
42
43
        return true;
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    private function getRequirements()
50
    {
51
        $requirements = [];
52
        foreach ($this->conditions as $condition) {
53
            $requirements = array_merge($requirements, $condition->requires());
54
        }
55
56
        return $requirements;
57
    }
58
}
59