Completed
Push — master ( e6719d...13ae3c )
by John
01:53
created

Request::getAcceptableMIMETypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 $ip;
38
    /**
39
     * @var RequestData
40
     */
41
    private $body;
42
    /**
43
     * @var RequestData
44
     */
45
    private $urlData;
46
    /**
47
     * @var array
48
     */
49
    private $acceptableMIMETypes;
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 array $acceptableMIMETypes
63
     * @param string $instance
64
     * @internal param string $extension
65
     */
66
67
    public function __construct($method, array $headers, RequestData $body, RequestData $urlData, $ip, $version, $apiKey, $endpoint, array $acceptableMIMETypes = [], $instance = null){
68
        $this->method = strtolower($method);
69
        $this->headers = $headers;
70
        $this->body = $body;
71
        $this->urlData = $urlData;
72
        $this->ip = $ip;
73
        $this->version = $version;
74
        $this->apiKey = $apiKey;
75
        $this->endpoint = $endpoint;
76
        $this->acceptableMIMETypes = $acceptableMIMETypes;
77
        $this->instance = $instance;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getIp() {
84
        return $this->ip;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getMethod() {
91
        return $this->method . ($this->instance ? '' : 'All');
92
    }
93
94
    /**
95
     * @return array
96
     */
97
    public function getHeaders() {
98
        return $this->headers;
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function getVersion() {
105
        return $this->version;
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    public function getApiKey() {
112
        return $this->apiKey;
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function getEndpoint() {
119
        return $this->endpoint;
120
    }
121
122
    /**
123
     * @return array
124
     */
125
    public function getAcceptableMIMETypes(): array {
126
        return $this->acceptableMIMETypes;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getInstance() {
133
        return $this->instance;
134
    }
135
    /**
136
     * @return RequestData
137
     */
138
    public function getBody(): RequestData {
139
        return $this->body;
140
    }
141
142
    /**
143
     * @return RequestData
144
     */
145
    public function getUrlData(): RequestData {
146
        return $this->urlData;
147
    }
148
149
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
150
     *
151
        $acceptedMIMETypes = [];
152
        if($this->extension) {
153
            //extension to mime type conversion
154
            $acceptedMIMETypes[] = $this->MIMEProvider->getByFileExtension($this->extension);
155
        } else {
156
            $headerAccepts = [];
157
            foreach($this->headers as $key => $value) {
158
                if(strtolower($key) == 'http-accept'){
159
                    $values = explode(',', $value);
160
                    foreach($values as $acceptedType) {
161
                        $typeParts = explode(';', $acceptedType);
162
                        if(count($typeParts) > 0 ){
163
                            $headerAccepts[] = trim($typeParts);
164
                        }
165
                    }
166
                    break;
167
                }
168
            }
169
            $acceptedMIMETypes = array_merge($acceptedMIMETypes, $headerAccepts);
170
        }
171
172
        return $acceptedMIMETypes;
173
     */
174
}
175