APIRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 8
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
namespace LunixREST\Server\APIRequest;
3
4
/**
5
 * An immutable data class for representing API requests.
6
 * Class APIRequest
7
 * @package LunixREST\Server\Request
8
 */
9
class APIRequest
10
{
11
    /**
12
     * @var string
13
     */
14
    private $method;
15
    /**
16
     * @var string
17
     */
18
    private $endpoint;
19
    /**
20
     * @var null|string
21
     */
22
    private $element;
23
    /**
24
     * @var array
25
     */
26
    private $acceptableMIMETypes;
27
    /**
28
     * @var null|string
29
     */
30
    private $version;
31
    /**
32
     * @var null|string
33
     */
34
    private $apiKey;
35
    /**
36
     * @var array
37
     */
38
    private $queryData;
39
    /**
40
     * @var null|object|array
41
     */
42
    private $data;
43
44
    /**
45
     * APIRequest constructor.
46
     * @param string $method
47
     * @param string $endpoint
48
     * @param null|string $element
49
     * @param array $acceptableMIMETypes
50
     * @param null|string $version
51
     * @param null|string $apiKey
52
     * @param array $queryData
53
     * @param null|object|array $data
54
     */
55 3
    public function __construct(
56
        string $method,
57
        string $endpoint,
58
        ?string $element,
59
        array $acceptableMIMETypes,
60
        ?string $version,
61
        ?string $apiKey,
62
        array $queryData,
63
        $data
64
    ) {
65 3
        $this->method = $method;
66 3
        $this->endpoint = $endpoint;
67 3
        $this->element = $element;
68 3
        $this->acceptableMIMETypes = $acceptableMIMETypes;
69 3
        $this->version = $version;
70 3
        $this->apiKey = $apiKey;
71 3
        $this->queryData = $queryData;
72 3
        $this->data = $data;
73 3
    }
74
75
    /**
76
     * @return string
77
     */
78 2
    public function getMethod(): string
79
    {
80 2
        return $this->method;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 2
    public function getEndpoint(): string
87
    {
88 2
        return $this->endpoint;
89
    }
90
91
    /**
92
     * @return null|string
93
     */
94 2
    public function getElement(): ?string
95
    {
96 2
        return $this->element;
97
    }
98
99
    /**
100
     * @return array
101
     */
102 2
    public function getAcceptableMIMETypes(): array
103
    {
104 2
        return $this->acceptableMIMETypes;
105
    }
106
107
    /**
108
     * @return null|string
109
     */
110 2
    public function getVersion(): ?string
111
    {
112 2
        return $this->version;
113
    }
114
115
    /**
116
     * @return null|string
117
     */
118 3
    public function getApiKey(): ?string
119
    {
120 3
        return $this->apiKey;
121
    }
122
123
    /**
124
     * @return array
125
     */
126 2
    public function getQueryData(): array
127
    {
128 2
        return $this->queryData;
129
    }
130
131
    /**
132
     * @return array|null|object
133
     */
134 2
    public function getData()
135
    {
136 2
        return $this->data;
137
    }
138
}
139