GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ArrayComparison   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 76
ccs 24
cts 24
cp 1
rs 10
c 2
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isIn() 0 4 1
A isNotIn() 0 4 1
A intersect() 0 4 1
A doNotIntersect() 0 4 1
B contains() 0 23 5
1
<?php
2
3
namespace PhpAbac\Comparison;
4
5
class ArrayComparison extends AbstractComparison
6
{
7
    /**
8
     * @param array $haystack
9
     * @param mixed  $needle
10
     *
11
     * @return bool
12
     */
13 3
    public function isIn($haystack, $needle)
14
    {
15 3
        return in_array($needle, $haystack);
16
    }
17
18
    /**
19
     * @param array $haystack
20
     * @param mixed  $needle
21
     *
22
     * @return bool
23
     */
24 1
    public function isNotIn($haystack, $needle)
25
    {
26 1
        return !$this->isIn($haystack, $needle);
27
    }
28
29
    /**
30
     * @param array $array1
31
     * @param array $array2
32
     *
33
     * @return bool
34
     */
35 2
    public function intersect($array1, $array2)
36
    {
37 2
        return count(array_intersect($array1, $array2)) > 0;
38
    }
39
40
    /**
41
     * @param array $array1
42
     * @param array $array2
43
     *
44
     * @return bool
45
     */
46 1
    public function doNotIntersect($array1, $array2)
47
    {
48 1
        return !$this->intersect($array1, $array2);
49
    }
50
51
    /**
52
     * @param array $policyRuleAttributes
53
     * @param array $attributes
54
     * @param array $extraData
55
     * @return boolean
56
     */
57 4
    public function contains($policyRuleAttributes, $attributes, $extraData = []) {
0 ignored issues
show
Unused Code introduced by
The parameter $attributes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58 4
        foreach($extraData['attribute']->getValue() as $attribute) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FOREACH keyword; 0 found
Loading history...
59 4
            $result = true;
60
            // For each attribute, we check the whole rules set
61 4
            foreach($policyRuleAttributes as $pra) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FOREACH keyword; 0 found
Loading history...
62 4
                $attributeData = $pra->getAttribute();
63 4
                $attributeData->setValue(
64 4
                    $this->comparisonManager->getAttributeManager()->retrieveAttribute($attributeData, $extraData['user'], $attribute)
65 4
                );
66
                // If one field is not matched, the whole attribute is rejected
67 4
                if(!$this->comparisonManager->compare($pra, true)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
68
                    //var_dump($attributeData->getName(), $attributeData->getValue(), $pra->getValue());
69 2
                    $result = false;
70 2
                    break;
71
                }
72 4
            }
73
            // If the result is still true at the end of the attribute check, the rule is enforced
74 4
            if($result === true) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
75 4
                return true;
76
            }
77 4
        }
78 4
        return false;
79
    }
80
}
81