Passed
Push — master ( 72e6d1...600746 )
by Daimona
02:04
created
src/Request/RequestBase.php 1 patch
Spacing   +27 added lines, -27 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
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	/** @var string */
42 42
 	protected $method = self::METHOD_GET;
43 43
 	/** @var string[] */
44
-	protected $newCookies = [];
44
+	protected $newCookies = [ ];
45 45
 	/** @var callable|null */
46 46
 	private $cookiesHandlerCallback;
47 47
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * @param string $domain
58 58
 	 * @param callable $cookiesHandlerCallback
59 59
 	 */
60
-	public function __construct(
60
+	public function __construct (
61 61
 		LoggerInterface $logger,
62 62
 		array $params,
63 63
 		string $domain,
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return self For chaining
76 76
 	 */
77
-	public function setPost(): self {
77
+	public function setPost (): self {
78 78
 		$this->method = self::METHOD_POST;
79 79
 		return $this;
80 80
 	}
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @param string[] $cookies
84 84
 	 * @return self For chaining
85 85
 	 */
86
-	public function setCookies( array $cookies ): self {
86
+	public function setCookies ( array $cookies ): self {
87 87
 		$this->cookiesToSet = $cookies;
88 88
 		return $this;
89 89
 	}
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 	 * Execute a query request
93 93
 	 * @return Generator
94 94
 	 */
95
-	public function executeAsQuery(): Generator {
96
-		if ( ( $this->params['action'] ?? false ) !== 'query' ) {
95
+	public function executeAsQuery (): Generator {
96
+		if ( ( $this->params[ 'action' ] ?? false ) !== 'query' ) {
97 97
 			throw new BadMethodCallException( 'Not an ApiQuery!' );
98 98
 		}
99 99
 		// TODO Is this always correct?
100
-		$key = $this->params['list'] ?? 'pages';
100
+		$key = $this->params[ 'list' ] ?? 'pages';
101 101
 		$curParams = $this->params;
102 102
 		$lim = $this->parseLimit();
103 103
 		do {
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 * Execute a request that doesn't need any continuation.
127 127
 	 * @return stdClass
128 128
 	 */
129
-	public function executeSingle(): stdClass {
129
+	public function executeSingle (): stdClass {
130 130
 		$curParams = $this->params;
131 131
 		$res = $this->makeRequestInternal( $curParams );
132 132
 		$this->handleErrorAndWarnings( $res );
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	/**
137 137
 	 * @return int
138 138
 	 */
139
-	private function parseLimit(): int {
139
+	private function parseLimit (): int {
140 140
 		foreach ( $this->params as $name => $val ) {
141 141
 			if ( substr( $name, -strlen( 'limit' ) ) === 'limit' ) {
142 142
 				return $val === 'max' ? -1 : (int)$val;
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @param string $resKey
154 154
 	 * @return int|null
155 155
 	 */
156
-	private function countQueryResults( stdClass $res, string $resKey ): ?int {
156
+	private function countQueryResults ( stdClass $res, string $resKey ): ?int {
157 157
 		if ( !isset( $res->query->$resKey ) ) {
158 158
 			return null;
159 159
 		}
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
 	 * @phan-param array<int|string|bool> $params
182 182
 	 * @return stdClass
183 183
 	 */
184
-	private function makeRequestInternal( array $params ): stdClass {
184
+	private function makeRequestInternal ( array $params ): stdClass {
185 185
 		if ( $this->method === self::METHOD_POST ) {
186
-			$params['maxlag'] = self::MAXLAG;
186
+			$params[ 'maxlag' ] = self::MAXLAG;
187 187
 		}
188
-		if ( !isset( $params['assert'] ) ) {
189
-			$params['assert'] = 'user';
188
+		if ( !isset( $params[ 'assert' ] ) ) {
189
+			$params[ 'assert' ] = 'user';
190 190
 		}
191 191
 		$query = http_build_query( $params );
192 192
 
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
 	 *
207 207
 	 * @param string $cookie "{key}={value}"
208 208
 	 */
209
-	protected function saveNewCookie( string $cookie ): void {
209
+	protected function saveNewCookie ( string $cookie ): void {
210 210
 		$bits = explode( ';', $cookie );
211
-		[ $name, $value ] = explode( '=', $bits[0] );
212
-		$this->newCookies[$name] = $value;
211
+		[ $name, $value ] = explode( '=', $bits[ 0 ] );
212
+		$this->newCookies[ $name ] = $value;
213 213
 	}
214 214
 
215 215
 	/**
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 * @param string $params
219 219
 	 * @return string
220 220
 	 */
221
-	abstract protected function reallyMakeRequest( string $params ): string;
221
+	abstract protected function reallyMakeRequest ( string $params ): string;
222 222
 
223 223
 	/**
224 224
 	 * Get a specific exception class depending on the error code
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 * @param stdClass $res
227 227
 	 * @return APIRequestException
228 228
 	 */
229
-	private function getException( stdClass $res ): APIRequestException {
229
+	private function getException ( stdClass $res ): APIRequestException {
230 230
 		switch ( $res->error->code ) {
231 231
 			case 'missingtitle':
232 232
 				$ex = new MissingPageException;
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	 * @param stdClass $res
253 253
 	 * @throws APIRequestException
254 254
 	 */
255
-	protected function handleErrorAndWarnings( stdClass $res ): void {
255
+	protected function handleErrorAndWarnings ( stdClass $res ): void {
256 256
 		if ( isset( $res->error ) ) {
257 257
 			throw $this->getException( $res );
258 258
 		}
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
 	 *
269 269
 	 * @return string[]
270 270
 	 */
271
-	protected function getHeaders(): array {
271
+	protected function getHeaders (): array {
272 272
 		$ret = self::HEADERS;
273 273
 		if ( $this->cookiesToSet ) {
274
-			$cookies = [];
274
+			$cookies = [ ];
275 275
 			foreach ( $this->cookiesToSet as $cname => $cval ) {
276
-				$cookies[] = trim( "$cname=$cval" );
276
+				$cookies[ ] = trim( "$cname=$cval" );
277 277
 			}
278
-			$ret[] = 'Cookie: ' . implode( '; ', $cookies );
278
+			$ret[ ] = 'Cookie: ' . implode( '; ', $cookies );
279 279
 		}
280 280
 		return $ret;
281 281
 	}
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 * @param string[] $headers
287 287
 	 * @return string
288 288
 	 */
289
-	protected function buildHeadersString( array $headers ): string {
289
+	protected function buildHeadersString ( array $headers ): string {
290 290
 		$ret = '';
291 291
 		foreach ( $headers as $header ) {
292 292
 			$ret .= "$header\r\n";
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	 * @param string $actualParams
299 299
 	 * @return string
300 300
 	 */
301
-	protected function getDebugURL( string $actualParams ): string {
301
+	protected function getDebugURL ( string $actualParams ): string {
302 302
 		return strpos( $this->url, 'login' ) !== false
303 303
 			? '[Login request]'
304 304
 			: "{$this->url}?$actualParams";
Please login to merge, or discard this patch.
src/Request/RequestFactory.php 1 patch
Spacing   +4 added lines, -4 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
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	 * @param LoggerInterface $logger
15 15
 	 * @param string $domain
16 16
 	 */
17
-	public function __construct( LoggerInterface $logger, string $domain ) {
17
+	public function __construct ( LoggerInterface $logger, string $domain ) {
18 18
 		$this->logger = $logger;
19 19
 		$this->domain = $domain;
20 20
 	}
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @param callable $cookiesCallback
27 27
 	 * @return RequestBase
28 28
 	 */
29
-	public function createRequest( array $params, array $cookies, callable $cookiesCallback ) {
29
+	public function createRequest ( array $params, array $cookies, callable $cookiesCallback ) {
30 30
 		$ret = extension_loaded( 'curl' )
31 31
 			? new CurlRequest( $this->logger, $params, $this->domain, $cookiesCallback )
32 32
 			: new NativeRequest( $this->logger, $params, $this->domain, $cookiesCallback );
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 * @phan-param array<int|string|bool> $params
42 42
 	 * @return RequestBase
43 43
 	 */
44
-	public function createStandaloneRequest( array $params ) {
44
+	public function createStandaloneRequest ( array $params ) {
45 45
 		/** @param string[] $newCookies */
46 46
 		$cookiesCallback = function ( array $newCookies ) {
47 47
 			$this->logger->warning(
Please login to merge, or discard this patch.