@@ -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 | |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @inheritDoc |
21 | 21 | */ |
22 | - protected function getSubtasksMap(): array { |
|
22 | + protected function getSubtasksMap (): array { |
|
23 | 23 | // Everything is done here. |
24 | - return []; |
|
24 | + return [ ]; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @inheritDoc |
29 | 29 | */ |
30 | - public function runInternal() : int { |
|
30 | + public function runInternal () : int { |
|
31 | 31 | $this->actualList = $this->getActualAdmins(); |
32 | 32 | $pageBotList = PageBotList::get( $this->getWiki() ); |
33 | 33 | $this->botList = $pageBotList->getAdminsList(); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - protected function getActualAdmins() : array { |
|
57 | + protected function getActualAdmins () : array { |
|
58 | 58 | $params = [ |
59 | 59 | 'action' => 'query', |
60 | 60 | 'list' => 'allusers', |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | * @param \stdClass $data |
72 | 72 | * @return array |
73 | 73 | */ |
74 | - protected function extractAdmins( \stdClass $data ) : array { |
|
75 | - $ret = []; |
|
74 | + protected function extractAdmins ( \stdClass $data ) : array { |
|
75 | + $ret = [ ]; |
|
76 | 76 | $blacklist = $this->getOpt( 'exclude-admins' ); |
77 | 77 | foreach ( $data->query->allusers as $u ) { |
78 | 78 | if ( in_array( $u->name, $blacklist ) ) { |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return array[] |
91 | 91 | */ |
92 | - protected function getMissingGroups() : array { |
|
93 | - $missing = []; |
|
92 | + protected function getMissingGroups () : array { |
|
93 | + $missing = [ ]; |
|
94 | 94 | foreach ( $this->actualList as $adm => $groups ) { |
95 | - $curMissing = array_diff( $groups, array_keys( $this->botList[$adm] ?? [] ) ); |
|
95 | + $curMissing = array_diff( $groups, array_keys( $this->botList[ $adm ] ?? [ ] ) ); |
|
96 | 96 | |
97 | 97 | foreach ( $curMissing as $group ) { |
98 | 98 | try { |
99 | 99 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
100 | 100 | } catch ( TaskException $e ) { |
101 | - $this->errors[] = $e->getMessage(); |
|
101 | + $this->errors[ ] = $e->getMessage(); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @return string |
114 | 114 | * @throws TaskException |
115 | 115 | */ |
116 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
116 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
117 | 117 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
118 | 118 | |
119 | 119 | $url = DEFAULT_URL; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param string $group |
150 | 150 | * @return string|null |
151 | 151 | */ |
152 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
152 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
153 | 153 | $ts = null; |
154 | 154 | foreach ( $data->query->logevents as $entry ) { |
155 | 155 | if ( isset( $entry->params ) ) { |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return array[] |
170 | 170 | */ |
171 | - protected function getExtraGroups() : array { |
|
172 | - $extra = []; |
|
171 | + protected function getExtraGroups () : array { |
|
172 | + $extra = [ ]; |
|
173 | 173 | foreach ( $this->botList as $name => $groups ) { |
174 | 174 | $groups = array_diff_key( $groups, PageBotList::NON_GROUP_KEYS ); |
175 | 175 | if ( !isset( $this->actualList[ $name ] ) ) { |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param string[] $names |
188 | 188 | * @return string[] [ new_name => old_name ] |
189 | 189 | */ |
190 | - protected function checkRenamedUsers( array $names ) : array { |
|
190 | + protected function checkRenamedUsers ( array $names ) : array { |
|
191 | 191 | $titles = array_map( function ( $x ) { |
192 | 192 | return "Utente:$x"; |
193 | 193 | }, $names ); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | ]; |
203 | 203 | |
204 | 204 | $data = RequestBase::newFromParams( $params )->execute(); |
205 | - $ret = []; |
|
205 | + $ret = [ ]; |
|
206 | 206 | foreach ( $data->query->logevents as $entry ) { |
207 | 207 | $time = strtotime( $entry->timestamp ); |
208 | 208 | // 1 month is arbitrary |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | * @param array[] $extra |
222 | 222 | * @return array[] |
223 | 223 | */ |
224 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
224 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
225 | 225 | $newContent = $this->botList; |
226 | 226 | $renameMap = $this->checkRenamedUsers( array_keys( $extra ) ); |
227 | - $removed = []; |
|
227 | + $removed = [ ]; |
|
228 | 228 | foreach ( $newContent as $user => $groups ) { |
229 | 229 | if ( isset( $missing[ $user ] ) ) { |
230 | 230 | $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $newContent[ $user ] = $newGroups; |
236 | 236 | } else { |
237 | 237 | unset( $newContent[ $user ] ); |
238 | - $removed[] = $user; |
|
238 | + $removed[ ] = $user; |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
@@ -246,16 +246,16 @@ discard block |
||
246 | 246 | foreach ( $removed as $oldName ) { |
247 | 247 | if ( |
248 | 248 | array_key_exists( $oldName, $renameMap ) && |
249 | - array_key_exists( $renameMap[$oldName], $newContent ) |
|
249 | + array_key_exists( $renameMap[ $oldName ], $newContent ) |
|
250 | 250 | ) { |
251 | 251 | $newName = $renameMap[ $oldName ]; |
252 | 252 | // This user was renamed! Add this name as alias... If they're still listed! |
253 | 253 | if ( array_key_exists( 'aliases', $newContent[ $newName ] ) ) { |
254 | - if ( !in_array( $oldName, $newContent[ $newName ]['aliases'] ) ) { |
|
255 | - $newContent[ $newName ]['aliases'][] = $oldName; |
|
254 | + if ( !in_array( $oldName, $newContent[ $newName ][ 'aliases' ] ) ) { |
|
255 | + $newContent[ $newName ][ 'aliases' ][ ] = $oldName; |
|
256 | 256 | } |
257 | 257 | } else { |
258 | - $newContent[ $newName ]['aliases'] = [ $oldName ]; |
|
258 | + $newContent[ $newName ][ 'aliases' ] = [ $oldName ]; |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
@@ -272,21 +272,21 @@ discard block |
||
272 | 272 | * @param array[] $newContent |
273 | 273 | * @return array[] |
274 | 274 | */ |
275 | - protected function removeOverrides( array $newContent ) : array { |
|
276 | - $removed = []; |
|
275 | + protected function removeOverrides ( array $newContent ) : array { |
|
276 | + $removed = [ ]; |
|
277 | 277 | foreach ( $newContent as $user => $groups ) { |
278 | - if ( !isset( $groups['override'] ) ) { |
|
278 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
279 | 279 | continue; |
280 | 280 | } |
281 | 281 | |
282 | 282 | $flagTS = PageBotList::getValidFlagTimestamp( $groups ); |
283 | 283 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); |
284 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
284 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
285 | 285 | $delay = 60 * 60 * 24 * 3; |
286 | 286 | |
287 | 287 | if ( time() > $usualTS + $delay && time() > $overrideTS + $delay ) { |
288 | 288 | unset( $newContent[ $user ][ 'override' ] ); |
289 | - $removed[] = $user; |
|
289 | + $removed[ ] = $user; |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 |
@@ -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 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @param string $name |
18 | 18 | * @param Wiki $wiki |
19 | 19 | */ |
20 | - public function __construct( string $name, Wiki $wiki ) { |
|
20 | + public function __construct ( string $name, Wiki $wiki ) { |
|
21 | 21 | parent::__construct( $wiki ); |
22 | 22 | $this->name = $name; |
23 | 23 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @return string |
27 | 27 | */ |
28 | - public function getName() : string { |
|
28 | + public function getName () : string { |
|
29 | 29 | return $this->name; |
30 | 30 | } |
31 | 31 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return string[] |
36 | 36 | */ |
37 | - public function getGroups() : array { |
|
37 | + public function getGroups () : array { |
|
38 | 38 | return array_keys( array_diff_key( $this->getUserInfo(), PageBotList::NON_GROUP_KEYS ) ); |
39 | 39 | } |
40 | 40 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return string[] |
45 | 45 | */ |
46 | - public function getUserInfo() : array { |
|
46 | + public function getUserInfo () : array { |
|
47 | 47 | if ( $this->groups === null ) { |
48 | 48 | $usersList = PageBotList::get( $this->wiki )->getAdminsList(); |
49 | 49 | $this->groups = $usersList[ $this->name ]; |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param string $groupName |
58 | 58 | * @return bool |
59 | 59 | */ |
60 | - public function inGroup( string $groupName ) : bool { |
|
60 | + public function inGroup ( string $groupName ) : bool { |
|
61 | 61 | return in_array( $groupName, $this->getGroups() ); |
62 | 62 | } |
63 | 63 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @inheritDoc |
68 | 68 | */ |
69 | - public function getRegex() : string { |
|
69 | + public function getRegex () : string { |
|
70 | 70 | return str_replace( ' ', '[ _]', preg_quote( $this->name ) ); |
71 | 71 | } |
72 | 72 | |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return string[] |
77 | 77 | */ |
78 | - public function getAliases() : array { |
|
79 | - return $this->getUserInfo()['aliases'] ?? []; |
|
78 | + public function getAliases () : array { |
|
79 | + return $this->getUserInfo()[ 'aliases' ] ?? [ ]; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @return string |
84 | 84 | */ |
85 | - public function __toString() { |
|
85 | + public function __toString () { |
|
86 | 86 | return $this->name; |
87 | 87 | } |
88 | 88 | } |