Completed
Branch master (73f336)
by John
01:59
created

Request::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 11
nc 1
nop 10

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\Request;
3
use LunixREST\Request\RequestData\RequestData;
4
5
/**
6
 * Class Request
7
 * @package LunixREST\Request
8
 */
9
class Request {
10
    /**
11
     * @var string
12
     */
13
    protected $method;
14
    /**
15
     * @var array
16
     */
17
    protected $headers;
18
    /**
19
     * @var string
20
     */
21
    protected $version;
22
    /**
23
     * @var string
24
     */
25
    protected $apiKey;
26
    /**
27
     * @var string
28
     */
29
    protected $endpoint;
30
    /**
31
     * @var string
32
     */
33
    protected $instance;
34
    /**
35
     * @var string
36
     */
37
    protected $extension;
38
    /**
39
     * @var string
40
     */
41
    protected $ip;
42
    /**
43
     * @var RequestData
44
     */
45
    private $body;
46
    /**
47
     * @var RequestData
48
     */
49
    private $urlData;
50
51
    /**
52
     * Create a request. Pass Either a URL to parse or the parsed parts.
53
     * If both are passed the explicitly stated parts will be used.
54
     * @param $method
55
     * @param array $headers
56
     * @param RequestData $body
57
     * @param RequestData $urlData
58
     * @param $ip
59
     * @param string $version
60
     * @param string $apiKey
61
     * @param string $endpoint
62
     * @param string $extension
63
     * @param string $instance
64
     */
65
    public function __construct($method, array $headers, RequestData $body, RequestData $urlData, $ip, $version, $apiKey, $endpoint, $extension, $instance = null){
66
        $this->method = strtolower($method);
67
        $this->headers = $headers;
68
        $this->body = $body;
69
        $this->urlData = $urlData;
70
        $this->ip = $ip;
71
        $this->version = $version;
72
        $this->apiKey = $apiKey;
73
        $this->endpoint = $endpoint;
74
        $this->extension = $extension;
75
        $this->instance = $instance;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getIp() {
82
        return $this->ip;
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getMethod() {
89
        return $this->method . ($this->instance ? '' : 'All');
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    public function getHeaders() {
96
        return $this->headers;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getVersion() {
103
        return $this->version;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getApiKey() {
110
        return $this->apiKey;
111
    }
112
113
    /**
114
     * @return string
115
     */
116
    public function getEndpoint() {
117
        return $this->endpoint;
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getInstance() {
124
        return $this->instance;
125
    }
126
127
    /**
128
     * @return string
129
     */
130
    public function getExtension() {
131
        return $this->extension;
132
    }
133
134
    /**
135
     * @return RequestData
136
     */
137
    public function getBody(): RequestData {
138
        return $this->body;
139
    }
140
141
    /**
142
     * @return RequestData
143
     */
144
    public function getUrlData(): RequestData {
145
        return $this->urlData;
146
    }
147
148
}
149