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.

Accessor::readValue()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
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 12
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
        }
36 2
        if (\is_object($arrayOrObject)) {
37 2
            $method = $this->getMethod($arrayOrObject, $property);
38
39 2
            return $method ? $arrayOrObject->$method() : false;
40
        }
41
42
        return false;
43
    }
44
45 2
    public function writeValue(&$arrayOrObject, $property, $value)
46
    {
47 2
        if (\is_array($arrayOrObject)) {
48
            $arrayOrObject[$property] = $value;
49 2
        } elseif (\is_object($arrayOrObject)) {
50 2
            $method = $this->getMethod($arrayOrObject, $property, self::MODE_WRITE);
51 2
            false === $method ?: $arrayOrObject->$method($value);
52
        }
53 2
    }
54
55 4
    public function camelize(string $string): string
56
    {
57 4
        return str_replace('_', '', ucwords($string, '_'));
58
    }
59
60 4
    private function getMethod($target, $property, $mode = self::MODE_READ)
61
    {
62 4
        $camelized = $this->camelize($property);
63
64 4
        foreach (self::PREFIXES[$mode] as $prefix) {
65 4
            $method = $prefix === self::NO_PREF ? lcfirst($camelized) : $prefix.$camelized;
66 4
            if (method_exists($target, $method)) {
67 4
                return $method;
68
            }
69
        }
70
71 2
        return false;
72
    }
73
}
74