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 ( 2b0490...beaba1 )
by VEBER
15s
created

AbstractDocument::toJson()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 8.5125
c 0
b 0
f 0
cc 5
eloc 12
nc 5
nop 0
crap 5
1
<?php
2
3
/*
4
 * This file is part of the KongAdminApi package.
5
 *
6
 * (c) Unikorp <https://github.com/unikorp>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Unikorp\KongAdminApi;
13
14
/**
15
 * abstract document
16
 *
17
 * @author VEBER Arnaud <https://github.com/VEBERArnaud>
18
 */
19
abstract class AbstractDocument implements DocumentInterface
20
{
21
    /**
22
     * get fields
23
     *
24
     * @return array
25
     */
26
    abstract protected function getFields(): array;
27
28
    /**
29
     * to json
30
     *
31
     * @return string
32
     */
33 5
    public function toJson(): string
34
    {
35 5
        $document = [];
36
37 5
        foreach ($this->getFields() as $field) {
38 4
            $value = $this->$field;
39
40 4
            if (is_null($value)) {
41 1
                continue;
42
            }
43
44 4
            if (is_array($value)) {
45 1
                foreach (array_keys($value) as $key) {
46 1
                    $document[sprintf('%1$s.%2$s', $field, $key)] = $value[$key];
47
                }
48
49 1
                continue;
50
            }
51
52 4
            $document[$this->toSnakeCase($field)] = $this->$field;
53
        }
54
55 5
        return json_encode($document);
56
    }
57
58
    /**
59
     * to snake case
60
     *
61
     * @param string $string
62
     *
63
     * @return string
64
     */
65 4
    private function toSnakeCase(string $string): string
66
    {
67 4
        return mb_strtolower(preg_replace('/(.)(?=[A-Z])/', '$1_', $string));
68
    }
69
}
70