Passed
Push — master ( 5a8341...4cf7bd )
by Daimona
01:31
created
includes/Request/RequestBase.php 1 patch
Spacing   +23 added lines, -23 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
 
@@ -30,14 +30,14 @@  discard block
 block discarded – undo
30 30
 	/** @var string */
31 31
 	protected $method = 'GET';
32 32
 	/** @var string[] */
33
-	protected $newCookies = [];
33
+	protected $newCookies = [ ];
34 34
 
35 35
 	/**
36 36
 	 * Use self::newFromParams, which will provide the right class to use
37 37
 	 *
38 38
 	 * @param array $params
39 39
 	 */
40
-	protected function __construct( array $params ) {
40
+	protected function __construct ( array $params ) {
41 41
 		$this->params = [ 'format' => 'json' ] + $params;
42 42
 		$this->url = DEFAULT_URL;
43 43
 	}
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @param array $params
49 49
 	 * @return self
50 50
 	 */
51
-	public static function newFromParams( array $params ) : self {
51
+	public static function newFromParams ( array $params ) : self {
52 52
 		if ( extension_loaded( 'curl' ) ) {
53 53
 			$ret = new CurlRequest( $params );
54 54
 		} else {
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @return self For chaining
64 64
 	 */
65
-	public function setPost() : self {
65
+	public function setPost () : self {
66 66
 		$this->method = 'POST';
67 67
 		return $this;
68 68
 	}
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @param string $url
74 74
 	 * @return self for chaining
75 75
 	 */
76
-	public function setUrl( string $url ) : self {
76
+	public function setUrl ( string $url ) : self {
77 77
 		$this->url = $url;
78 78
 		return $this;
79 79
 	}
@@ -83,14 +83,14 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @return \stdClass
85 85
 	 */
86
-	public function execute() : \stdClass {
86
+	public function execute () : \stdClass {
87 87
 		$curParams = $this->params;
88
-		$sets = [];
88
+		$sets = [ ];
89 89
 		do {
90 90
 			$res = $this->makeRequestInternal( $curParams );
91 91
 
92 92
 			$this->handleErrorAndWarnings( $res );
93
-			$sets[] = $res;
93
+			$sets[ ] = $res;
94 94
 
95 95
 			$finished = true;
96 96
 			if ( isset( $res->continue ) ) {
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 	 * @param array $params
109 109
 	 * @return \stdClass
110 110
 	 */
111
-	private function makeRequestInternal( array $params ) : \stdClass {
111
+	private function makeRequestInternal ( array $params ) : \stdClass {
112 112
 		if ( $this->method === 'POST' ) {
113
-			$params['maxlag'] = self::MAXLAG;
113
+			$params[ 'maxlag' ] = self::MAXLAG;
114 114
 		}
115 115
 		$params = http_build_query( $params );
116 116
 
@@ -126,17 +126,17 @@  discard block
 block discarded – undo
126 126
 	 * @param string $params
127 127
 	 * @return string
128 128
 	 */
129
-	abstract protected function reallyMakeRequest( string $params ) : string;
129
+	abstract protected function reallyMakeRequest ( string $params ) : string;
130 130
 
131 131
 	/**
132 132
 	 * After a request, set cookies for the next ones
133 133
 	 *
134 134
 	 * @param array $cookies
135 135
 	 */
136
-	protected function setCookies( array $cookies ) {
136
+	protected function setCookies ( array $cookies ) {
137 137
 		foreach ( $cookies as $cookie ) {
138 138
 			$bits = explode( ';', $cookie );
139
-			list( $name, $value ) = explode( '=', $bits[0] );
139
+			list( $name, $value ) = explode( '=', $bits[ 0 ] );
140 140
 			self::$cookiesToSet[ $name ] = $value;
141 141
 		}
142 142
 	}
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 * @param \stdClass $res
148 148
 	 * @return APIRequestException
149 149
 	 */
150
-	private function getException( \stdClass $res ) : APIRequestException {
150
+	private function getException ( \stdClass $res ) : APIRequestException {
151 151
 		switch ( $res->error->code ) {
152 152
 			case 'missingtitle':
153 153
 				$ex = new MissingPageException;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @param \stdClass $res
171 171
 	 * @throws APIRequestException
172 172
 	 */
173
-	protected function handleErrorAndWarnings( \stdClass $res ) {
173
+	protected function handleErrorAndWarnings ( \stdClass $res ) {
174 174
 		if ( isset( $res->error ) ) {
175 175
 			throw $this->getException( $res );
176 176
 		} elseif ( isset( $res->warnings ) ) {
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	 * @param \stdClass[] $sets
187 187
 	 * @return \stdClass
188 188
 	 */
189
-	private function mergeSets( array $sets ) : \stdClass {
189
+	private function mergeSets ( array $sets ) : \stdClass {
190 190
 		// Use the first set as template
191 191
 		$ret = array_shift( $sets );
192 192
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @param array|\stdClass $second
204 204
 	 * @return array|\stdClass array
205 205
 	 */
206
-	private function recursiveMerge( $first, $second ) {
206
+	private function recursiveMerge ( $first, $second ) {
207 207
 		$ret = $first;
208 208
 		if ( is_array( $second ) ) {
209 209
 			$ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second;
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 	 *
222 222
 	 * @return array
223 223
 	 */
224
-	protected function getHeaders() :array {
224
+	protected function getHeaders () :array {
225 225
 		$ret = self::HEADERS;
226 226
 		if ( self::$cookiesToSet ) {
227
-			$cookies = [];
227
+			$cookies = [ ];
228 228
 			foreach ( self::$cookiesToSet as $cname => $cval ) {
229
-				$cookies[] = trim( "$cname=$cval" );
229
+				$cookies[ ] = trim( "$cname=$cval" );
230 230
 			}
231
-			$ret[] = 'Cookie: ' . implode( '; ', $cookies );
231
+			$ret[ ] = 'Cookie: ' . implode( '; ', $cookies );
232 232
 		}
233 233
 		return $ret;
234 234
 	}
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	 * @param array $headers
240 240
 	 * @return string
241 241
 	 */
242
-	protected function buildHeadersString( array $headers ) : string {
242
+	protected function buildHeadersString ( array $headers ) : string {
243 243
 		$ret = '';
244 244
 		foreach ( $headers as $header ) {
245 245
 			$ret .= "$header\r\n";
Please login to merge, or discard this patch.