@@ -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 | |
@@ -30,14 +30,14 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | * @todo Return an iterable object which automatically continues the query only if the last |
86 | 86 | * entry available is reached. |
87 | 87 | */ |
88 | - public function execute() : \stdClass { |
|
88 | + public function execute () : \stdClass { |
|
89 | 89 | $curParams = $this->params; |
90 | - $sets = []; |
|
90 | + $sets = [ ]; |
|
91 | 91 | do { |
92 | 92 | $res = $this->makeRequestInternal( $curParams ); |
93 | 93 | |
94 | 94 | $this->handleErrorAndWarnings( $res ); |
95 | - $sets[] = $res; |
|
95 | + $sets[ ] = $res; |
|
96 | 96 | |
97 | 97 | $finished = true; |
98 | 98 | if ( isset( $res->continue ) ) { |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * @param array $params |
111 | 111 | * @return \stdClass |
112 | 112 | */ |
113 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
113 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
114 | 114 | if ( $this->method === 'POST' ) { |
115 | - $params['maxlag'] = self::MAXLAG; |
|
115 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
116 | 116 | } |
117 | 117 | $params = http_build_query( $params ); |
118 | 118 | |
@@ -128,17 +128,17 @@ discard block |
||
128 | 128 | * @param string $params |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
131 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * After a request, set cookies for the next ones |
135 | 135 | * |
136 | 136 | * @param array $cookies |
137 | 137 | */ |
138 | - protected function setCookies( array $cookies ) { |
|
138 | + protected function setCookies ( array $cookies ) { |
|
139 | 139 | foreach ( $cookies as $cookie ) { |
140 | 140 | $bits = explode( ';', $cookie ); |
141 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
141 | + list( $name, $value ) = explode( '=', $bits[ 0 ] ); |
|
142 | 142 | self::$cookiesToSet[ $name ] = $value; |
143 | 143 | } |
144 | 144 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param \stdClass $res |
150 | 150 | * @return APIRequestException |
151 | 151 | */ |
152 | - private function getException( \stdClass $res ) : APIRequestException { |
|
152 | + private function getException ( \stdClass $res ) : APIRequestException { |
|
153 | 153 | switch ( $res->error->code ) { |
154 | 154 | case 'missingtitle': |
155 | 155 | $ex = new MissingPageException; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param \stdClass $res |
173 | 173 | * @throws APIRequestException |
174 | 174 | */ |
175 | - protected function handleErrorAndWarnings( \stdClass $res ) { |
|
175 | + protected function handleErrorAndWarnings ( \stdClass $res ) { |
|
176 | 176 | if ( isset( $res->error ) ) { |
177 | 177 | throw $this->getException( $res ); |
178 | 178 | } elseif ( isset( $res->warnings ) ) { |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @param \stdClass[] $sets |
189 | 189 | * @return \stdClass |
190 | 190 | */ |
191 | - private function mergeSets( array $sets ) : \stdClass { |
|
191 | + private function mergeSets ( array $sets ) : \stdClass { |
|
192 | 192 | // Use the first set as template |
193 | 193 | $ret = array_shift( $sets ); |
194 | 194 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @param array|\stdClass $second |
206 | 206 | * @return array|\stdClass array |
207 | 207 | */ |
208 | - private function recursiveMerge( $first, $second ) { |
|
208 | + private function recursiveMerge ( $first, $second ) { |
|
209 | 209 | $ret = $first; |
210 | 210 | if ( is_array( $second ) ) { |
211 | 211 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -223,14 +223,14 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return array |
225 | 225 | */ |
226 | - protected function getHeaders() :array { |
|
226 | + protected function getHeaders () :array { |
|
227 | 227 | $ret = self::HEADERS; |
228 | 228 | if ( self::$cookiesToSet ) { |
229 | - $cookies = []; |
|
229 | + $cookies = [ ]; |
|
230 | 230 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
231 | - $cookies[] = trim( "$cname=$cval" ); |
|
231 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
232 | 232 | } |
233 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
233 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
234 | 234 | } |
235 | 235 | return $ret; |
236 | 236 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param array $headers |
242 | 242 | * @return string |
243 | 243 | */ |
244 | - protected function buildHeadersString( array $headers ) : string { |
|
244 | + protected function buildHeadersString ( array $headers ) : string { |
|
245 | 245 | $ret = ''; |
246 | 246 | foreach ( $headers as $header ) { |
247 | 247 | $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\Wiki; |
4 | 4 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param LoggerInterface $logger |
29 | 29 | * @param string $domain The URL of the wiki, if different from default |
30 | 30 | */ |
31 | - public function __construct( LoggerInterface $logger, string $domain = DEFAULT_URL ) { |
|
31 | + public function __construct ( LoggerInterface $logger, string $domain = DEFAULT_URL ) { |
|
32 | 32 | $this->logger = $logger; |
33 | 33 | $this->domain = $domain; |
34 | 34 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @throws MissingPageException |
43 | 43 | * @throws MissingSectionException |
44 | 44 | */ |
45 | - public function getPageContent( string $title, int $section = null ) : string { |
|
45 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
46 | 46 | $msg = "Retrieving content of $title" . ( $section !== null ? ", section $section" : '' ); |
47 | 47 | $this->logger->debug( $msg ); |
48 | 48 | $params = [ |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | ]; |
55 | 55 | |
56 | 56 | if ( $section !== null ) { |
57 | - $params['rvsection'] = $section; |
|
57 | + $params[ 'rvsection' ] = $section; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $req = $this->buildRequest( $params ); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | throw new MissingPageException( $title ); |
65 | 65 | } |
66 | 66 | |
67 | - $mainSlot = $page->revisions[0]->slots->main; |
|
67 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
68 | 68 | |
69 | 69 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
70 | 70 | throw new MissingSectionException( $title, $section ); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param array $params |
79 | 79 | * @throws EditException |
80 | 80 | */ |
81 | - public function editPage( array $params ) { |
|
81 | + public function editPage ( array $params ) { |
|
82 | 82 | $this->login(); |
83 | 83 | |
84 | 84 | $params = [ |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | ] + $params; |
88 | 88 | |
89 | 89 | if ( Config::getInstance()->get( 'bot-edits' ) ) { |
90 | - $params['bot'] = 1; |
|
90 | + $params[ 'bot' ] = 1; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $res = $this->buildRequest( $params )->setPost()->execute(); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
106 | 106 | * @throws LoginException |
107 | 107 | */ |
108 | - public function login() { |
|
108 | + public function login () { |
|
109 | 109 | if ( self::$loggedIn ) { |
110 | 110 | return; |
111 | 111 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | self::$loggedIn = true; |
134 | 134 | // Clear tokens cache |
135 | - $this->tokens = []; |
|
135 | + $this->tokens = [ ]; |
|
136 | 136 | $this->logger->info( 'Login succeeded' ); |
137 | 137 | } |
138 | 138 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string $type |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function getToken( string $type ) : string { |
|
145 | + public function getToken ( string $type ) : string { |
|
146 | 146 | if ( !isset( $this->tokens[ $type ] ) ) { |
147 | 147 | $params = [ |
148 | 148 | 'action' => 'query', |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param string $title |
166 | 166 | * @return int |
167 | 167 | */ |
168 | - public function getPageCreationTS( string $title ) : int { |
|
168 | + public function getPageCreationTS ( string $title ) : int { |
|
169 | 169 | $params = [ |
170 | 170 | 'action' => 'query', |
171 | 171 | 'prop' => 'revisions', |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | |
179 | 179 | $res = $this->buildRequest( $params )->execute(); |
180 | 180 | $data = $res->query->pages; |
181 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
181 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param string $title |
188 | 188 | * @param string $reason |
189 | 189 | */ |
190 | - public function protectPage( string $title, string $reason ) { |
|
190 | + public function protectPage ( string $title, string $reason ) { |
|
191 | 191 | $this->logger->info( "Protecting page $title" ); |
192 | 192 | $this->login(); |
193 | 193 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @param array $params |
209 | 209 | * @return RequestBase |
210 | 210 | */ |
211 | - private function buildRequest( array $params ) : RequestBase { |
|
211 | + private function buildRequest ( array $params ) : RequestBase { |
|
212 | 212 | return RequestBase::newFromParams( $params )->setUrl( $this->domain ); |
213 | 213 | } |
214 | 214 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Logger; |
4 | 4 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param Page $logPage |
27 | 27 | * @param string $minlevel |
28 | 28 | */ |
29 | - public function __construct( Page $logPage, $minlevel = LogLevel::INFO ) { |
|
29 | + public function __construct ( Page $logPage, $minlevel = LogLevel::INFO ) { |
|
30 | 30 | $this->minLevel = $this->levelToInt( $minlevel ); |
31 | 31 | $this->logPage = $logPage; |
32 | 32 | } |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | * @inheritDoc |
36 | 36 | * @suppress PhanUnusedPublicMethodParameter |
37 | 37 | */ |
38 | - public function log( $level, $message, array $context = [] ) { |
|
38 | + public function log ( $level, $message, array $context = [ ] ) { |
|
39 | 39 | if ( $this->levelToInt( $level ) >= $this->minLevel ) { |
40 | - $this->buffer[] = $this->getFormattedMessage( $level, $message ); |
|
40 | + $this->buffer[ ] = $this->getFormattedMessage( $level, $message ); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - protected function getOutput() : string { |
|
47 | + protected function getOutput () : string { |
|
48 | 48 | $line = str_repeat( '-', 80 ); |
49 | 49 | return "\n\n" . implode( "\n", $this->buffer ) . "\n$line\n\n"; |
50 | 50 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @inheritDoc |
54 | 54 | */ |
55 | - public function flush() : void { |
|
55 | + public function flush () : void { |
|
56 | 56 | if ( $this->buffer ) { |
57 | 57 | $this->logPage->edit( [ |
58 | 58 | 'appendtext' => $this->getOutput(), |
@@ -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\Subtask; |
4 | 4 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * @inheritDoc |
14 | 14 | */ |
15 | - public function runInternal() : int { |
|
15 | + public function runInternal () : int { |
|
16 | 16 | $pages = $this->getDataProvider()->getCreatedPages(); |
17 | 17 | $users = $this->getDataProvider()->getUsersToProcess(); |
18 | 18 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | return TaskResult::STATUS_NOTHING; |
21 | 21 | } |
22 | 22 | |
23 | - $ricNums = []; |
|
23 | + $ricNums = [ ]; |
|
24 | 24 | foreach ( $pages as $page ) { |
25 | 25 | $ricNums[ $page->getUser()->getName() ] = $page->getNum(); |
26 | 26 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param User $user |
39 | 39 | * @param int $ricNum |
40 | 40 | */ |
41 | - protected function addMsg( User $user, int $ricNum ) { |
|
41 | + protected function addMsg ( User $user, int $ricNum ) { |
|
42 | 42 | $this->getLogger()->info( "Leaving msg to $user" ); |
43 | 43 | $msg = $this->msg( 'user-notice-msg' )->params( [ '$num' => $ricNum ] )->text(); |
44 | 44 |
@@ -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 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param LoggerInterface $logger |
26 | 26 | * @param Wiki $wiki |
27 | 27 | */ |
28 | - public function __construct( LoggerInterface $logger, Wiki $wiki ) { |
|
28 | + public function __construct ( LoggerInterface $logger, Wiki $wiki ) { |
|
29 | 29 | $this->setLogger( $logger ); |
30 | 30 | $this->setConfig( Config::getInstance() ); |
31 | 31 | $this->setWiki( $wiki ); |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @return LoggerInterface |
36 | 36 | */ |
37 | - protected function getLogger() : LoggerInterface { |
|
37 | + protected function getLogger () : LoggerInterface { |
|
38 | 38 | return $this->logger; |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @inheritDoc |
43 | 43 | */ |
44 | - public function setLogger( LoggerInterface $logger ) { |
|
44 | + public function setLogger ( LoggerInterface $logger ) { |
|
45 | 45 | $this->logger = $logger; |
46 | 46 | } |
47 | 47 | |
@@ -51,35 +51,35 @@ discard block |
||
51 | 51 | * @param string $optname |
52 | 52 | * @return mixed |
53 | 53 | */ |
54 | - protected function getOpt( string $optname ) { |
|
54 | + protected function getOpt ( string $optname ) { |
|
55 | 55 | return $this->getConfig()->get( $optname ); |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @return Config |
60 | 60 | */ |
61 | - protected function getConfig() : Config { |
|
61 | + protected function getConfig () : Config { |
|
62 | 62 | return $this->config; |
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @param Config $cfg |
67 | 67 | */ |
68 | - protected function setConfig( Config $cfg ) { |
|
68 | + protected function setConfig ( Config $cfg ) { |
|
69 | 69 | $this->config = $cfg; |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @return Wiki |
74 | 74 | */ |
75 | - protected function getWiki() : Wiki { |
|
75 | + protected function getWiki () : Wiki { |
|
76 | 76 | return $this->wiki; |
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @param Wiki $wiki |
81 | 81 | */ |
82 | - protected function setWiki( Wiki $wiki ) { |
|
82 | + protected function setWiki ( Wiki $wiki ) { |
|
83 | 83 | $this->wiki = $wiki; |
84 | 84 | } |
85 | 85 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @param string $key |
90 | 90 | * @return Message |
91 | 91 | */ |
92 | - protected function msg( string $key ) : Message { |
|
92 | + protected function msg ( string $key ) : Message { |
|
93 | 93 | return new Message( $key ); |
94 | 94 | } |
95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param string $title |
100 | 100 | * @return Page |
101 | 101 | */ |
102 | - protected function getPage( string $title ) : Page { |
|
102 | + protected function getPage ( string $title ) : Page { |
|
103 | 103 | return new Page( $title, $this->getWiki() ); |
104 | 104 | } |
105 | 105 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param string $name |
110 | 110 | * @return User |
111 | 111 | */ |
112 | - protected function getUser( string $name ) : User { |
|
112 | + protected function getUser ( string $name ) : User { |
|
113 | 113 | return new User( $name, $this->getWiki() ); |
114 | 114 | } |
115 | 115 | } |
@@ -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 | |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | private $supportSection; |
17 | 17 | private $opposeSection; |
18 | 18 | /** @var array Counts of votes for each section */ |
19 | - private $sectionCounts = []; |
|
19 | + private $sectionCounts = [ ]; |
|
20 | 20 | |
21 | 21 | // Possible outcomes of a vote |
22 | 22 | public const OUTCOME_OK = 0; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * because they can vary depending on whether the page is a vote, which is relatively |
36 | 36 | * expensive to know since it requires parsing the content of the page. |
37 | 37 | */ |
38 | - private function defineSections() { |
|
38 | + private function defineSections () { |
|
39 | 39 | $this->supportSection = $this->isVote() ? 3 : 0; |
40 | 40 | $this->opposeSection = $this->isVote() ? 4 : 3; |
41 | 41 | } |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return User |
47 | 47 | */ |
48 | - public function getUser() : User { |
|
49 | - $name = explode( '/', $this->title )[2]; |
|
48 | + public function getUser () : User { |
|
49 | + $name = explode( '/', $this->title )[ 2 ]; |
|
50 | 50 | return new User( $name, $this->wiki ); |
51 | 51 | } |
52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return int |
57 | 57 | */ |
58 | - public function getNum() : int { |
|
58 | + public function getNum () : int { |
|
59 | 59 | $bits = explode( '/', $this->getTitle() ); |
60 | 60 | return intval( end( $bits ) ); |
61 | 61 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return string |
67 | 67 | */ |
68 | - public function getUserNum() : string { |
|
69 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
68 | + public function getUserNum () : string { |
|
69 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return int |
76 | 76 | */ |
77 | - public function getOpposingCount() : int { |
|
77 | + public function getOpposingCount () : int { |
|
78 | 78 | $this->defineSections(); |
79 | 79 | return $this->getCountForSection( $this->opposeSection ); |
80 | 80 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @return int |
86 | 86 | * @throws \BadMethodCallException |
87 | 87 | */ |
88 | - public function getSupportCount() : int { |
|
88 | + public function getSupportCount () : int { |
|
89 | 89 | if ( !$this->isVote() ) { |
90 | 90 | throw new \BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
91 | 91 | } |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * @param int $secNum |
100 | 100 | * @return int |
101 | 101 | */ |
102 | - protected function getCountForSection( int $secNum ) : int { |
|
102 | + protected function getCountForSection ( int $secNum ) : int { |
|
103 | 103 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
104 | 104 | $content = $this->wiki->getPageContent( $this->title, $secNum ); |
105 | 105 | // Let's hope that this is good enough... |
106 | - $this->sectionCounts[$secNum] = preg_match_all( "/^\# *(?![# *:]|\.\.\.$)/m", $content ); |
|
106 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^\# *(?![# *:]|\.\.\.$)/m", $content ); |
|
107 | 107 | } |
108 | - return $this->sectionCounts[$secNum]; |
|
108 | + return $this->sectionCounts[ $secNum ]; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return int |
115 | 115 | */ |
116 | - protected function getQuorum() : int { |
|
116 | + protected function getQuorum () : int { |
|
117 | 117 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
118 | - return intval( $this->getMatch( $reg )[1] ); |
|
118 | + return intval( $this->getMatch( $reg )[ 1 ] ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | - public function hasOpposition() : bool { |
|
126 | + public function hasOpposition () : bool { |
|
127 | 127 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
128 | 128 | } |
129 | 129 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return int One of the OUTCOME_* constants |
134 | 134 | */ |
135 | - public function getOutcome() : int { |
|
135 | + public function getOutcome () : int { |
|
136 | 136 | if ( !$this->isVote() ) { |
137 | 137 | return self::OUTCOME_OK; |
138 | 138 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @throws \BadMethodCallException |
156 | 156 | * @throws \LogicException |
157 | 157 | */ |
158 | - public function getOutcomeText() : string { |
|
158 | + public function getOutcomeText () : string { |
|
159 | 159 | if ( !$this->isVote() ) { |
160 | 160 | throw new \BadMethodCallException( 'No need for an outcome text.' ); |
161 | 161 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return bool |
191 | 191 | */ |
192 | - public function isVote() : bool { |
|
192 | + public function isVote () : bool { |
|
193 | 193 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
194 | 194 | return !$this->matches( $sectionReg ); |
195 | 195 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @return int |
201 | 201 | */ |
202 | - public function getCreationTimestamp() : int { |
|
202 | + public function getCreationTimestamp () : int { |
|
203 | 203 | return $this->wiki->getPageCreationTS( $this->title ); |
204 | 204 | } |
205 | 205 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * |
209 | 209 | * @return int |
210 | 210 | */ |
211 | - public function getEndTimestamp() : int { |
|
211 | + public function getEndTimestamp () : int { |
|
212 | 212 | if ( $this->isVote() ) { |
213 | 213 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
214 | 214 | list( , $hours, $day ) = $this->getMatch( $reg ); |
@@ -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; |
4 | 4 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @param string $name |
21 | 21 | * @param Wiki $wiki |
22 | 22 | */ |
23 | - public function __construct( string $name, Wiki $wiki ) { |
|
23 | + public function __construct ( string $name, Wiki $wiki ) { |
|
24 | 24 | parent::__construct( $wiki ); |
25 | 25 | $this->name = $name; |
26 | 26 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function getName() : string { |
|
31 | + public function getName () : string { |
|
32 | 32 | return $this->name; |
33 | 33 | } |
34 | 34 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return string[] |
39 | 39 | */ |
40 | - public function getGroups() : array { |
|
40 | + public function getGroups () : array { |
|
41 | 41 | return array_diff( array_keys( $this->getUserInfo() ), PageBotList::NON_GROUP_KEYS ); |
42 | 42 | } |
43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return string[] [ group => date ] |
48 | 48 | */ |
49 | - public function getGroupsWithDates() : array { |
|
49 | + public function getGroupsWithDates () : array { |
|
50 | 50 | return array_intersect_key( $this->getUserInfo(), array_fill_keys( $this->getGroups(), 1 ) ); |
51 | 51 | } |
52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return string[] |
57 | 57 | */ |
58 | - public function getUserInfo() : array { |
|
58 | + public function getUserInfo () : array { |
|
59 | 59 | if ( $this->info === null ) { |
60 | 60 | $usersList = PageBotList::get( $this->wiki )->getAdminsList(); |
61 | 61 | $this->info = $usersList[ $this->name ]->getUserInfo(); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | /** |
67 | 67 | * @param array|null $info |
68 | 68 | */ |
69 | - public function setInfo( ?array $info ) : void { |
|
69 | + public function setInfo ( ?array $info ) : void { |
|
70 | 70 | $this->info = $info; |
71 | 71 | } |
72 | 72 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param string $groupName |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - public function inGroup( string $groupName ) : bool { |
|
79 | + public function inGroup ( string $groupName ) : bool { |
|
80 | 80 | return in_array( $groupName, $this->getGroups() ); |
81 | 81 | } |
82 | 82 | |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @inheritDoc |
87 | 87 | */ |
88 | - public function getRegex() : string { |
|
88 | + public function getRegex () : string { |
|
89 | 89 | $bits = $this->getAliases(); |
90 | - $bits[] = $this->name; |
|
90 | + $bits[ ] = $this->name; |
|
91 | 91 | $regexify = function ( $el ) { |
92 | 92 | return str_replace( ' ', '[ _]', preg_quote( $el ) ); |
93 | 93 | }; |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return string[] |
101 | 101 | */ |
102 | - public function getAliases() : array { |
|
103 | - return $this->getUserInfo()['aliases'] ?? []; |
|
102 | + public function getAliases () : array { |
|
103 | + return $this->getUserInfo()[ 'aliases' ] ?? [ ]; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @return Page |
108 | 108 | */ |
109 | - public function getTalkPage() : Page { |
|
109 | + public function getTalkPage () : Page { |
|
110 | 110 | return new Page( "User talk:{$this->name}", $this->wiki ); |
111 | 111 | } |
112 | 112 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * Get the default base page, e.g. WP:A/Riconferma annuale/XXX |
115 | 115 | * @return Page |
116 | 116 | */ |
117 | - public function getBasePage() : Page { |
|
117 | + public function getBasePage () : Page { |
|
118 | 118 | $prefix = Config::getInstance()->get( 'main-page-title' ); |
119 | 119 | return new Page( "$prefix/$this", $this->wiki ); |
120 | 120 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @throws MissingPageException |
127 | 127 | * @return Page |
128 | 128 | */ |
129 | - public function getExistingBasePage() : Page { |
|
129 | + public function getExistingBasePage () : Page { |
|
130 | 130 | $basePage = $this->getBasePage(); |
131 | 131 | if ( !$basePage->exists() ) { |
132 | 132 | $basePage = null; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | /** |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function __toString() { |
|
153 | + public function __toString () { |
|
154 | 154 | return $this->name; |
155 | 155 | } |
156 | 156 | } |
@@ -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\Subtask; |
4 | 4 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * @inheritDoc |
15 | 15 | */ |
16 | - public function runInternal() : int { |
|
16 | + public function runInternal () : int { |
|
17 | 17 | $pages = $this->getDataProvider()->getPagesToClose(); |
18 | 18 | |
19 | 19 | if ( !$pages ) { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @param PageRiconferma $page |
37 | 37 | */ |
38 | - protected function addVoteCloseText( PageRiconferma $page ) { |
|
38 | + protected function addVoteCloseText ( PageRiconferma $page ) { |
|
39 | 39 | $content = $page->getContent(); |
40 | 40 | $beforeReg = '!è necessario ottenere una maggioranza .+ votanti\.!'; |
41 | 41 | $newContent = preg_replace( $beforeReg, '$0' . "\n" . $page->getOutcomeText(), $content ); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param PageRiconferma $page |
51 | 51 | * @see CreatePages::updateBasePage() |
52 | 52 | */ |
53 | - protected function updateBasePage( PageRiconferma $page ) { |
|
53 | + protected function updateBasePage ( PageRiconferma $page ) { |
|
54 | 54 | $this->getLogger()->info( "Updating base page for $page" ); |
55 | 55 | |
56 | 56 | if ( $page->getNum() === 1 ) { |
@@ -62,8 +62,7 @@ discard block |
||
62 | 62 | $current = $basePage->getContent(); |
63 | 63 | |
64 | 64 | $outcomeText = $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ? |
65 | - 'non riconfermato' : |
|
66 | - 'riconfermato'; |
|
65 | + 'non riconfermato' : 'riconfermato'; |
|
67 | 66 | $text = $page->isVote() ? "votazione: $outcomeText" : 'riconferma tacita'; |
68 | 67 | |
69 | 68 | $newContent = str_replace( 'riconferma in corso', $text, $current ); |
@@ -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\Subtask; |
4 | 4 | |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @inheritDoc |
18 | 18 | */ |
19 | - public function runInternal() : int { |
|
19 | + public function runInternal () : int { |
|
20 | 20 | $users = $this->getDataProvider()->getUsersToProcess(); |
21 | 21 | |
22 | 22 | if ( !$users ) { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param User $user |
37 | 37 | */ |
38 | - protected function processUser( User $user ) { |
|
38 | + protected function processUser ( User $user ) { |
|
39 | 39 | try { |
40 | 40 | $num = $this->getLastPageNum( $user ) + 1; |
41 | 41 | } catch ( TaskException $e ) { |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | * @return int |
70 | 70 | * @throws TaskException |
71 | 71 | */ |
72 | - protected function getLastPageNum( User $user ) : int { |
|
72 | + protected function getLastPageNum ( User $user ) : int { |
|
73 | 73 | $this->getLogger()->debug( "Retrieving previous pages for $user" ); |
74 | 74 | |
75 | - $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[1]; |
|
75 | + $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[ 1 ]; |
|
76 | 76 | |
77 | 77 | $prefixes = [ "$unprefixedTitle/$user/" ]; |
78 | 78 | foreach ( $user->getAliases() as $alias ) { |
79 | - $prefixes[] = "$unprefixedTitle/$alias/"; |
|
79 | + $prefixes[ ] = "$unprefixedTitle/$alias/"; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $params = [ |
@@ -112,14 +112,14 @@ discard block |
||
112 | 112 | * @param string $title |
113 | 113 | * @param User $user |
114 | 114 | */ |
115 | - protected function createPage( string $title, User $user ) { |
|
115 | + protected function createPage ( string $title, User $user ) { |
|
116 | 116 | $this->getLogger()->info( "Creating page $title" ); |
117 | 117 | $groups = $user->getGroups(); |
118 | 118 | $textParams = [ |
119 | 119 | '$user' => $user->getName(), |
120 | - '$date' => $groups['sysop'], |
|
121 | - '$burocrate' => $groups['bureaucrat'] ?? '', |
|
122 | - '$checkuser' => $groups['checkuser'] ?? '' |
|
120 | + '$date' => $groups[ 'sysop' ], |
|
121 | + '$burocrate' => $groups[ 'bureaucrat' ] ?? '', |
|
122 | + '$checkuser' => $groups[ 'checkuser' ] ?? '' |
|
123 | 123 | ]; |
124 | 124 | |
125 | 125 | $params = [ |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param Page $basePage |
138 | 138 | * @param string $newText |
139 | 139 | */ |
140 | - protected function createBasePage( Page $basePage, string $newText ) { |
|
140 | + protected function createBasePage ( Page $basePage, string $newText ) { |
|
141 | 141 | $this->getLogger()->info( "Creating base page $basePage" ); |
142 | 142 | |
143 | 143 | $params = [ |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param Page $basePage |
154 | 154 | * @param string $newText |
155 | 155 | */ |
156 | - protected function updateBasePage( Page $basePage, string $newText ) { |
|
156 | + protected function updateBasePage ( Page $basePage, string $newText ) { |
|
157 | 157 | $this->getLogger()->info( "Updating base page $basePage" ); |
158 | 158 | |
159 | 159 | $params = [ |