@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function isEmpty($filter = null): bool |
50 | 50 | { |
51 | - if (! $this->exists()) { |
|
51 | + if (!$this->exists()) { |
|
52 | 52 | throw new DirectoryException("Directory {dir} does not exist", array( |
53 | 53 | 'dir' => $this->path |
54 | 54 | )); |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | $iter = new \DirectoryIterator($this->path); |
58 | 58 | while ($iter->valid()) { |
59 | - if (! $iter->isDot() && ($filter === null || ! preg_match("/$filter/", $iter->getFilename()))) { |
|
59 | + if (!$iter->isDot() && ($filter === null || !preg_match("/$filter/", $iter->getFilename()))) { |
|
60 | 60 | return false; |
61 | 61 | } |
62 | 62 | $iter->next(); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function remove($recursive = false) |
77 | 77 | { |
78 | - if (! $this->exists()) { |
|
78 | + if (!$this->exists()) { |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | - if (! $recursive) { |
|
91 | + if (!$recursive) { |
|
92 | 92 | throw new DirectoryException("Directory {dir} is not empty", array( |
93 | 93 | 'dir' => $this->path |
94 | 94 | )); |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function exists(): bool |
147 | 147 | { |
148 | - if (! file_exists($this->path)) { |
|
148 | + if (!file_exists($this->path)) { |
|
149 | 149 | return false; |
150 | 150 | } |
151 | 151 | |
152 | - if (! is_dir($this->path)) { |
|
152 | + if (!is_dir($this->path)) { |
|
153 | 153 | throw new DirectoryException("Entry {path} exists, but it is not a directory!", array( |
154 | 154 | 'path' => $this->path |
155 | 155 | )); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function fileExists($fileName): bool |
182 | 182 | { |
183 | - if (! $this->exists()) { |
|
183 | + if (!$this->exists()) { |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 |
@@ -104,7 +104,8 @@ |
||
104 | 104 | if ($iter->isDir()) { |
105 | 105 | $dir = new Directory($iter->getPathname()); |
106 | 106 | $dir->remove(true); |
107 | - } else { |
|
107 | + } |
|
108 | + else { |
|
108 | 109 | unlink($iter->getPathname()); |
109 | 110 | } |
110 | 111 |
@@ -24,6 +24,8 @@ discard block |
||
24 | 24 | * |
25 | 25 | * {@inheritdoc} |
26 | 26 | * @see \Generics\Streams\HttpStream::setHeader() |
27 | + * @param string $headerName |
|
28 | + * @param string $headerValue |
|
27 | 29 | * @return HttpClient |
28 | 30 | */ |
29 | 31 | public function setHeader($headerName, $headerValue) |
@@ -61,6 +63,7 @@ discard block |
||
61 | 63 | |
62 | 64 | /** |
63 | 65 | * Adjust the headers by injecting default values for missing keys. |
66 | + * @param string $requestType |
|
64 | 67 | */ |
65 | 68 | private function adjustHeaders($requestType) |
66 | 69 | { |
@@ -64,23 +64,23 @@ |
||
64 | 64 | */ |
65 | 65 | private function adjustHeaders($requestType) |
66 | 66 | { |
67 | - if (! array_key_exists('Accept', $this->headers) && $requestType != 'HEAD') { |
|
67 | + if (!array_key_exists('Accept', $this->headers) && $requestType != 'HEAD') { |
|
68 | 68 | $this->setHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'); |
69 | 69 | } |
70 | 70 | |
71 | - if (! array_key_exists('Accept-Language', $this->headers) && $requestType != 'HEAD') { |
|
71 | + if (!array_key_exists('Accept-Language', $this->headers) && $requestType != 'HEAD') { |
|
72 | 72 | $this->setHeader('Accept-Language', 'en-US;q=0.7,en;q=0.3'); |
73 | 73 | } |
74 | 74 | |
75 | - if (! array_key_exists('User-Agent', $this->headers) && $requestType != 'HEAD') { |
|
75 | + if (!array_key_exists('User-Agent', $this->headers) && $requestType != 'HEAD') { |
|
76 | 76 | $this->setHeader('User-Agent', 'phpGenerics 1.0'); |
77 | 77 | } |
78 | 78 | |
79 | - if (! array_key_exists('Connection', $this->headers) || strlen($this->headers['Connection']) == 0) { |
|
79 | + if (!array_key_exists('Connection', $this->headers) || strlen($this->headers['Connection']) == 0) { |
|
80 | 80 | $this->adjustConnectionHeader($requestType); |
81 | 81 | } |
82 | 82 | |
83 | - if (! array_key_exists('Accept-Encoding', $this->headers)) { |
|
83 | + if (!array_key_exists('Accept-Encoding', $this->headers)) { |
|
84 | 84 | $encoding = ""; |
85 | 85 | if (function_exists('gzinflate')) { |
86 | 86 | $encoding = 'gzip, deflate'; |
@@ -84,7 +84,8 @@ discard block |
||
84 | 84 | $encoding = ""; |
85 | 85 | if (function_exists('gzinflate')) { |
86 | 86 | $encoding = 'gzip, deflate'; |
87 | - } else { |
|
87 | + } |
|
88 | + else { |
|
88 | 89 | $encoding = 'identity'; |
89 | 90 | } |
90 | 91 | $this->setHeader('Accept-Encoding', $encoding); |
@@ -101,7 +102,8 @@ discard block |
||
101 | 102 | { |
102 | 103 | if ($requestType == 'HEAD') { |
103 | 104 | $this->setHeader('Connection', 'close'); |
104 | - } else { |
|
105 | + } |
|
106 | + else { |
|
105 | 107 | $this->setHeader('Connection', 'keep-alive'); |
106 | 108 | } |
107 | 109 | } |
@@ -115,7 +117,8 @@ discard block |
||
115 | 117 | { |
116 | 118 | if (strpos($line, ':') === false) { |
117 | 119 | $this->responseCode = HttpStatus::parseStatus($line)->getCode(); |
118 | - } else { |
|
120 | + } |
|
121 | + else { |
|
119 | 122 | $line = trim($line); |
120 | 123 | list ($headerName, $headerValue) = explode(':', $line, 2); |
121 | 124 | $this->headers[$headerName] = trim($headerValue); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $this->handle = $clientHandle; |
37 | 37 | $this->conntected = false; |
38 | 38 | |
39 | - if (! is_resource($clientHandle)) { |
|
39 | + if (!is_resource($clientHandle)) { |
|
40 | 40 | parent::__construct($endpoint); |
41 | 41 | } |
42 | 42 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | if (!is_resource($this->handle)) { |
52 | 52 | throw new SocketException("Socket is not available"); |
53 | 53 | } |
54 | - if (! @socket_connect($this->handle, $this->endpoint->getAddress(), $this->endpoint->getPort())) { |
|
54 | + if (!@socket_connect($this->handle, $this->endpoint->getAddress(), $this->endpoint->getPort())) { |
|
55 | 55 | $code = socket_last_error($this->handle); |
56 | 56 | throw new SocketException(socket_strerror($code), array(), $code); |
57 | 57 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function disconnect() |
67 | 67 | { |
68 | - if (! $this->conntected) { |
|
68 | + if (!$this->conntected) { |
|
69 | 69 | throw new SocketException("Socket is not connected"); |
70 | 70 | } |
71 | 71 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function isWriteable():bool |
101 | 101 | { |
102 | - if (! $this->isConnected()) { |
|
102 | + if (!$this->isConnected()) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | 'rqtype' => $requestType, |
130 | 130 | 'path' => $this->path, |
131 | 131 | 'proto' => $this->protocol, |
132 | - 'query' => (strlen($this->queryString) ? '?' . $this->queryString : '') |
|
132 | + 'query' => (strlen($this->queryString) ? '?'.$this->queryString : '') |
|
133 | 133 | )); |
134 | 134 | |
135 | 135 | // Add the host part |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $numBytes = 1; |
185 | 185 | $start = time(); |
186 | 186 | while (true) { |
187 | - if (! $this->checkConnection($start)) { |
|
187 | + if (!$this->checkConnection($start)) { |
|
188 | 188 | continue; |
189 | 189 | } |
190 | 190 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $start = time(); // we have readen something => adjust timeout start point |
198 | 198 | $tmp .= $c; |
199 | 199 | |
200 | - if (! $delimiterFound) { |
|
200 | + if (!$delimiterFound) { |
|
201 | 201 | $this->handleHeader($delimiterFound, $numBytes, $tmp); |
202 | 202 | } |
203 | 203 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | |
306 | 306 | $ms = $this->appendPayloadToRequest($ms); |
307 | 307 | |
308 | - if (! $this->isConnected()) { |
|
308 | + if (!$this->isConnected()) { |
|
309 | 309 | $this->connect(); |
310 | 310 | } |
311 | 311 | |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | */ |
331 | 331 | private function checkConnection($start): bool |
332 | 332 | { |
333 | - if (! $this->ready()) { |
|
333 | + if (!$this->ready()) { |
|
334 | 334 | if (time() - $start > $this->timeout) { |
335 | 335 | $this->disconnect(); |
336 | 336 | throw new HttpException("Connection timed out!"); |
@@ -234,7 +234,8 @@ |
||
234 | 234 | |
235 | 235 | if (is_dir($caPath)) { |
236 | 236 | $opts['ssl']['capath'] = $caPath; |
237 | - } else { |
|
237 | + } |
|
238 | + else { |
|
238 | 239 | $opts['ssl']['cafile'] = $caPath; |
239 | 240 | } |
240 | 241 |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function read($length = 1, $offset = null): string |
62 | 62 | { |
63 | - return stream_get_contents($this->handle, $length, $offset === null ? - 1 : intval($offset)); |
|
63 | + return stream_get_contents($this->handle, $length, $offset === null ? -1 : intval($offset)); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function isOpen(): bool |
72 | 72 | { |
73 | - return is_resource($this->handle) && ! feof($this->handle); |
|
73 | + return is_resource($this->handle) && !feof($this->handle); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function ready(): bool |
92 | 92 | { |
93 | - if (! is_resource($this->handle)) { |
|
93 | + if (!is_resource($this->handle)) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
113 | - if (! in_array($this->handle, $read)) { |
|
113 | + if (!in_array($this->handle, $read)) { |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function write($buffer) |
171 | 171 | { |
172 | - if(!$this->isWriteable()) { |
|
172 | + if (!$this->isWriteable()) { |
|
173 | 173 | throw new SocketException("Stream is not ready for writing"); |
174 | 174 | } |
175 | 175 | $len = strlen($buffer); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function isWriteable(): bool |
195 | 195 | { |
196 | - if (! is_resource($this->handle)) { |
|
196 | + if (!is_resource($this->handle)) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | return false; |
214 | 214 | } |
215 | 215 | |
216 | - if (! in_array($this->handle, $write)) { |
|
216 | + if (!in_array($this->handle, $write)) { |
|
217 | 217 | return false; |
218 | 218 | } |
219 | 219 |
@@ -174,7 +174,8 @@ |
||
174 | 174 | if ($code != 0) { |
175 | 175 | if ($code != 10053) { |
176 | 176 | throw new SocketException(socket_strerror($code), array(), $code); |
177 | - } else { |
|
177 | + } |
|
178 | + else { |
|
178 | 179 | $this->handle = null; |
179 | 180 | } |
180 | 181 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | $this->handle = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
56 | 56 | |
57 | - if (! is_resource($this->handle)) { |
|
57 | + if (!is_resource($this->handle)) { |
|
58 | 58 | $code = socket_last_error(); |
59 | 59 | throw new SocketException(socket_strerror($code), array(), $code); |
60 | 60 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function ready(): bool |
90 | 90 | { |
91 | - if (! is_resource($this->handle)) { |
|
91 | + if (!is_resource($this->handle)) { |
|
92 | 92 | return false; |
93 | 93 | } |
94 | 94 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | return false; |
110 | 110 | } |
111 | 111 | |
112 | - if (! in_array($this->handle, $read)) { |
|
112 | + if (!in_array($this->handle, $read)) { |
|
113 | 113 | return false; |
114 | 114 | } |
115 | 115 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function isWriteable(): bool |
125 | 125 | { |
126 | - if (! is_resource($this->handle)) { |
|
126 | + if (!is_resource($this->handle)) { |
|
127 | 127 | return false; |
128 | 128 | } |
129 | 129 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | |
147 | - if (! in_array($this->handle, $write)) { |
|
147 | + if (!in_array($this->handle, $write)) { |
|
148 | 148 | return false; |
149 | 149 | } |
150 | 150 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $this->handle = $clientHandle; |
36 | 36 | $this->conntected = false; |
37 | 37 | |
38 | - if (! is_resource($clientHandle)) { |
|
38 | + if (!is_resource($clientHandle)) { |
|
39 | 39 | parent::__construct($endpoint); |
40 | 40 | } |
41 | 41 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function disconnect() |
59 | 59 | { |
60 | - if (! $this->conntected) { |
|
60 | + if (!$this->conntected) { |
|
61 | 61 | throw new SocketException("Socket is not connected"); |
62 | 62 | } |
63 | 63 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function isWriteable(): bool |
93 | 93 | { |
94 | - if (! $this->isConnected()) { |
|
94 | + if (!$this->isConnected()) { |
|
95 | 95 | return false; |
96 | 96 | } |
97 | 97 |
@@ -68,7 +68,7 @@ |
||
68 | 68 | */ |
69 | 69 | public function get($key) |
70 | 70 | { |
71 | - if (! isset($this->sessionContainer[$key])) { |
|
71 | + if (!isset($this->sessionContainer[$key])) { |
|
72 | 72 | return null; |
73 | 73 | } |
74 | 74 |