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.
Completed
Push — master ( ca9b69...35d367 )
by Axel
03:00
created

ComparisonManager::compare()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 5
cts 7
cp 0.7143
rs 9.4285
cc 3
eloc 7
nc 3
nop 5
crap 3.2098
1
<?php
2
3
namespace PhpAbac\Manager;
4
5
use PhpAbac\Comparison\ArrayComparison;
6
use PhpAbac\Comparison\BooleanComparison;
7
use PhpAbac\Comparison\DatetimeComparison;
8
use PhpAbac\Comparison\NumericComparison;
9
use PhpAbac\Comparison\StringComparison;
10
11
class ComparisonManager {
12
    /** @var \PhpAbac\Manager\AttributeManager **/
13
    protected $attributeManager;
14
    /** @var array **/
15
    protected $comparisons = [
16
        'array' => ArrayComparison::class,
17
        'boolean' => BooleanComparison::class,
18
        'datetime' => DatetimeComparison::class,
19
        'numeric' => NumericComparison::class,
20
        'string' => StringComparison::class,
21
    ];
22
    
23
    /**
24
     * @param \PhpAbac\Manager\AttributeManager $manager
25
     */
26 16
    public function __construct(AttributeManager $manager) {
27 16
        $this->attributeManager = $manager;
28 16
    }
29
    
30
    /**
31
     * @param string $type
32
     * @param string $method
33
     * @param mixed $expectedValue
34
     * @param mixed $value
35
     * @param array $extraData
36
     * @return bool
37
     */
38 2
    public function compare($type, $method, $expectedValue, $value, $extraData = []) {
39 2
        if(!isset($this->comparisons[$type])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
40
            throw new \InvalidArgumentException('The requested comparison class does not exist');
41
        }
42 2
        $comparison = new $this->comparisons[$type]($this);
43 2
        if(!method_exists($comparison, $method)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
44
            throw new \InvalidArgumentException('The requested comparison method does not exist');
45
        }
46 2
        return $comparison->{$method}($expectedValue, $value, $extraData);
47
    }
48
    
49
    /**
50
     * @param string $type
51
     * @param string $class
52
     */
53
    public function addComparison($type, $class) {
54
        $this->comparisons[$type] = $class;
55
    }
56
    
57
    /**
58
     * @return \PhpAbac\Manager\AttributeManager
59
     */
60 2
    public function getAttributeManager() {
61 2
        return $this->attributeManager;
62
    }
63
}