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 ( d85cb7...21c7d7 )
by VEBER
11s
created

AbstractDocument::toRequestParameters()   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
     * 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 9
    public function toJson(): string
70
    {
71 9
        return json_encode($this->toRequestParameters());
72
    }
73
74
    /**
75
     * to query string
76
     *
77
     * @return string
78
     */
79 9
    public function toQueryString(): string
80
    {
81 9
        return http_build_query($this->toRequestParameters());
82
    }
83
84
    /**
85
     * to request parameters
86
     *
87
     * @return array
88
     */
89 16
    protected function toRequestParameters(): array
90
    {
91 16
        $requestParameters = [];
92
93 16
        foreach (array_merge($this->getFields(), self::DEFAULT_FIELDS) as $field) {
94 16
            if (!is_null($value = $this->$field)) {
95 16
                $requestParameters[$this->toSnakeCase($field)] = $value;
96
            }
97
        }
98
99 16
        return $requestParameters;
100
    }
101
102
    /**
103
     * to snake case
104
     *
105
     * @param string $string
106
     *
107
     * @return string
108
     */
109 16
    protected function toSnakeCase(string $string): string
110
    {
111 16
        return mb_strtolower(preg_replace('/(.)(?=[A-Z])/', '$1_', $string));
112
    }
113
}
114