@@ -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 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | /** @var string */ |
| 30 | 30 | protected $method; |
| 31 | 31 | /** @var string[] */ |
| 32 | - protected $newCookies = []; |
|
| 32 | + protected $newCookies = [ ]; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Use self::newFromParams, which will provide the right class to use |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param array $params |
| 38 | 38 | * @param bool $isPOST |
| 39 | 39 | */ |
| 40 | - protected function __construct( array $params, bool $isPOST = false ) { |
|
| 40 | + protected function __construct ( array $params, bool $isPOST = false ) { |
|
| 41 | 41 | $this->params = [ 'format' => 'json' ] + $params; |
| 42 | 42 | $this->method = $isPOST ? 'POST' : 'GET'; |
| 43 | 43 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @param bool $isPOST |
| 50 | 50 | * @return self |
| 51 | 51 | */ |
| 52 | - public static function newFromParams( array $params, bool $isPOST = false ) : self { |
|
| 52 | + public static function newFromParams ( array $params, bool $isPOST = false ) : self { |
|
| 53 | 53 | if ( extension_loaded( 'curl' ) ) { |
| 54 | 54 | $ret = new CurlRequest( $params, $isPOST ); |
| 55 | 55 | } else { |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return \stdClass |
| 65 | 65 | */ |
| 66 | - public function execute() : \stdClass { |
|
| 66 | + public function execute () : \stdClass { |
|
| 67 | 67 | $curParams = $this->params; |
| 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 | $finished = true; |
| 76 | 76 | if ( isset( $res->continue ) ) { |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | * @param array $params |
| 89 | 89 | * @return \stdClass |
| 90 | 90 | */ |
| 91 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 91 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 92 | 92 | if ( $this->method === 'POST' ) { |
| 93 | - $params['maxlag'] = self::MAXLAG; |
|
| 93 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 94 | 94 | } |
| 95 | 95 | $params = http_build_query( $params ); |
| 96 | 96 | |
@@ -106,17 +106,17 @@ discard block |
||
| 106 | 106 | * @param string $params |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 109 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | 112 | * After a request, set cookies for the next ones |
| 113 | 113 | * |
| 114 | 114 | * @param array $cookies |
| 115 | 115 | */ |
| 116 | - protected function setCookies( array $cookies ) { |
|
| 116 | + protected function setCookies ( array $cookies ) { |
|
| 117 | 117 | foreach ( $cookies as $cookie ) { |
| 118 | 118 | $bits = explode( ';', $cookie ); |
| 119 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
| 119 | + list( $name, $value ) = explode( '=', $bits[ 0 ] ); |
|
| 120 | 120 | self::$cookiesToSet[ $name ] = $value; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param \stdClass $res |
| 128 | 128 | * @throws APIRequestException |
| 129 | 129 | */ |
| 130 | - protected function handleErrorAndWarnings( $res ) { |
|
| 130 | + protected function handleErrorAndWarnings ( $res ) { |
|
| 131 | 131 | if ( isset( $res->error ) ) { |
| 132 | 132 | switch ( $res->error->code ) { |
| 133 | 133 | case 'missingtitle': |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param \stdClass[] $sets |
| 154 | 154 | * @return \stdClass |
| 155 | 155 | */ |
| 156 | - private function mergeSets( array $sets ) : \stdClass { |
|
| 156 | + private function mergeSets ( array $sets ) : \stdClass { |
|
| 157 | 157 | // Use the first set as template |
| 158 | 158 | $ret = array_shift( $sets ); |
| 159 | 159 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param array|\stdClass $second |
| 171 | 171 | * @return array|\stdClass array |
| 172 | 172 | */ |
| 173 | - private function recursiveMerge( $first, $second ) { |
|
| 173 | + private function recursiveMerge ( $first, $second ) { |
|
| 174 | 174 | $ret = $first; |
| 175 | 175 | if ( is_array( $second ) ) { |
| 176 | 176 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -193,14 +193,14 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @return array |
| 195 | 195 | */ |
| 196 | - protected function getHeaders() :array { |
|
| 196 | + protected function getHeaders () :array { |
|
| 197 | 197 | $ret = self::HEADERS; |
| 198 | 198 | if ( self::$cookiesToSet ) { |
| 199 | - $cookies = []; |
|
| 199 | + $cookies = [ ]; |
|
| 200 | 200 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 201 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 201 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 202 | 202 | } |
| 203 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 203 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 204 | 204 | } |
| 205 | 205 | return $ret; |
| 206 | 206 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @param array $headers |
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | - protected function buildHeadersString( array $headers ) : string { |
|
| 214 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 215 | 215 | $ret = ''; |
| 216 | 216 | foreach ( $headers as $header ) { |
| 217 | 217 | $ret .= "$header\r\n"; |