@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Request; |
4 | 4 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** @var string */ |
42 | 42 | protected $method = self::METHOD_GET; |
43 | 43 | /** @var string[] */ |
44 | - protected $newCookies = []; |
|
44 | + protected $newCookies = [ ]; |
|
45 | 45 | /** @var callable|null */ |
46 | 46 | private $cookiesHandlerCallback; |
47 | 47 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param string $domain |
58 | 58 | * @param callable $cookiesHandlerCallback |
59 | 59 | */ |
60 | - public function __construct( |
|
60 | + public function __construct ( |
|
61 | 61 | LoggerInterface $logger, |
62 | 62 | array $params, |
63 | 63 | string $domain, |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return self For chaining |
76 | 76 | */ |
77 | - public function setPost(): self { |
|
77 | + public function setPost (): self { |
|
78 | 78 | $this->method = self::METHOD_POST; |
79 | 79 | return $this; |
80 | 80 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param string[] $cookies |
84 | 84 | * @return self For chaining |
85 | 85 | */ |
86 | - public function setCookies( array $cookies ): self { |
|
86 | + public function setCookies ( array $cookies ): self { |
|
87 | 87 | $this->cookiesToSet = $cookies; |
88 | 88 | return $this; |
89 | 89 | } |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | * Execute a query request |
93 | 93 | * @return Generator |
94 | 94 | */ |
95 | - public function executeAsQuery(): Generator { |
|
96 | - if ( ( $this->params['action'] ?? false ) !== 'query' ) { |
|
95 | + public function executeAsQuery (): Generator { |
|
96 | + if ( ( $this->params[ 'action' ] ?? false ) !== 'query' ) { |
|
97 | 97 | throw new BadMethodCallException( 'Not an ApiQuery!' ); |
98 | 98 | } |
99 | 99 | // TODO Is this always correct? |
100 | - $key = $this->params['list'] ?? 'pages'; |
|
100 | + $key = $this->params[ 'list' ] ?? 'pages'; |
|
101 | 101 | $curParams = $this->params; |
102 | 102 | $lim = $this->parseLimit(); |
103 | 103 | do { |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * Execute a request that doesn't need any continuation. |
127 | 127 | * @return stdClass |
128 | 128 | */ |
129 | - public function executeSingle(): stdClass { |
|
129 | + public function executeSingle (): stdClass { |
|
130 | 130 | $curParams = $this->params; |
131 | 131 | $res = $this->makeRequestInternal( $curParams ); |
132 | 132 | $this->handleErrorAndWarnings( $res ); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | /** |
137 | 137 | * @return int |
138 | 138 | */ |
139 | - private function parseLimit(): int { |
|
139 | + private function parseLimit (): int { |
|
140 | 140 | foreach ( $this->params as $name => $val ) { |
141 | 141 | if ( substr( $name, -strlen( 'limit' ) ) === 'limit' ) { |
142 | 142 | return $val === 'max' ? -1 : (int)$val; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param string $resKey |
154 | 154 | * @return int|null |
155 | 155 | */ |
156 | - private function countQueryResults( stdClass $res, string $resKey ): ?int { |
|
156 | + private function countQueryResults ( stdClass $res, string $resKey ): ?int { |
|
157 | 157 | if ( !isset( $res->query->$resKey ) ) { |
158 | 158 | return null; |
159 | 159 | } |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | * @phan-param array<int|string|bool> $params |
182 | 182 | * @return stdClass |
183 | 183 | */ |
184 | - private function makeRequestInternal( array $params ): stdClass { |
|
184 | + private function makeRequestInternal ( array $params ): stdClass { |
|
185 | 185 | if ( $this->method === self::METHOD_POST ) { |
186 | - $params['maxlag'] = self::MAXLAG; |
|
186 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
187 | 187 | } |
188 | 188 | $query = http_build_query( $params ); |
189 | 189 | |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @param string $cookie "{key}={value}" |
205 | 205 | */ |
206 | - protected function saveNewCookie( string $cookie ): void { |
|
206 | + protected function saveNewCookie ( string $cookie ): void { |
|
207 | 207 | $bits = explode( ';', $cookie ); |
208 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
209 | - $this->newCookies[$name] = $value; |
|
208 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
209 | + $this->newCookies[ $name ] = $value; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param string $params |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - abstract protected function reallyMakeRequest( string $params ): string; |
|
218 | + abstract protected function reallyMakeRequest ( string $params ): string; |
|
219 | 219 | |
220 | 220 | /** |
221 | 221 | * Get a specific exception class depending on the error code |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * @param stdClass $res |
224 | 224 | * @return APIRequestException |
225 | 225 | */ |
226 | - private function getException( stdClass $res ): APIRequestException { |
|
226 | + private function getException ( stdClass $res ): APIRequestException { |
|
227 | 227 | switch ( $res->error->code ) { |
228 | 228 | case 'missingtitle': |
229 | 229 | $ex = new MissingPageException; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @param stdClass $res |
250 | 250 | * @throws APIRequestException |
251 | 251 | */ |
252 | - protected function handleErrorAndWarnings( stdClass $res ): void { |
|
252 | + protected function handleErrorAndWarnings ( stdClass $res ): void { |
|
253 | 253 | if ( isset( $res->error ) ) { |
254 | 254 | throw $this->getException( $res ); |
255 | 255 | } |
@@ -265,14 +265,14 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @return string[] |
267 | 267 | */ |
268 | - protected function getHeaders(): array { |
|
268 | + protected function getHeaders (): array { |
|
269 | 269 | $ret = self::HEADERS; |
270 | 270 | if ( $this->cookiesToSet ) { |
271 | - $cookies = []; |
|
271 | + $cookies = [ ]; |
|
272 | 272 | foreach ( $this->cookiesToSet as $cname => $cval ) { |
273 | - $cookies[] = trim( "$cname=$cval" ); |
|
273 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
274 | 274 | } |
275 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
275 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
276 | 276 | } |
277 | 277 | return $ret; |
278 | 278 | } |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string[] $headers |
284 | 284 | * @return string |
285 | 285 | */ |
286 | - protected function buildHeadersString( array $headers ): string { |
|
286 | + protected function buildHeadersString ( array $headers ): string { |
|
287 | 287 | $ret = ''; |
288 | 288 | foreach ( $headers as $header ) { |
289 | 289 | $ret .= "$header\r\n"; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * @param string $actualParams |
296 | 296 | * @return string |
297 | 297 | */ |
298 | - protected function getDebugURL( string $actualParams ): string { |
|
298 | + protected function getDebugURL ( string $actualParams ): string { |
|
299 | 299 | return strpos( $this->url, 'login' ) !== false |
300 | 300 | ? '[Login request]' |
301 | 301 | : "{$this->url}?$actualParams"; |