Completed
Push — master ( 24bb3c...b333c5 )
by Christopher
04:00
created

IncomingIlluminateRequest::getAllInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace POData\OperationContext\Web\Illuminate;
4
5
use Illuminate\Http\Request;
6
use POData\OperationContext\HTTPRequestMethod;
7
use POData\OperationContext\IHTTPRequest;
8
9
class IncomingIlluminateRequest implements IHTTPRequest
10
{
11
    /**
12
     * The Illuminate request.
13
     *
14
     * @var Request
15
     */
16
    private $request;
17
18
    /**
19
     * The request headers.
20
     *
21
     * @var array
22
     */
23
    private $_headers;
24
25
    /**
26
     * The incoming url in raw format.
27
     *
28
     * @var string
29
     */
30
    private $_rawUrl = null;
31
32
    /**
33
     * The request method (GET, POST, PUT, DELETE or MERGE).
34
     *
35
     * @var HTTPRequestMethod HttpVerb
36
     */
37
    private $_method;
38
39
    /**
40
     * The query options as key value.
41
     *
42
     * @var array(string, string);
43
     */
44
    private $_queryOptions;
45
46
    /**
47
     * A collection that represents mapping between query
48
     * option and its count.
49
     *
50
     * @var array(string, int)
51
     */
52
    private $_queryOptionsCount;
53
54
    /**
55
     * IncomingIlluminateRequest constructor.
56
     *
57
     * @param Request $request
58
     */
59
    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...
60
    {
61
        $this->request = $request;
62
        $this->_headers = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $_headers.

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...
63
        $this->_queryOptions = null;
64
        $this->_queryOptionsCount = null;
65
        $this->_method = new HTTPRequestMethod($this->request->getMethod());
66
    }
67
68
    /**
69
     * @return string RequestURI called by User with the value of QueryString
70
     */
71
    public function getRawUrl()
72
    {
73
        $this->_rawUrl = $this->request->fullUrl();
74
75
        return $this->_rawUrl;
76
    }
77
78
    /**
79
     * @param string $key The header name
80
     *
81
     * @return array|null|string
82
     */
83
    public function getRequestHeader($key)
84
    {
85
        $result = $this->request->header($key);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->request->header($key); of type string|array adds the type array to the return on line 91 which is incompatible with the return type declared by the interface POData\OperationContext\...quest::getRequestHeader of type string|null.
Loading history...
86
        //Zend returns false for a missing header...POData needs a null
87
        if ($result === false || $result === '') {
88
            return null;
89
        }
90
91
        return $result;
92
    }
93
94
    /**
95
     * Returns the Query String Parameters (QSPs) as an array of KEY-VALUE pairs.  If a QSP appears twice
96
     * it will have two entries in this array.
97
     *
98
     * @return array
99
     */
100
    public function getQueryParameters()
101
    {
102
        //TODO: the contract is more specific than this, it requires the name and values to be decoded
103
        //not sure how to test that...
104
        //TODO: another issue.  This may not be the right thing to return...since POData only really understands GET requests today
105
        //Have to convert to the stranger format known to POData that deals with multiple query strings.
106
        //this makes this request a bit non compliant as it doesn't expose duplicate keys, something POData will check for
107
        //instead whatever parameter was last in the query string is set.  IE
108
        //odata.svc/?$format=xml&$format=json the format will be json
109
        $this->_queryOptions = [];
110
        $this->_queryOptionsCount = 0;
111
        foreach ($this->request->all() as $key => $value) {
112
            $this->_queryOptions[] = [$key => $value];
113
            ++$this->_queryOptionsCount;
114
        }
115
116
        return $this->_queryOptions;
117
    }
118
119
    /**
120
     * @return HTTPRequestMethod
121
     */
122
    public function getMethod()
123
    {
124
        return $this->_method;
125
    }
126
127
    /**
128
     * @return array|mixed
129
     */
130
    public function getAllInput()
131
    {
132
        return $this->request->all();
133
    }
134
}
135