@@ -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,14 +29,14 @@ discard block |
||
| 29 | 29 | /** @var string */ |
| 30 | 30 | protected $method = 'GET'; |
| 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 |
| 36 | 36 | * |
| 37 | 37 | * @param array $params |
| 38 | 38 | */ |
| 39 | - protected function __construct( array $params ) { |
|
| 39 | + protected function __construct ( array $params ) { |
|
| 40 | 40 | $this->params = [ 'format' => 'json' ] + $params; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @param array $params |
| 47 | 47 | * @return self |
| 48 | 48 | */ |
| 49 | - public static function newFromParams( array $params ) : self { |
|
| 49 | + public static function newFromParams ( array $params ) : self { |
|
| 50 | 50 | if ( extension_loaded( 'curl' ) ) { |
| 51 | 51 | $ret = new CurlRequest( $params ); |
| 52 | 52 | } else { |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @return self For chaining |
| 62 | 62 | */ |
| 63 | - public function post() : self { |
|
| 63 | + public function post () : self { |
|
| 64 | 64 | $this->method = 'POST'; |
| 65 | 65 | return $this; |
| 66 | 66 | } |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return \stdClass |
| 72 | 72 | */ |
| 73 | - public function execute() : \stdClass { |
|
| 73 | + public function execute () : \stdClass { |
|
| 74 | 74 | $curParams = $this->params; |
| 75 | - $sets = []; |
|
| 75 | + $sets = [ ]; |
|
| 76 | 76 | do { |
| 77 | 77 | $res = $this->makeRequestInternal( $curParams ); |
| 78 | 78 | |
| 79 | 79 | $this->handleErrorAndWarnings( $res ); |
| 80 | - $sets[] = $res; |
|
| 80 | + $sets[ ] = $res; |
|
| 81 | 81 | |
| 82 | 82 | $finished = true; |
| 83 | 83 | if ( isset( $res->continue ) ) { |
@@ -95,9 +95,9 @@ discard block |
||
| 95 | 95 | * @param array $params |
| 96 | 96 | * @return \stdClass |
| 97 | 97 | */ |
| 98 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 98 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 99 | 99 | if ( $this->method === 'POST' ) { |
| 100 | - $params['maxlag'] = self::MAXLAG; |
|
| 100 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 101 | 101 | } |
| 102 | 102 | $params = http_build_query( $params ); |
| 103 | 103 | |
@@ -113,17 +113,17 @@ discard block |
||
| 113 | 113 | * @param string $params |
| 114 | 114 | * @return string |
| 115 | 115 | */ |
| 116 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 116 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 117 | 117 | |
| 118 | 118 | /** |
| 119 | 119 | * After a request, set cookies for the next ones |
| 120 | 120 | * |
| 121 | 121 | * @param array $cookies |
| 122 | 122 | */ |
| 123 | - protected function setCookies( array $cookies ) { |
|
| 123 | + protected function setCookies ( array $cookies ) { |
|
| 124 | 124 | foreach ( $cookies as $cookie ) { |
| 125 | 125 | $bits = explode( ';', $cookie ); |
| 126 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
| 126 | + list( $name, $value ) = explode( '=', $bits[ 0 ] ); |
|
| 127 | 127 | self::$cookiesToSet[ $name ] = $value; |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param \stdClass $res |
| 135 | 135 | * @throws APIRequestException |
| 136 | 136 | */ |
| 137 | - protected function handleErrorAndWarnings( $res ) { |
|
| 137 | + protected function handleErrorAndWarnings ( $res ) { |
|
| 138 | 138 | if ( isset( $res->error ) ) { |
| 139 | 139 | switch ( $res->error->code ) { |
| 140 | 140 | case 'missingtitle': |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @param \stdClass[] $sets |
| 161 | 161 | * @return \stdClass |
| 162 | 162 | */ |
| 163 | - private function mergeSets( array $sets ) : \stdClass { |
|
| 163 | + private function mergeSets ( array $sets ) : \stdClass { |
|
| 164 | 164 | // Use the first set as template |
| 165 | 165 | $ret = array_shift( $sets ); |
| 166 | 166 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @param array|\stdClass $second |
| 178 | 178 | * @return array|\stdClass array |
| 179 | 179 | */ |
| 180 | - private function recursiveMerge( $first, $second ) { |
|
| 180 | + private function recursiveMerge ( $first, $second ) { |
|
| 181 | 181 | $ret = $first; |
| 182 | 182 | if ( is_array( $second ) ) { |
| 183 | 183 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -195,14 +195,14 @@ discard block |
||
| 195 | 195 | * |
| 196 | 196 | * @return array |
| 197 | 197 | */ |
| 198 | - protected function getHeaders() :array { |
|
| 198 | + protected function getHeaders () :array { |
|
| 199 | 199 | $ret = self::HEADERS; |
| 200 | 200 | if ( self::$cookiesToSet ) { |
| 201 | - $cookies = []; |
|
| 201 | + $cookies = [ ]; |
|
| 202 | 202 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 203 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 203 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 204 | 204 | } |
| 205 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 205 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 206 | 206 | } |
| 207 | 207 | return $ret; |
| 208 | 208 | } |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @param array $headers |
| 214 | 214 | * @return string |
| 215 | 215 | */ |
| 216 | - protected function buildHeadersString( array $headers ) : string { |
|
| 216 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 217 | 217 | $ret = ''; |
| 218 | 218 | foreach ( $headers as $header ) { |
| 219 | 219 | $ret .= "$header\r\n"; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme; |
| 4 | 4 | |
@@ -12,12 +12,12 @@ discard block |
||
| 12 | 12 | /** @var self */ |
| 13 | 13 | private static $instance; |
| 14 | 14 | /** @var array */ |
| 15 | - private $opts = []; |
|
| 15 | + private $opts = [ ]; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Use self::init() and self::getInstance() |
| 19 | 19 | */ |
| 20 | - private function __construct() { |
|
| 20 | + private function __construct () { |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | * @param array $defaults |
| 27 | 27 | * @throws ConfigException |
| 28 | 28 | */ |
| 29 | - public static function init( array $defaults ) { |
|
| 29 | + public static function init ( array $defaults ) { |
|
| 30 | 30 | if ( self::$instance ) { |
| 31 | 31 | throw new ConfigException( 'Config was already initialized' ); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $inst = new self; |
| 35 | - $inst->set( 'list-title', $defaults['list-title'] ); |
|
| 36 | - $inst->set( 'msg-title', $defaults['msg-title'] ); |
|
| 37 | - $inst->set( 'username', $defaults['username'] ); |
|
| 38 | - $inst->set( 'password', $defaults['password'] ); |
|
| 35 | + $inst->set( 'list-title', $defaults[ 'list-title' ] ); |
|
| 36 | + $inst->set( 'msg-title', $defaults[ 'msg-title' ] ); |
|
| 37 | + $inst->set( 'username', $defaults[ 'username' ] ); |
|
| 38 | + $inst->set( 'password', $defaults[ 'password' ] ); |
|
| 39 | 39 | self::$instance = $inst; |
| 40 | 40 | |
| 41 | 41 | // On-wiki values |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param string $key |
| 55 | 55 | * @return string |
| 56 | 56 | */ |
| 57 | - public function getWikiMessage( string $key ) : string { |
|
| 57 | + public function getWikiMessage ( string $key ) : string { |
|
| 58 | 58 | static $messages = null; |
| 59 | 59 | if ( $messages === null ) { |
| 60 | 60 | try { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
| 68 | - return $messages[$key]; |
|
| 68 | + return $messages[ $key ]; |
|
| 69 | 69 | } |
| 70 | 70 | /** |
| 71 | 71 | * Set a config value. |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param string $key |
| 74 | 74 | * @param mixed $value |
| 75 | 75 | */ |
| 76 | - protected function set( string $key, $value ) { |
|
| 76 | + protected function set ( string $key, $value ) { |
|
| 77 | 77 | $this->opts[ $key ] = $value; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @return self |
| 84 | 84 | * @throws ConfigException |
| 85 | 85 | */ |
| 86 | - public static function getInstance() : self { |
|
| 86 | + public static function getInstance () : self { |
|
| 87 | 87 | if ( !self::$instance ) { |
| 88 | 88 | throw new ConfigException( 'Config not yet initialized' ); |
| 89 | 89 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @return mixed |
| 98 | 98 | * @throws ConfigException |
| 99 | 99 | */ |
| 100 | - public function get( string $opt ) { |
|
| 100 | + public function get ( string $opt ) { |
|
| 101 | 101 | if ( !isset( $this->opts[ $opt ] ) ) { |
| 102 | 102 | throw new ConfigException( "Config option '$opt' not set." ); |
| 103 | 103 | } |