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::contains()   B
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 16
cts 16
cp 1
rs 8.5906
c 0
b 0
f 0
cc 5
eloc 13
nc 7
nop 3
crap 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