OrVoter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 30
Duplicated Lines 43.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
c 2
b 0
f 1
lcom 1
cbo 2
dl 13
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A result() 13 13 4
A supports() 0 14 4

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 OrVoter extends VoterAbstract {
6 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...
7
        foreach ($this->conditions as $condition) {
8
            $result = $condition->result($entity);
9
10
            $this->logger->debug(sprintf('Condition "%s" returned result: %s', (string)$condition, $result ? 'true' : 'false'));
11
12
            if ($result == true) {
13
                return true;
14
            }
15
        }
16
17
        return false;
18
    }
19
20
    public function supports($entities)
21
    {
22
        if (!is_array($entities)) {
23
            $entities = [$entities];
24
        }
25
26
        foreach ($this->conditions as $condition) {
27
            if (!array_diff((array)$condition->requires(), $entities)) {
28
                return true;
29
            }
30
        }
31
32
        return false;
33
    }
34
}
35