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 ( 9d9f32...f9e1a4 )
by Benjamin
02:15
created

Accessor::readValue()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.3731

Importance

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