Completed
Push — master ( 932cc5...b796f0 )
by Andrii
12:16
created

ServerRequest::withoutHeader()   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 1
1
<?php
2
3
namespace hiapi\console;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Psr\Http\Message\UriInterface;
7
use Psr\Http\Message\StreamInterface;
8
9
/**
10
 * PSR-7 compatible console ServerRequest
11
 *
12
 * XXX
13
 * XXX NOT finished, NOT used
14
 * XXX
15
 *
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class ServerRequest implements ServerRequestInterface
19
{
20
21
    protected $route;
22
23
    protected $params;
24
25
    public function getQueryParams()
26
    {
27
        if ($this->params === null) {
28
            $this->params = $this->parseParams();
29
        }
30
31
        return $this->params;
32
    }
33
34
    protected function parseParams()
0 ignored issues
show
Coding Style introduced by
parseParams uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
35
    {
36
        if (isset($_SERVER['argv'])) {
37
            $args = $_SERVER['argv'];
38
            array_shift($this->_params);
0 ignored issues
show
Bug introduced by
The property _params does not seem to exist. Did you mean params?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
39
        } else {
40
            $args = [];
41
        }
42
        foreach ($args as $arg) {
43
            var_dump($arg);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($arg); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
44
        }
45
        die;
0 ignored issues
show
Coding Style Compatibility introduced by
The method parseParams() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
46
47
        return $params;
0 ignored issues
show
Unused Code introduced by
return $params; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
48
    }
49
50
    public function getParsedBody()
51
    {
52
        return [];
53
    }
54
55
    public function getServerParams()
56
    {
57
        throw new \Exception('not implemented');
58
    }
59
60
    public function getCookieParams()
61
    {
62
        throw new \Exception('not implemented');
63
    }
64
65
    public function withCookieParams(array $cookies)
66
    {
67
        throw new \Exception('not implemented');
68
    }
69
70
    public function withQueryParams(array $query)
71
    {
72
        throw new \Exception('not implemented');
73
    }
74
75
    public function getUploadedFiles()
76
    {
77
        throw new \Exception('not implemented');
78
    }
79
80
    public function withUploadedFiles(array $uploadedFiles)
81
    {
82
        throw new \Exception('not implemented');
83
    }
84
85
    public function withParsedBody($data)
86
    {
87
        throw new \Exception('not implemented');
88
    }
89
90
    public function getAttributes()
91
    {
92
        throw new \Exception('not implemented');
93
    }
94
95
    public function getAttribute($name, $default = null)
96
    {
97
        throw new \Exception('not implemented');
98
    }
99
100
    public function withAttribute($name, $value)
101
    {
102
        throw new \Exception('not implemented');
103
    }
104
105
    public function withoutAttribute($name)
106
    {
107
        throw new \Exception('not implemented');
108
    }
109
110
    public function getRequestTarget()
111
    {
112
        throw new \Exception('not implemented');
113
    }
114
115
    public function withRequestTarget($requestTarget)
116
    {
117
        throw new \Exception('not implemented');
118
    }
119
120
    public function getMethod()
121
    {
122
        throw new \Exception('not implemented');
123
    }
124
125
    public function withMethod($method)
126
    {
127
        throw new \Exception('not implemented');
128
    }
129
130
    public function getUri()
131
    {
132
        throw new \Exception('not implemented');
133
    }
134
135
    public function withUri(UriInterface $uri, $preserveHost = false)
136
    {
137
        throw new \Exception('not implemented');
138
    }
139
140
    public function getProtocolVersion()
141
    {
142
        throw new \Exception('not implemented');
143
    }
144
145
    public function withProtocolVersion($version)
146
    {
147
        throw new \Exception('not implemented');
148
    }
149
150
    public function getHeaders()
151
    {
152
        throw new \Exception('not implemented');
153
    }
154
155
    public function hasHeader($name)
156
    {
157
        throw new \Exception('not implemented');
158
    }
159
160
    public function getHeader($name)
161
    {
162
        throw new \Exception('not implemented');
163
    }
164
165
    public function getHeaderLine($name)
166
    {
167
        throw new \Exception('not implemented');
168
    }
169
170
    public function withHeader($name, $value)
171
    {
172
        throw new \Exception('not implemented');
173
    }
174
175
    public function withAddedHeader($name, $value)
176
    {
177
        throw new \Exception('not implemented');
178
    }
179
180
    public function withoutHeader($name)
181
    {
182
        throw new \Exception('not implemented');
183
    }
184
185
    public function getBody()
186
    {
187
        throw new \Exception('not implemented');
188
    }
189
190
    public function withBody(StreamInterface $body)
191
    {
192
        throw new \Exception('not implemented');
193
    }
194
}
195