@@ -1,4 +1,4 @@ |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Exception; |
| 4 | 4 | |
@@ -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 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * @param LoggerInterface $logger |
| 15 | 15 | * @param string $domain |
| 16 | 16 | */ |
| 17 | - public function __construct( LoggerInterface $logger, string $domain ) { |
|
| 17 | + public function __construct ( LoggerInterface $logger, string $domain ) { |
|
| 18 | 18 | $this->logger = $logger; |
| 19 | 19 | $this->domain = $domain; |
| 20 | 20 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * @phan-param array<int|string|bool> $params |
| 25 | 25 | * @return RequestBase |
| 26 | 26 | */ |
| 27 | - public function newFromParams( array $params ) : RequestBase { |
|
| 27 | + public function newFromParams ( array $params ) : RequestBase { |
|
| 28 | 28 | if ( extension_loaded( 'curl' ) ) { |
| 29 | 29 | return new CurlRequest( $this->logger, $params, $this->domain ); |
| 30 | 30 | } |
@@ -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,9 +163,9 @@ 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 | 170 | $query = http_build_query( $params ); |
| 171 | 171 | |
@@ -186,17 +186,17 @@ discard block |
||
| 186 | 186 | * @param string $params |
| 187 | 187 | * @return string |
| 188 | 188 | */ |
| 189 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 189 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | 192 | * After a request, set cookies for the next ones |
| 193 | 193 | * |
| 194 | 194 | * @param string[] $cookies |
| 195 | 195 | */ |
| 196 | - protected function setCookies( array $cookies ) : void { |
|
| 196 | + protected function setCookies ( array $cookies ) : void { |
|
| 197 | 197 | foreach ( $cookies as $cookie ) { |
| 198 | 198 | $bits = explode( ';', $cookie ); |
| 199 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
| 199 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
| 200 | 200 | self::$cookiesToSet[ $name ] = $value; |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * @param stdClass $res |
| 208 | 208 | * @return APIRequestException |
| 209 | 209 | */ |
| 210 | - private function getException( stdClass $res ) : APIRequestException { |
|
| 210 | + private function getException ( stdClass $res ) : APIRequestException { |
|
| 211 | 211 | switch ( $res->error->code ) { |
| 212 | 212 | case 'missingtitle': |
| 213 | 213 | $ex = new MissingPageException; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @param stdClass $res |
| 234 | 234 | * @throws APIRequestException |
| 235 | 235 | */ |
| 236 | - protected function handleErrorAndWarnings( stdClass $res ) : void { |
|
| 236 | + protected function handleErrorAndWarnings ( stdClass $res ) : void { |
|
| 237 | 237 | if ( isset( $res->error ) ) { |
| 238 | 238 | throw $this->getException( $res ); |
| 239 | 239 | } |
@@ -249,14 +249,14 @@ discard block |
||
| 249 | 249 | * |
| 250 | 250 | * @return string[] |
| 251 | 251 | */ |
| 252 | - protected function getHeaders() : array { |
|
| 252 | + protected function getHeaders () : array { |
|
| 253 | 253 | $ret = self::HEADERS; |
| 254 | 254 | if ( self::$cookiesToSet ) { |
| 255 | - $cookies = []; |
|
| 255 | + $cookies = [ ]; |
|
| 256 | 256 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 257 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 257 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 258 | 258 | } |
| 259 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 259 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 260 | 260 | } |
| 261 | 261 | return $ret; |
| 262 | 262 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @param string[] $headers |
| 268 | 268 | * @return string |
| 269 | 269 | */ |
| 270 | - protected function buildHeadersString( array $headers ) : string { |
|
| 270 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 271 | 271 | $ret = ''; |
| 272 | 272 | foreach ( $headers as $header ) { |
| 273 | 273 | $ret .= "$header\r\n"; |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @param string $actualParams |
| 280 | 280 | * @return string |
| 281 | 281 | */ |
| 282 | - protected function getDebugURL( string $actualParams ) : string { |
|
| 282 | + protected function getDebugURL ( string $actualParams ) : string { |
|
| 283 | 283 | return strpos( $this->url, 'login' ) !== false |
| 284 | 284 | ? '[Login request]' |
| 285 | 285 | : "{$this->url}?$actualParams"; |