@@ -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 | |
46 | 46 | /** @var LoggerInterface */ |
47 | 47 | protected $logger; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @phan-param array<int|string|bool> $params |
55 | 55 | * @param string $domain |
56 | 56 | */ |
57 | - public function __construct( LoggerInterface $logger, array $params, string $domain ) { |
|
57 | + public function __construct ( LoggerInterface $logger, array $params, string $domain ) { |
|
58 | 58 | $this->logger = $logger; |
59 | 59 | $this->params = [ 'format' => 'json' ] + $params; |
60 | 60 | $this->url = $domain; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return self For chaining |
67 | 67 | */ |
68 | - public function setPost(): self { |
|
68 | + public function setPost (): self { |
|
69 | 69 | $this->method = self::METHOD_POST; |
70 | 70 | return $this; |
71 | 71 | } |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | * Execute a query request |
75 | 75 | * @return Generator |
76 | 76 | */ |
77 | - public function executeAsQuery(): Generator { |
|
78 | - if ( ( $this->params['action'] ?? false ) !== 'query' ) { |
|
77 | + public function executeAsQuery (): Generator { |
|
78 | + if ( ( $this->params[ 'action' ] ?? false ) !== 'query' ) { |
|
79 | 79 | throw new BadMethodCallException( 'Not an ApiQuery!' ); |
80 | 80 | } |
81 | 81 | // TODO Is this always correct? |
82 | - $key = $this->params['list'] ?? 'pages'; |
|
82 | + $key = $this->params[ 'list' ] ?? 'pages'; |
|
83 | 83 | $curParams = $this->params; |
84 | 84 | $lim = $this->parseLimit(); |
85 | 85 | do { |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * Execute a request that doesn't need any continuation. |
109 | 109 | * @return stdClass |
110 | 110 | */ |
111 | - public function executeSingle(): stdClass { |
|
111 | + public function executeSingle (): stdClass { |
|
112 | 112 | $curParams = $this->params; |
113 | 113 | $res = $this->makeRequestInternal( $curParams ); |
114 | 114 | $this->handleErrorAndWarnings( $res ); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | /** |
119 | 119 | * @return int |
120 | 120 | */ |
121 | - private function parseLimit(): int { |
|
121 | + private function parseLimit (): int { |
|
122 | 122 | foreach ( $this->params as $name => $val ) { |
123 | 123 | if ( substr( $name, -strlen( 'limit' ) ) === 'limit' ) { |
124 | 124 | return $val === 'max' ? -1 : (int)$val; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @param string $resKey |
136 | 136 | * @return int|null |
137 | 137 | */ |
138 | - private function countQueryResults( stdClass $res, string $resKey ): ?int { |
|
138 | + private function countQueryResults ( stdClass $res, string $resKey ): ?int { |
|
139 | 139 | if ( !isset( $res->query->$resKey ) ) { |
140 | 140 | return null; |
141 | 141 | } |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | * @phan-param array<int|string|bool> $params |
164 | 164 | * @return stdClass |
165 | 165 | */ |
166 | - private function makeRequestInternal( array $params ): stdClass { |
|
166 | + private function makeRequestInternal ( array $params ): stdClass { |
|
167 | 167 | if ( $this->method === self::METHOD_POST ) { |
168 | - $params['maxlag'] = self::MAXLAG; |
|
168 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
169 | 169 | } |
170 | - if ( !isset( $params['assert'] ) ) { |
|
171 | - $params['assert'] = 'user'; |
|
170 | + if ( !isset( $params[ 'assert' ] ) ) { |
|
171 | + $params[ 'assert' ] = 'user'; |
|
172 | 172 | } |
173 | 173 | $query = http_build_query( $params ); |
174 | 174 | |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | * @param string $params |
190 | 190 | * @return string |
191 | 191 | */ |
192 | - abstract protected function reallyMakeRequest( string $params ): string; |
|
192 | + abstract protected function reallyMakeRequest ( string $params ): string; |
|
193 | 193 | |
194 | 194 | /** |
195 | 195 | * After a request, set cookies for the next ones |
196 | 196 | * |
197 | 197 | * @param string[] $cookies |
198 | 198 | */ |
199 | - protected function setCookies( array $cookies ): void { |
|
199 | + protected function setCookies ( array $cookies ): void { |
|
200 | 200 | foreach ( $cookies as $cookie ) { |
201 | 201 | /** @var string[] $bits */ |
202 | 202 | $bits = explode( ';', $cookie ); |
203 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
203 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
204 | 204 | self::$cookiesToSet[ $name ] = $value; |
205 | 205 | } |
206 | 206 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @param stdClass $res |
212 | 212 | * @return APIRequestException |
213 | 213 | */ |
214 | - private function getException( stdClass $res ): APIRequestException { |
|
214 | + private function getException ( stdClass $res ): APIRequestException { |
|
215 | 215 | switch ( $res->error->code ) { |
216 | 216 | case 'missingtitle': |
217 | 217 | $ex = new MissingPageException; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @param stdClass $res |
238 | 238 | * @throws APIRequestException |
239 | 239 | */ |
240 | - protected function handleErrorAndWarnings( stdClass $res ): void { |
|
240 | + protected function handleErrorAndWarnings ( stdClass $res ): void { |
|
241 | 241 | if ( isset( $res->error ) ) { |
242 | 242 | throw $this->getException( $res ); |
243 | 243 | } |
@@ -253,14 +253,14 @@ discard block |
||
253 | 253 | * |
254 | 254 | * @return string[] |
255 | 255 | */ |
256 | - protected function getHeaders(): array { |
|
256 | + protected function getHeaders (): array { |
|
257 | 257 | $ret = self::HEADERS; |
258 | 258 | if ( self::$cookiesToSet ) { |
259 | - $cookies = []; |
|
259 | + $cookies = [ ]; |
|
260 | 260 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
261 | - $cookies[] = trim( "$cname=$cval" ); |
|
261 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
262 | 262 | } |
263 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
263 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
264 | 264 | } |
265 | 265 | return $ret; |
266 | 266 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @param string[] $headers |
272 | 272 | * @return string |
273 | 273 | */ |
274 | - protected function buildHeadersString( array $headers ): string { |
|
274 | + protected function buildHeadersString ( array $headers ): string { |
|
275 | 275 | $ret = ''; |
276 | 276 | foreach ( $headers as $header ) { |
277 | 277 | $ret .= "$header\r\n"; |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string $actualParams |
284 | 284 | * @return string |
285 | 285 | */ |
286 | - protected function getDebugURL( string $actualParams ): string { |
|
286 | + protected function getDebugURL ( string $actualParams ): string { |
|
287 | 287 | return strpos( $this->url, 'login' ) !== false |
288 | 288 | ? '[Login request]' |
289 | 289 | : "{$this->url}?$actualParams"; |