Completed
Push — next ( aa6b76...a5d913 )
by Jonathan
02:53
created

Psr7RequestAdapter::getHeaders()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.4286
cc 3
eloc 6
nc 2
nop 0
crap 3
1
<?php
2
3
/*
4
The MIT License (MIT)
5
6
Copyright (c) 2015 Vectorface, Inc.
7
8
Permission is hereby granted, free of charge, to any person obtaining a copy
9
of this software and associated documentation files (the "Software"), to deal
10
in the Software without restriction, including without limitation the rights
11
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
copies of the Software, and to permit persons to whom the Software is
13
furnished to do so, subject to the following conditions:
14
15
The above copyright notice and this permission notice shall be included in
16
all copies or substantial portions of the Software.
17
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
THE SOFTWARE.
25
*/
26
27
namespace Vectorface\Whip\Request;
28
29
use Psr\Http\Message\ServerRequestInterface;
30
31
/**
32
 * Provide IP address data from ta PSR-7 request.
33
 */
34
class Psr7RequestAdapter implements RequestAdapter
35
{
36
    /**
37
     * The PSR-7 request that serves as the source of data.
38
     *
39
     * @var Psr\Http\Message\ServerRequestInterface
40
     */
41
    private $request;
42
43
    /**
44
     * A formatted version of the HTTP headers: ["header" => "value", ...]
45
     *
46
     * @var string[]
47
     */
48
    private $headers;
49
50
    /**
51
     * Create a new adapter for a superglobal $_SERVER-style array.
52
     *
53
     * @param string[] $server An array in a format like PHP's $_SERVER var.
0 ignored issues
show
Bug introduced by
There is no parameter named $server. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
54
     */
55 1
    public function __construct(ServerRequestInterface $request)
56
    {
57 1
        $this->request = $request;
0 ignored issues
show
Documentation Bug introduced by
It seems like $request of type object<Psr\Http\Message\ServerRequestInterface> is incompatible with the declared type object<Vectorface\Whip\R...ServerRequestInterface> of property $request.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58 1
    }
59
60 1
    public function getRemoteAddr()
61
    {
62 1
        $server = $this->request->getServerParams();
63 1
        return isset($server['REMOTE_ADDR']) ? $server['REMOTE_ADDR'] : null;
64
    }
65
66 1
    public function getHeaders()
67
    {
68 1
        if (!isset($this->headers)) {
69 1
            $this->headers = [];
70 1
            foreach ($this->request->getHeaders() as $header => $values) {
71 1
                $this->headers[strtolower($header)] = end($values);
72 1
            }
73 1
        }
74 1
        return $this->headers;
75
    }
76
}
77