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 ( 1e068f...798bff )
by Benjamin
02:26
created

Accessor::getMethod()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 21
nc 3
nop 3
dl 0
loc 31
ccs 21
cts 21
cp 1
crap 3
rs 8.8571
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
        $refObject = new \ReflectionClass(get_class($target));
40 4
        $camelized = $this->camelize($property);
41
42 4
        $magicGet  = '__'.self::PREF_GET;
43 4
        $magicSet  = '__'.self::PREF_SET;
44 4
        $magicCall = '__call';
45
46
        $methods = [
47 4
            self::MODE_READ  => [
48 4
                self::PREF_GET.$camelized => self::PREF_GET.$camelized,
49 4
                self::PREF_HAS.$camelized => self::PREF_HAS.$camelized,
50 4
                self::PREF_IS.$camelized  => self::PREF_IS.$camelized,
51 4
                lcfirst($camelized)       => lcfirst($camelized),
52 4
                $magicGet                 => self::PREF_GET.$camelized,
53 4
                $magicCall                => self::PREF_GET.$camelized
54
            ],
55 4
            self::MODE_WRITE => [
56 4
                self::PREF_SET.$camelized => self::PREF_SET.$camelized,
57 4
                $magicSet                 => self::PREF_SET.$camelized,
58 4
                $magicCall                => self::PREF_SET.$camelized
59
            ]
60
        ];
61
62 4
        foreach ($methods[$mode] as $name => $method) {
63 4
            if ($refObject->hasMethod($name)) {
64 4
                return $method;
65
            }
66
        }
67 2
        return false;
68
    }
69
70 4
    public function camelize($string)
71
    {
72 4
        return str_replace('_', '', ucwords($string, '_'));
73
    }
74
}
75