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
Pull Request — master (#9)
by VEBER
01:51
created

AbstractDocument::toJson()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 0
crap 3
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 4
    public function toJson(): string
34
    {
35 4
        $document = [];
36
37 4
        foreach ($this->getFields() as $field) {
38 3
            if (!is_null($value = $this->$field)) {
39 3
                $document[$this->toSnakeCase($field)] = $this->$field;
40
            }
41
        }
42
43 4
        return json_encode($document);
44
    }
45
46
    /**
47
     * to snake case
48
     *
49
     * @param string $string
50
     *
51
     * @return string
52
     */
53 4
    protected function toSnakeCase(string $string): string
54
    {
55 4
        return mb_strtolower(preg_replace('/(.)(?=[A-Z])/', '$1_', $string));
56
    }
57
}
58