@@ -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 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | /** |
| 10 | 10 | * @inheritDoc |
| 11 | 11 | */ |
| 12 | - protected function reallyMakeRequest( string $params ) : string { |
|
| 12 | + protected function reallyMakeRequest ( string $params ) : string { |
|
| 13 | 13 | $context = [ |
| 14 | 14 | 'http' => [ |
| 15 | 15 | 'method' => $this->method, |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | ]; |
| 19 | 19 | $url = $this->url; |
| 20 | 20 | if ( $this->method === self::METHOD_POST ) { |
| 21 | - $context['http']['content'] = $params; |
|
| 21 | + $context[ 'http' ][ 'content' ] = $params; |
|
| 22 | 22 | } else { |
| 23 | 23 | $url = "$url?$params"; |
| 24 | 24 | } |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | foreach ( $http_response_header as $header ) { |
| 29 | 29 | $bits = explode( ':', $header, 2 ); |
| 30 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
| 31 | - $this->newCookies[] = $bits[1]; |
|
| 30 | + if ( trim( $bits[ 0 ] ) === 'Set-Cookie' ) { |
|
| 31 | + $this->newCookies[ ] = $bits[ 1 ]; |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
@@ -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 | |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | /** @var string */ |
| 34 | 34 | protected $method = self::METHOD_GET; |
| 35 | 35 | /** @var string[] */ |
| 36 | - protected $newCookies = []; |
|
| 36 | + protected $newCookies = [ ]; |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Use self::newFromParams, which will provide the right class to use |
| 40 | 40 | * |
| 41 | 41 | * @param array $params |
| 42 | 42 | */ |
| 43 | - protected function __construct( array $params ) { |
|
| 43 | + protected function __construct ( array $params ) { |
|
| 44 | 44 | $this->params = [ 'format' => 'json' ] + $params; |
| 45 | 45 | $this->url = DEFAULT_URL; |
| 46 | 46 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param array $params |
| 52 | 52 | * @return self |
| 53 | 53 | */ |
| 54 | - public static function newFromParams( array $params ) : self { |
|
| 54 | + public static function newFromParams ( array $params ) : self { |
|
| 55 | 55 | if ( extension_loaded( 'curl' ) ) { |
| 56 | 56 | $ret = new CurlRequest( $params ); |
| 57 | 57 | } else { |
@@ -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 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param string $url |
| 77 | 77 | * @return self for chaining |
| 78 | 78 | */ |
| 79 | - public function setUrl( string $url ) : self { |
|
| 79 | + public function setUrl ( string $url ) : self { |
|
| 80 | 80 | $this->url = $url; |
| 81 | 81 | return $this; |
| 82 | 82 | } |
@@ -88,14 +88,14 @@ discard block |
||
| 88 | 88 | * @todo Return an iterable object which automatically continues the query only if the last |
| 89 | 89 | * entry available is reached. |
| 90 | 90 | */ |
| 91 | - public function execute() : \stdClass { |
|
| 91 | + public function execute () : \stdClass { |
|
| 92 | 92 | $curParams = $this->params; |
| 93 | - $sets = []; |
|
| 93 | + $sets = [ ]; |
|
| 94 | 94 | do { |
| 95 | 95 | $res = $this->makeRequestInternal( $curParams ); |
| 96 | 96 | |
| 97 | 97 | $this->handleErrorAndWarnings( $res ); |
| 98 | - $sets[] = $res; |
|
| 98 | + $sets[ ] = $res; |
|
| 99 | 99 | |
| 100 | 100 | $finished = true; |
| 101 | 101 | if ( isset( $res->continue ) ) { |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | * @param array $params |
| 114 | 114 | * @return \stdClass |
| 115 | 115 | */ |
| 116 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 116 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 117 | 117 | if ( $this->method === self::METHOD_POST ) { |
| 118 | - $params['maxlag'] = self::MAXLAG; |
|
| 118 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 119 | 119 | } |
| 120 | 120 | $query = http_build_query( $params ); |
| 121 | 121 | |
@@ -131,17 +131,17 @@ discard block |
||
| 131 | 131 | * @param string $params |
| 132 | 132 | * @return string |
| 133 | 133 | */ |
| 134 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 134 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | 137 | * After a request, set cookies for the next ones |
| 138 | 138 | * |
| 139 | 139 | * @param array $cookies |
| 140 | 140 | */ |
| 141 | - protected function setCookies( array $cookies ) : void { |
|
| 141 | + protected function setCookies ( array $cookies ) : void { |
|
| 142 | 142 | foreach ( $cookies as $cookie ) { |
| 143 | 143 | $bits = explode( ';', $cookie ); |
| 144 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
| 144 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
| 145 | 145 | self::$cookiesToSet[ $name ] = $value; |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param \stdClass $res |
| 153 | 153 | * @return APIRequestException |
| 154 | 154 | */ |
| 155 | - private function getException( \stdClass $res ) : APIRequestException { |
|
| 155 | + private function getException ( \stdClass $res ) : APIRequestException { |
|
| 156 | 156 | switch ( $res->error->code ) { |
| 157 | 157 | case 'missingtitle': |
| 158 | 158 | $ex = new MissingPageException; |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * @param \stdClass $res |
| 176 | 176 | * @throws APIRequestException |
| 177 | 177 | */ |
| 178 | - protected function handleErrorAndWarnings( \stdClass $res ) : void { |
|
| 178 | + protected function handleErrorAndWarnings ( \stdClass $res ) : void { |
|
| 179 | 179 | if ( isset( $res->error ) ) { |
| 180 | 180 | throw $this->getException( $res ); |
| 181 | 181 | } elseif ( isset( $res->warnings ) ) { |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @param \stdClass[] $sets |
| 192 | 192 | * @return \stdClass |
| 193 | 193 | */ |
| 194 | - private function mergeSets( array $sets ) : \stdClass { |
|
| 194 | + private function mergeSets ( array $sets ) : \stdClass { |
|
| 195 | 195 | // Use the first set as template |
| 196 | 196 | $ret = array_shift( $sets ); |
| 197 | 197 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @param array|\stdClass $second |
| 209 | 209 | * @return array|\stdClass array |
| 210 | 210 | */ |
| 211 | - private function recursiveMerge( $first, $second ) { |
|
| 211 | + private function recursiveMerge ( $first, $second ) { |
|
| 212 | 212 | $ret = $first; |
| 213 | 213 | if ( is_array( $second ) ) { |
| 214 | 214 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -226,14 +226,14 @@ discard block |
||
| 226 | 226 | * |
| 227 | 227 | * @return array |
| 228 | 228 | */ |
| 229 | - protected function getHeaders() :array { |
|
| 229 | + protected function getHeaders () :array { |
|
| 230 | 230 | $ret = self::HEADERS; |
| 231 | 231 | if ( self::$cookiesToSet ) { |
| 232 | - $cookies = []; |
|
| 232 | + $cookies = [ ]; |
|
| 233 | 233 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 234 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 234 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 235 | 235 | } |
| 236 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 236 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 237 | 237 | } |
| 238 | 238 | return $ret; |
| 239 | 239 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * @param array $headers |
| 245 | 245 | * @return string |
| 246 | 246 | */ |
| 247 | - protected function buildHeadersString( array $headers ) : string { |
|
| 247 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 248 | 248 | $ret = ''; |
| 249 | 249 | foreach ( $headers as $header ) { |
| 250 | 250 | $ret .= "$header\r\n"; |