IlluminateRequestToPsr7   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 2
dl 0
loc 153
ccs 37
cts 37
cp 1
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMethod() 0 4 1
A hasHeader() 0 4 1
A getHeader() 0 4 1
A getProtocolVersion() 0 4 1
A withProtocolVersion() 0 4 1
A getHeaders() 0 4 1
A getHeaderLine() 0 4 1
A withHeader() 0 4 1
A withAddedHeader() 0 4 1
A withoutHeader() 0 4 1
A getBody() 0 4 1
A withBody() 0 4 1
A getRequestTarget() 0 4 1
A withRequestTarget() 0 4 1
A withMethod() 0 4 1
A getUri() 0 4 1
A withUri() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace Neomerx\CorsIlluminate\Adapters;
4
5
/**
6
 * Copyright 2015-2020 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Illuminate\Http\Request;
22
use LogicException;
23
use Psr\Http\Message\RequestInterface;
24
use Psr\Http\Message\StreamInterface;
25
use Psr\Http\Message\UriInterface;
26
27
/**
28
 * This class is a wrapper for Laravel/Lumen Requests to PSR-7 compatible objects designed specifically for
29
 * neomerx/cors-psr-7 package and implements only the methods required by neomerx/cors-psr-7.
30
 *
31
 * If you are already using PSR-7 Bridge solutions it's totally fine to replace this class with them.
32
 * The main benefit of this class it's very lightweight.
33
 *
34
 * @package Neomerx\CorsIlluminate
35
 *
36
 * @SuppressWarnings(PHPMD.TooManyMethods)
37
 */
38
class IlluminateRequestToPsr7 implements RequestInterface
39
{
40
    /**
41
     * @var Request
42
     */
43
    private $request;
44
45
    /**
46 21
     * @param Request $request
47
     */
48 21
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
49 21
    {
50
        $this->request = $request;
51
    }
52
53
    /**
54 1
     * @inheritdoc
55
     */
56 1
    public function getMethod()
57
    {
58
        return $this->request->getMethod();
59
    }
60
61
    /**
62 1
     * @inheritdoc
63
     */
64 1
    public function hasHeader($name)
65
    {
66
        return $this->request->headers->has($name);
67
    }
68
69
    /**
70 1
     * @inheritdoc
71
     */
72 1
    public function getHeader($name)
73
    {
74
        return $this->request->headers->get($name, null, false);
75
    }
76
77
    /**
78 1
     * @inheritdoc
79
     */
80 1
    public function getProtocolVersion()
81
    {
82
        throw new LogicException('Method is not implemented');
83
    }
84
85
    /**
86 1
     * @inheritdoc
87
     */
88 1
    public function withProtocolVersion($version)
89
    {
90
        throw new LogicException('Method is not implemented');
91
    }
92
93
    /**
94 1
     * @inheritdoc
95
     */
96 1
    public function getHeaders()
97
    {
98
        throw new LogicException('Method is not implemented');
99
    }
100
101
    /**
102 1
     * @inheritdoc
103
     */
104 1
    public function getHeaderLine($name)
105
    {
106
        throw new LogicException('Method is not implemented');
107
    }
108
109
    /**
110 1
     * @inheritdoc
111
     */
112 1
    public function withHeader($name, $value)
113
    {
114
        throw new LogicException('Method is not implemented');
115
    }
116
117
    /**
118 1
     * @inheritdoc
119
     */
120 1
    public function withAddedHeader($name, $value)
121
    {
122
        throw new LogicException('Method is not implemented');
123
    }
124
125
    /**
126 1
     * @inheritdoc
127
     */
128 1
    public function withoutHeader($name)
129
    {
130
        throw new LogicException('Method is not implemented');
131
    }
132
133
    /**
134 1
     * @inheritdoc
135
     */
136 1
    public function getBody()
137
    {
138
        throw new LogicException('Method is not implemented');
139
    }
140
141
    /**
142 1
     * @inheritdoc
143
     */
144 1
    public function withBody(StreamInterface $body)
145
    {
146
        throw new LogicException('Method is not implemented');
147
    }
148
149
    /**
150 1
     * @inheritdoc
151
     */
152 1
    public function getRequestTarget()
153
    {
154
        throw new LogicException('Method is not implemented');
155
    }
156
157
    /**
158 1
     * @inheritdoc
159
     */
160 1
    public function withRequestTarget($requestTarget)
161
    {
162
        throw new LogicException('Method is not implemented');
163
    }
164
165
    /**
166 1
     * @inheritdoc
167
     */
168 1
    public function withMethod($method)
169
    {
170
        throw new LogicException('Method is not implemented');
171
    }
172
173
    /**
174 1
     * @inheritdoc
175
     */
176 1
    public function getUri()
177
    {
178
        throw new LogicException('Method is not implemented');
179
    }
180
181
    /**
182
     * @inheritdoc
183
     *
184 1
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
185
     */
186 1
    public function withUri(UriInterface $uri, $preserveHost = false)
187
    {
188
        throw new LogicException('Method is not implemented');
189
    }
190
}
191