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 ( 798bff...8db0fd )
by Benjamin
02:46
created

Accessor   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 91.18%

Importance

Changes 0
Metric Value
dl 0
loc 64
ccs 31
cts 34
cp 0.9118
rs 10
c 0
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A readValue() 0 9 4
A writeValue() 0 7 4
B getMethod() 0 27 3
A camelize() 0 3 1
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
        $methods = [
43 4
            self::MODE_READ  => [
44 4
                self::PREF_GET.$camelized => self::PREF_GET.$camelized,
45 4
                self::PREF_HAS.$camelized => self::PREF_HAS.$camelized,
46 4
                self::PREF_IS.$camelized  => self::PREF_IS.$camelized,
47 4
                lcfirst($camelized)       => lcfirst($camelized),
48 4
                '__'.self::PREF_GET       => self::PREF_GET.$camelized,
49 4
                '__call'                  => self::PREF_GET.$camelized
50
            ],
51 4
            self::MODE_WRITE => [
52 4
                self::PREF_SET.$camelized => self::PREF_SET.$camelized,
53 4
                '__'.self::PREF_SET       => self::PREF_SET.$camelized,
54 4
                '__call'                  => self::PREF_SET.$camelized
55
            ]
56
        ];
57
58 4
        foreach ($methods[$mode] as $name => $method) {
59 4
            if ($refObject->hasMethod($name)) {
60 4
                return $method;
61
            }
62
        }
63 2
        return false;
64
    }
65
66 4
    public function camelize($string)
67
    {
68 4
        return str_replace('_', '', ucwords($string, '_'));
69
    }
70
}
71