Passed
Push — master ( ebe4f4...85a9ba )
by Daimona
02:09
created
includes/Request/RequestBase.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
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
 block discarded – undo
29 29
 	/** @var string */
30 30
 	protected $method;
31 31
 	/** @var string[] */
32
-	protected $newCookies = [];
32
+	protected $newCookies = [ ];
33 33
 	/** @var int */
34 34
 	private $limit = -1;
35 35
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 * @param array $params
40 40
 	 * @param bool $isPOST
41 41
 	 */
42
-	protected function __construct( array $params, bool $isPOST = false ) {
42
+	protected function __construct ( array $params, bool $isPOST = false ) {
43 43
 		$this->params = [ 'format' => 'json' ] + $params;
44 44
 		$this->method = $isPOST ? 'POST' : 'GET';
45 45
 	}
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @param bool $isPOST
52 52
 	 * @return self
53 53
 	 */
54
-	public static function newFromParams( array $params, bool $isPOST = false ) : self {
54
+	public static function newFromParams ( array $params, bool $isPOST = false ) : self {
55 55
 		if ( extension_loaded( 'curl' ) ) {
56 56
 			$ret = new CurlRequest( $params, $isPOST );
57 57
 		} else {
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @param int $val
67 67
 	 */
68
-	public function setResultLimit( int $val ) {
68
+	public function setResultLimit ( int $val ) {
69 69
 		$this->limit = $val;
70 70
 	}
71 71
 
@@ -74,16 +74,16 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return \stdClass
76 76
 	 */
77
-	public function execute() : \stdClass {
77
+	public function execute () : \stdClass {
78 78
 		$curParams = $this->params;
79
-		$sets = [];
79
+		$sets = [ ];
80 80
 		$amount = 0;
81 81
 		do {
82 82
 			$res = $this->makeRequestInternal( $curParams );
83 83
 			$amount += count( $res );
84 84
 
85 85
 			$this->handleErrorAndWarnings( $res );
86
-			$sets[] = $res;
86
+			$sets[ ] = $res;
87 87
 
88 88
 			$finished = true;
89 89
 			if ( isset( $res->continue ) && $this->limit > -1 && $amount < $this->limit ) {
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 	 * @param array $params
102 102
 	 * @return \stdClass
103 103
 	 */
104
-	private function makeRequestInternal( array $params ) : \stdClass {
104
+	private function makeRequestInternal ( array $params ) : \stdClass {
105 105
 		if ( $this->method === 'POST' ) {
106
-			$params['maxlag'] = self::MAXLAG;
106
+			$params[ 'maxlag' ] = self::MAXLAG;
107 107
 		}
108 108
 		$params = http_build_query( $params );
109 109
 
@@ -119,17 +119,17 @@  discard block
 block discarded – undo
119 119
 	 * @param string $params
120 120
 	 * @return string
121 121
 	 */
122
-	abstract protected function reallyMakeRequest( string $params ) : string;
122
+	abstract protected function reallyMakeRequest ( string $params ) : string;
123 123
 
124 124
 	/**
125 125
 	 * After a request, set cookies for the next ones
126 126
 	 *
127 127
 	 * @param array $cookies
128 128
 	 */
129
-	protected function setCookies( array $cookies ) {
129
+	protected function setCookies ( array $cookies ) {
130 130
 		foreach ( $cookies as $cookie ) {
131 131
 			$bits = explode( ';', $cookie );
132
-			list( $name, $value ) = explode( '=', $bits[0] );
132
+			list( $name, $value ) = explode( '=', $bits[ 0 ] );
133 133
 			self::$cookiesToSet[ $name ] = $value;
134 134
 		}
135 135
 	}
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 * @param \stdClass $res
141 141
 	 * @throws APIRequestException
142 142
 	 */
143
-	protected function handleErrorAndWarnings( $res ) {
143
+	protected function handleErrorAndWarnings ( $res ) {
144 144
 		if ( isset( $res->error ) ) {
145 145
 			switch ( $res->error->code ) {
146 146
 				case 'missingtitle':
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 * @param \stdClass[] $sets
167 167
 	 * @return \stdClass
168 168
 	 */
169
-	private function mergeSets( array $sets ) : \stdClass {
169
+	private function mergeSets ( array $sets ) : \stdClass {
170 170
 		// Use the first set as template
171 171
 		$ret = array_shift( $sets );
172 172
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * @param array|\stdClass $second
184 184
 	 * @return array|\stdClass array
185 185
 	 */
186
-	private function recursiveMerge( $first, $second ) {
186
+	private function recursiveMerge ( $first, $second ) {
187 187
 		$ret = $first;
188 188
 		if ( is_array( $second ) ) {
189 189
 			$ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second;
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
 	 *
202 202
 	 * @return array
203 203
 	 */
204
-	protected function getHeaders() :array {
204
+	protected function getHeaders () :array {
205 205
 		$ret = self::HEADERS;
206 206
 		if ( self::$cookiesToSet ) {
207
-			$cookies = [];
207
+			$cookies = [ ];
208 208
 			foreach ( self::$cookiesToSet as $cname => $cval ) {
209
-				$cookies[] = trim( "$cname=$cval" );
209
+				$cookies[ ] = trim( "$cname=$cval" );
210 210
 			}
211
-			$ret[] = 'Cookie: ' . implode( '; ', $cookies );
211
+			$ret[ ] = 'Cookie: ' . implode( '; ', $cookies );
212 212
 		}
213 213
 		return $ret;
214 214
 	}
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 * @param array $headers
220 220
 	 * @return string
221 221
 	 */
222
-	protected function buildHeadersString( array $headers ) : string {
222
+	protected function buildHeadersString ( array $headers ) : string {
223 223
 		$ret = '';
224 224
 		foreach ( $headers as $header ) {
225 225
 			$ret .= "$header\r\n";
Please login to merge, or discard this patch.