@@ -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 | |
@@ -14,7 +14,7 @@ discard block |
||
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 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @phan-param array<int|string|bool> $params |
25 | 25 | * @return RequestBase |
26 | 26 | */ |
27 | - public function newFromParams( array $params ) : RequestBase { |
|
27 | + public function newFromParams ( array $params ) : RequestBase { |
|
28 | 28 | if ( extension_loaded( 'curl' ) ) { |
29 | 29 | return new CurlRequest( $this->logger, $params, $this->domain ); |
30 | 30 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Utils; |
4 | 4 | |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | * @param IRegexable ...$elements |
11 | 11 | * @return string |
12 | 12 | */ |
13 | - public static function regexFromArray( |
|
13 | + public static function regexFromArray ( |
|
14 | 14 | string $delimiter = '/', |
15 | 15 | IRegexable ...$elements |
16 | 16 | ) : string { |
17 | - $bits = []; |
|
17 | + $bits = [ ]; |
|
18 | 18 | foreach ( $elements as $el ) { |
19 | - $bits[] = $el->getRegex( $delimiter ); |
|
19 | + $bits[ ] = $el->getRegex( $delimiter ); |
|
20 | 20 | } |
21 | 21 | return '(?:' . implode( '|', $bits ) . ')'; |
22 | 22 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Utils; |
4 | 4 | |
@@ -9,5 +9,5 @@ discard block |
||
9 | 9 | * @param string $delimiter |
10 | 10 | * @return string |
11 | 11 | */ |
12 | - public function getRegex( string $delimiter ) : string; |
|
12 | + public function getRegex ( string $delimiter ) : string; |
|
13 | 13 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Task; |
4 | 4 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | */ |
18 | 18 | abstract class TaskBase extends ContextSource { |
19 | 19 | /** @var string[] */ |
20 | - protected $errors = []; |
|
20 | + protected $errors = [ ]; |
|
21 | 21 | /** @var TaskDataProvider */ |
22 | 22 | protected $dataProvider; |
23 | 23 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param MessageProvider $mp |
31 | 31 | * @param PageBotList $pbl |
32 | 32 | */ |
33 | - final public function __construct( |
|
33 | + final public function __construct ( |
|
34 | 34 | LoggerInterface $logger, |
35 | 35 | WikiGroup $wikiGroup, |
36 | 36 | TaskDataProvider $dataProvider, |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return TaskResult |
48 | 48 | */ |
49 | - final public function run() : TaskResult { |
|
49 | + final public function run () : TaskResult { |
|
50 | 50 | $class = ( new ReflectionClass( $this ) )->getShortName(); |
51 | 51 | $opName = $this->getOperationName(); |
52 | 52 | $this->getLogger()->info( "Starting $opName $class" ); |
@@ -77,19 +77,19 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return int One of the STATUS_* constants |
79 | 79 | */ |
80 | - abstract protected function runInternal() : int; |
|
80 | + abstract protected function runInternal () : int; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * How this operation should be called in logs |
84 | 84 | * |
85 | 85 | * @return string |
86 | 86 | */ |
87 | - abstract public function getOperationName() : string; |
|
87 | + abstract public function getOperationName () : string; |
|
88 | 88 | |
89 | 89 | /** |
90 | 90 | * @return TaskDataProvider |
91 | 91 | */ |
92 | - protected function getDataProvider() : TaskDataProvider { |
|
92 | + protected function getDataProvider () : TaskDataProvider { |
|
93 | 93 | return $this->dataProvider; |
94 | 94 | } |
95 | 95 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Task; |
4 | 4 | |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return string[] |
17 | 17 | */ |
18 | - abstract protected function getSubtasksMap() : array; |
|
18 | + abstract protected function getSubtasksMap () : array; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param string $subtask Defined in self::SUBTASKS_MAP |
22 | 22 | * @return TaskResult |
23 | 23 | */ |
24 | - protected function runSubtask( string $subtask ) : TaskResult { |
|
24 | + protected function runSubtask ( string $subtask ) : TaskResult { |
|
25 | 25 | $map = $this->getSubtasksMap(); |
26 | 26 | if ( !isset( $map[ $subtask ] ) ) { |
27 | 27 | throw new InvalidArgumentException( "'$subtask' is not a valid task." ); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @inheritDoc |
36 | 36 | */ |
37 | - final public function getOperationName(): string { |
|
37 | + final public function getOperationName (): string { |
|
38 | 38 | return 'task'; |
39 | 39 | } |
40 | 40 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param string $class |
45 | 45 | * @return Subtask |
46 | 46 | */ |
47 | - private function getSubtaskInstance( string $class ) : Subtask { |
|
47 | + private function getSubtaskInstance ( string $class ) : Subtask { |
|
48 | 48 | return new $class( |
49 | 49 | $this->getLogger(), |
50 | 50 | $this->getWikiGroup(), |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Wiki\Page; |
4 | 4 | |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @param string $title |
23 | 23 | * @param Wiki $wiki For the site where the page lives |
24 | 24 | */ |
25 | - public function __construct( string $title, Wiki $wiki ) { |
|
25 | + public function __construct ( string $title, Wiki $wiki ) { |
|
26 | 26 | $this->wiki = $wiki; |
27 | 27 | $this->title = $title; |
28 | 28 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public function getTitle() : string { |
|
33 | + public function getTitle () : string { |
|
34 | 34 | return $this->title; |
35 | 35 | } |
36 | 36 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param int|null $section A section number to retrieve the content of that section |
41 | 41 | * @return string |
42 | 42 | */ |
43 | - public function getContent( int $section = null ) : string { |
|
43 | + public function getContent ( int $section = null ) : string { |
|
44 | 44 | if ( $this->content === null ) { |
45 | 45 | $this->content = $this->wiki->getPageContent( $this->title, $section ); |
46 | 46 | } |
@@ -54,18 +54,18 @@ discard block |
||
54 | 54 | * @phan-param array<int|string|bool> $params |
55 | 55 | * @throws LogicException |
56 | 56 | */ |
57 | - public function edit( array $params ) : void { |
|
57 | + public function edit ( array $params ) : void { |
|
58 | 58 | $params = [ |
59 | 59 | 'title' => $this->getTitle() |
60 | 60 | ] + $params; |
61 | 61 | |
62 | 62 | $this->wiki->editPage( $params ); |
63 | - if ( isset( $params['text'] ) ) { |
|
64 | - $this->content = $params['text']; |
|
65 | - } elseif ( isset( $params['appendtext'] ) ) { |
|
66 | - $this->content .= $params['appendtext']; |
|
67 | - } elseif ( isset( $params['prependtext'] ) ) { |
|
68 | - $this->content = $params['prependtext'] . $this->content; |
|
63 | + if ( isset( $params[ 'text' ] ) ) { |
|
64 | + $this->content = $params[ 'text' ]; |
|
65 | + } elseif ( isset( $params[ 'appendtext' ] ) ) { |
|
66 | + $this->content .= $params[ 'appendtext' ]; |
|
67 | + } elseif ( isset( $params[ 'prependtext' ] ) ) { |
|
68 | + $this->content = $params[ 'prependtext' ] . $this->content; |
|
69 | 69 | } else { |
70 | 70 | throw new LogicException( |
71 | 71 | 'Unrecognized text param for edit. Params: ' . var_export( $params, true ) |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return bool |
80 | 80 | */ |
81 | - public function exists() : bool { |
|
81 | + public function exists () : bool { |
|
82 | 82 | $pages = $this->wiki->getRequestFactory()->newFromParams( [ |
83 | 83 | 'action' => 'query', |
84 | 84 | 'titles' => $this->getTitle() |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @param string $regex |
93 | 93 | * @return bool |
94 | 94 | */ |
95 | - public function matches( string $regex ) : bool { |
|
95 | + public function matches ( string $regex ) : bool { |
|
96 | 96 | return (bool)preg_match( $regex, $this->getContent() ); |
97 | 97 | } |
98 | 98 | |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @return string[] |
105 | 105 | * @throws MissingMatchException |
106 | 106 | */ |
107 | - public function getMatch( string $regex ) : array { |
|
108 | - $ret = []; |
|
107 | + public function getMatch ( string $regex ) : array { |
|
108 | + $ret = [ ]; |
|
109 | 109 | if ( preg_match( $regex, $this->getContent(), $ret ) === 0 ) { |
110 | 110 | throw new MissingMatchException( "The content of $this does not match the given regex $regex" ); |
111 | 111 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @inheritDoc |
119 | 119 | */ |
120 | - public function getRegex( string $delimiter = '/' ) : string { |
|
120 | + public function getRegex ( string $delimiter = '/' ) : string { |
|
121 | 121 | return str_replace( ' ', '[ _]', preg_quote( $this->title, $delimiter ) ); |
122 | 122 | } |
123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - public function __toString() : string { |
|
129 | + public function __toString () : string { |
|
130 | 130 | return $this->getTitle(); |
131 | 131 | } |
132 | 132 | } |
@@ -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 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** @var string */ |
42 | 42 | protected $method = self::METHOD_GET; |
43 | 43 | /** @var string[] */ |
44 | - protected $newCookies = []; |
|
44 | + protected $newCookies = [ ]; |
|
45 | 45 | |
46 | 46 | /** @var LoggerInterface */ |
47 | 47 | protected $logger; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @phan-param array<int|string|bool> $params |
55 | 55 | * @param string $domain |
56 | 56 | */ |
57 | - public function __construct( LoggerInterface $logger, array $params, string $domain ) { |
|
57 | + public function __construct ( LoggerInterface $logger, array $params, string $domain ) { |
|
58 | 58 | $this->logger = $logger; |
59 | 59 | $this->params = [ 'format' => 'json' ] + $params; |
60 | 60 | $this->url = $domain; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return self For chaining |
67 | 67 | */ |
68 | - public function setPost() : self { |
|
68 | + public function setPost () : self { |
|
69 | 69 | $this->method = self::METHOD_POST; |
70 | 70 | return $this; |
71 | 71 | } |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | * Execute a query request |
75 | 75 | * @return Generator |
76 | 76 | */ |
77 | - public function executeAsQuery() : Generator { |
|
78 | - if ( ( $this->params['action'] ?? false ) !== 'query' ) { |
|
77 | + public function executeAsQuery () : Generator { |
|
78 | + if ( ( $this->params[ 'action' ] ?? false ) !== 'query' ) { |
|
79 | 79 | throw new BadMethodCallException( 'Not an ApiQuery!' ); |
80 | 80 | } |
81 | 81 | // TODO Is this always correct? |
82 | - $key = $this->params['list'] ?? 'pages'; |
|
82 | + $key = $this->params[ 'list' ] ?? 'pages'; |
|
83 | 83 | $curParams = $this->params; |
84 | 84 | $lim = $this->parseLimit(); |
85 | 85 | do { |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * Execute a request that doesn't need any continuation. |
109 | 109 | * @return stdClass |
110 | 110 | */ |
111 | - public function executeSingle() : stdClass { |
|
111 | + public function executeSingle () : stdClass { |
|
112 | 112 | $curParams = $this->params; |
113 | 113 | $res = $this->makeRequestInternal( $curParams ); |
114 | 114 | $this->handleErrorAndWarnings( $res ); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | /** |
119 | 119 | * @return int |
120 | 120 | */ |
121 | - private function parseLimit() : int { |
|
121 | + private function parseLimit () : int { |
|
122 | 122 | foreach ( $this->params as $name => $val ) { |
123 | 123 | if ( substr( $name, -strlen( 'limit' ) ) === 'limit' ) { |
124 | 124 | return $val === 'max' ? -1 : (int)$val; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @param string $resKey |
136 | 136 | * @return int|null |
137 | 137 | */ |
138 | - private function countQueryResults( stdClass $res, string $resKey ) : ?int { |
|
138 | + private function countQueryResults ( stdClass $res, string $resKey ) : ?int { |
|
139 | 139 | if ( !isset( $res->query->$resKey ) ) { |
140 | 140 | return null; |
141 | 141 | } |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @phan-param array<int|string|bool> $params |
164 | 164 | * @return stdClass |
165 | 165 | */ |
166 | - private function makeRequestInternal( array $params ) : stdClass { |
|
166 | + private function makeRequestInternal ( array $params ) : stdClass { |
|
167 | 167 | if ( $this->method === self::METHOD_POST ) { |
168 | - $params['maxlag'] = self::MAXLAG; |
|
168 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
169 | 169 | } |
170 | 170 | $query = http_build_query( $params ); |
171 | 171 | |
@@ -186,18 +186,18 @@ discard block |
||
186 | 186 | * @param string $params |
187 | 187 | * @return string |
188 | 188 | */ |
189 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
189 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
190 | 190 | |
191 | 191 | /** |
192 | 192 | * After a request, set cookies for the next ones |
193 | 193 | * |
194 | 194 | * @param string[] $cookies |
195 | 195 | */ |
196 | - protected function setCookies( array $cookies ) : void { |
|
196 | + protected function setCookies ( array $cookies ) : void { |
|
197 | 197 | foreach ( $cookies as $cookie ) { |
198 | 198 | /** @var string[] $bits */ |
199 | 199 | $bits = explode( ';', $cookie ); |
200 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
200 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
201 | 201 | self::$cookiesToSet[ $name ] = $value; |
202 | 202 | } |
203 | 203 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @param stdClass $res |
209 | 209 | * @return APIRequestException |
210 | 210 | */ |
211 | - private function getException( stdClass $res ) : APIRequestException { |
|
211 | + private function getException ( stdClass $res ) : APIRequestException { |
|
212 | 212 | switch ( $res->error->code ) { |
213 | 213 | case 'missingtitle': |
214 | 214 | $ex = new MissingPageException; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @param stdClass $res |
235 | 235 | * @throws APIRequestException |
236 | 236 | */ |
237 | - protected function handleErrorAndWarnings( stdClass $res ) : void { |
|
237 | + protected function handleErrorAndWarnings ( stdClass $res ) : void { |
|
238 | 238 | if ( isset( $res->error ) ) { |
239 | 239 | throw $this->getException( $res ); |
240 | 240 | } |
@@ -250,14 +250,14 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @return string[] |
252 | 252 | */ |
253 | - protected function getHeaders() : array { |
|
253 | + protected function getHeaders () : array { |
|
254 | 254 | $ret = self::HEADERS; |
255 | 255 | if ( self::$cookiesToSet ) { |
256 | - $cookies = []; |
|
256 | + $cookies = [ ]; |
|
257 | 257 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
258 | - $cookies[] = trim( "$cname=$cval" ); |
|
258 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
259 | 259 | } |
260 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
260 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
261 | 261 | } |
262 | 262 | return $ret; |
263 | 263 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * @param string[] $headers |
269 | 269 | * @return string |
270 | 270 | */ |
271 | - protected function buildHeadersString( array $headers ) : string { |
|
271 | + protected function buildHeadersString ( array $headers ) : string { |
|
272 | 272 | $ret = ''; |
273 | 273 | foreach ( $headers as $header ) { |
274 | 274 | $ret .= "$header\r\n"; |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @param string $actualParams |
281 | 281 | * @return string |
282 | 282 | */ |
283 | - protected function getDebugURL( string $actualParams ) : string { |
|
283 | + protected function getDebugURL ( string $actualParams ) : string { |
|
284 | 284 | return strpos( $this->url, 'login' ) !== false |
285 | 285 | ? '[Login request]' |
286 | 286 | : "{$this->url}?$actualParams"; |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @inheritDoc |
14 | 14 | * @throws APIRequestException |
15 | 15 | */ |
16 | - protected function reallyMakeRequest( string $params ) : string { |
|
16 | + protected function reallyMakeRequest ( string $params ) : string { |
|
17 | 17 | $curl = curl_init(); |
18 | 18 | if ( $curl === false ) { |
19 | 19 | throw new APIRequestException( 'Cannot open cURL handler.' ); |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | * @internal Only used as CB for cURL (CURLOPT_HEADERFUNCTION) |
60 | 60 | * @suppress PhanUnreferencedPublicMethod,PhanUnusedPublicNoOverrideMethodParameter |
61 | 61 | */ |
62 | - public function headersHandler( $ch, string $header ) : int { |
|
62 | + public function headersHandler ( $ch, string $header ) : int { |
|
63 | 63 | /** @var string[] $bits */ |
64 | 64 | $bits = explode( ':', $header, 2 ); |
65 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
66 | - $this->newCookies[] = $bits[1]; |
|
65 | + if ( trim( $bits[ 0 ] ) === 'Set-Cookie' ) { |
|
66 | + $this->newCookies[ ] = $bits[ 1 ]; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return strlen( $header ); |
@@ -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 | |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | /** |
10 | 10 | * @inheritDoc |
11 | 11 | */ |
12 | - protected function reallyMakeRequest( string $params ) : string { |
|
12 | + protected function reallyMakeRequest ( string $params ) : string { |
|
13 | 13 | $context = [ |
14 | 14 | 'http' => [ |
15 | 15 | 'method' => $this->method, |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | ]; |
19 | 19 | $url = $this->url; |
20 | 20 | if ( $this->method === self::METHOD_POST ) { |
21 | - $context['http']['content'] = $params; |
|
21 | + $context[ 'http' ][ 'content' ] = $params; |
|
22 | 22 | } else { |
23 | 23 | $url = "$url?$params"; |
24 | 24 | } |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | foreach ( $http_response_header as $header ) { |
29 | 29 | /** @var string[] $bits */ |
30 | 30 | $bits = explode( ':', $header, 2 ); |
31 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
32 | - $this->newCookies[] = $bits[1]; |
|
31 | + if ( trim( $bits[ 0 ] ) === 'Set-Cookie' ) { |
|
32 | + $this->newCookies[ ] = $bits[ 1 ]; |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 |