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 ( 8db0fd...b49a60 )
by Benjamin
02:45
created

Accessor::getMethod()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 3
dl 0
loc 21
ccs 12
cts 12
cp 1
crap 3
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
namespace Lib\Access;
4
5
class Accessor
6
{
7
    const MODE_READ = 0;
8
    const MODE_WRITE = 1;
9
10
    const PREF_GET = "get";
11
    const PREF_HAS = "has";
12
    const PREF_IS = "is";
13
    const PREF_SET = "set";
14
15 2
    public function readValue($arrayOrObject, $property)
16
    {
17 2
        if (\is_array($arrayOrObject)) {
18
            return $arrayOrObject[$property];
19 2
        } elseif (\is_object($arrayOrObject)) {
20 2
            $method = $this->getMethod($arrayOrObject, $property);
21 2
            return $method ? $arrayOrObject->$method() : false;
22
        } else {
23
            return false;
24
        }
25
    }
26
27 2
    public function writeValue(&$arrayOrObject, $property, $value)
28
    {
29 2
        if (\is_array($arrayOrObject)) {
30
            $arrayOrObject[$property] = $value;
31 2
        } elseif (\is_object($arrayOrObject)) {
32 2
            $method = $this->getMethod($arrayOrObject, $property, self::MODE_WRITE);
33 2
            false === $method ?: $arrayOrObject->$method($value);
34
        }
35 2
    }
36
37 4
    private function getMethod($target, $property, $mode = self::MODE_READ)
38
    {
39 4
        $camelized = $this->camelize($property);
40
41
        $methods = [
42 4
            self::MODE_READ  => [
43 4
                self::PREF_GET.$camelized => self::PREF_GET.$camelized,
44 4
                self::PREF_HAS.$camelized => self::PREF_HAS.$camelized,
45 4
                self::PREF_IS.$camelized  => self::PREF_IS.$camelized,
46
            ],
47 4
            self::MODE_WRITE => [
48 4
                self::PREF_SET.$camelized => self::PREF_SET.$camelized,
49
            ]
50
        ];
51
52 4
        foreach ($methods[$mode] as $name => $method) {
53 4
            if (method_exists($target, $method)) {
54 4
                return $method;
55
            }
56
        }
57 2
        return false;
58
    }
59
60 4
    public function camelize($string)
61
    {
62 4
        return str_replace('_', '', ucwords($string, '_'));
63
    }
64
}
65