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 ( 0ee850...2eefd2 )
by VEBER
18s
created

AbstractDocument::setCreatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
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
     * default fields
23
     * @const array DEFAULT_FIELDS
24
     */
25
    const DEFAULT_FIELDS = ['createdAt'];
26
27
    /**
28
     * created at
29
     * @param int $createdAt
30
     */
31
    protected $createdAt = null;
32
33
    /**
34
     * get fields
35
     *
36
     * @return array
37
     */
38
    abstract protected function getFields(): array;
39
40
    /**
41
     * set created at
42
     *
43
     * @param int $createdAt
44
     *
45
     * @return this
46
     */
47 9
    public function setCreatedAt($createdAt)
48
    {
49 9
        $this->createdAt = $createdAt;
50
51 9
        return $this;
52
    }
53
54
    /**
55
     * get created at
56
     *
57
     * @return int
58
     */
59 9
    public function getCreatedAt(): int
60
    {
61 9
        return $this->createdAt;
62
    }
63
64
    /**
65
     * to json
66
     *
67
     * @return string
68
     */
69 8
    public function toJson(): string
70
    {
71 8
        $document = [];
72
73 8
        foreach (array_merge($this->getFields(), self::DEFAULT_FIELDS) as $field) {
74 8
            if (!is_null($value = $this->$field)) {
75 8
                $document[$this->toSnakeCase($field)] = $value;
76
            }
77
        }
78
79 8
        return json_encode($document);
80
    }
81
82
    /**
83
     * to snake case
84
     *
85
     * @param string $string
86
     *
87
     * @return string
88
     */
89 8
    protected function toSnakeCase(string $string): string
90
    {
91 8
        return mb_strtolower(preg_replace('/(.)(?=[A-Z])/', '$1_', $string));
92
    }
93
}
94