@@ -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 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | /** @var string */ |
| 33 | 33 | protected $method = self::METHOD_GET; |
| 34 | 34 | /** @var string[] */ |
| 35 | - protected $newCookies = []; |
|
| 35 | + protected $newCookies = [ ]; |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * @private Use RequestFactory |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param array $params |
| 41 | 41 | * @param string $domain |
| 42 | 42 | */ |
| 43 | - public function __construct( array $params, string $domain ) { |
|
| 43 | + public function __construct ( array $params, string $domain ) { |
|
| 44 | 44 | $this->params = [ 'format' => 'json' ] + $params; |
| 45 | 45 | $this->url = $domain; |
| 46 | 46 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return self For chaining |
| 52 | 52 | */ |
| 53 | - public function setPost() : self { |
|
| 53 | + public function setPost () : self { |
|
| 54 | 54 | $this->method = self::METHOD_POST; |
| 55 | 55 | return $this; |
| 56 | 56 | } |
@@ -62,15 +62,15 @@ discard block |
||
| 62 | 62 | * @todo Return an iterable object which automatically continues the query only if the last |
| 63 | 63 | * entry available is reached, instead of requesting max results. |
| 64 | 64 | */ |
| 65 | - public function execute() : \stdClass { |
|
| 65 | + public function execute () : \stdClass { |
|
| 66 | 66 | $curParams = $this->params; |
| 67 | 67 | $lim = $this->parseLimit(); |
| 68 | - $sets = []; |
|
| 68 | + $sets = [ ]; |
|
| 69 | 69 | do { |
| 70 | 70 | $res = $this->makeRequestInternal( $curParams ); |
| 71 | 71 | |
| 72 | 72 | $this->handleErrorAndWarnings( $res ); |
| 73 | - $sets[] = $res; |
|
| 73 | + $sets[ ] = $res; |
|
| 74 | 74 | |
| 75 | 75 | // Assume that we have finished |
| 76 | 76 | $finished = true; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * FIXME Should be revamped together with countResults |
| 96 | 96 | * @return int |
| 97 | 97 | */ |
| 98 | - private function parseLimit() : int { |
|
| 98 | + private function parseLimit () : int { |
|
| 99 | 99 | foreach ( $this->params as $name => $val ) { |
| 100 | 100 | if ( substr( $name, -strlen( 'limit' ) ) === 'limit' ) { |
| 101 | 101 | return $val === 'max' ? -1 : (int)$val; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param \stdClass $res |
| 114 | 114 | * @return int|null |
| 115 | 115 | */ |
| 116 | - private function countResults( \stdClass $res ) : ?int { |
|
| 116 | + private function countResults ( \stdClass $res ) : ?int { |
|
| 117 | 117 | if ( isset( $res->query->pages ) && count( get_object_vars( $res->query->pages ) ) === 1 ) { |
| 118 | 118 | $pages = $res->query->pages; |
| 119 | 119 | return count( reset( $pages )->revisions ); |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | * @param array $params |
| 128 | 128 | * @return \stdClass |
| 129 | 129 | */ |
| 130 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 130 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 131 | 131 | if ( $this->method === self::METHOD_POST ) { |
| 132 | - $params['maxlag'] = self::MAXLAG; |
|
| 132 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 133 | 133 | } |
| 134 | 134 | $query = http_build_query( $params ); |
| 135 | 135 | |
@@ -145,17 +145,17 @@ discard block |
||
| 145 | 145 | * @param string $params |
| 146 | 146 | * @return string |
| 147 | 147 | */ |
| 148 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 148 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * After a request, set cookies for the next ones |
| 152 | 152 | * |
| 153 | 153 | * @param array $cookies |
| 154 | 154 | */ |
| 155 | - protected function setCookies( array $cookies ) : void { |
|
| 155 | + protected function setCookies ( array $cookies ) : void { |
|
| 156 | 156 | foreach ( $cookies as $cookie ) { |
| 157 | 157 | $bits = explode( ';', $cookie ); |
| 158 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
| 158 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
| 159 | 159 | self::$cookiesToSet[ $name ] = $value; |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param \stdClass $res |
| 167 | 167 | * @return APIRequestException |
| 168 | 168 | */ |
| 169 | - private function getException( \stdClass $res ) : APIRequestException { |
|
| 169 | + private function getException ( \stdClass $res ) : APIRequestException { |
|
| 170 | 170 | switch ( $res->error->code ) { |
| 171 | 171 | case 'missingtitle': |
| 172 | 172 | $ex = new MissingPageException; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @param \stdClass $res |
| 190 | 190 | * @throws APIRequestException |
| 191 | 191 | */ |
| 192 | - protected function handleErrorAndWarnings( \stdClass $res ) : void { |
|
| 192 | + protected function handleErrorAndWarnings ( \stdClass $res ) : void { |
|
| 193 | 193 | if ( isset( $res->error ) ) { |
| 194 | 194 | throw $this->getException( $res ); |
| 195 | 195 | } elseif ( isset( $res->warnings ) ) { |
@@ -205,9 +205,9 @@ discard block |
||
| 205 | 205 | * @param \stdClass[] $sets |
| 206 | 206 | * @return \stdClass |
| 207 | 207 | */ |
| 208 | - private function mergeSets( array $sets ) : \stdClass { |
|
| 208 | + private function mergeSets ( array $sets ) : \stdClass { |
|
| 209 | 209 | if ( !$sets ) { |
| 210 | - return (object)[]; |
|
| 210 | + return (object)[ ]; |
|
| 211 | 211 | } |
| 212 | 212 | // Use the first set as template |
| 213 | 213 | $ret = array_shift( $sets ); |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param array|\stdClass $second |
| 226 | 226 | * @return array|\stdClass array |
| 227 | 227 | */ |
| 228 | - private function recursiveMerge( $first, $second ) { |
|
| 228 | + private function recursiveMerge ( $first, $second ) { |
|
| 229 | 229 | $ret = $first; |
| 230 | 230 | if ( is_array( $second ) ) { |
| 231 | 231 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | * |
| 244 | 244 | * @return array |
| 245 | 245 | */ |
| 246 | - protected function getHeaders() :array { |
|
| 246 | + protected function getHeaders () :array { |
|
| 247 | 247 | $ret = self::HEADERS; |
| 248 | 248 | if ( self::$cookiesToSet ) { |
| 249 | - $cookies = []; |
|
| 249 | + $cookies = [ ]; |
|
| 250 | 250 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 251 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 251 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 252 | 252 | } |
| 253 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 253 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 254 | 254 | } |
| 255 | 255 | return $ret; |
| 256 | 256 | } |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * @param array $headers |
| 262 | 262 | * @return string |
| 263 | 263 | */ |
| 264 | - protected function buildHeadersString( array $headers ) : string { |
|
| 264 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 265 | 265 | $ret = ''; |
| 266 | 266 | foreach ( $headers as $header ) { |
| 267 | 267 | $ret .= "$header\r\n"; |