@@ -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->getDecodedContent(); |
@@ -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, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ); |
| 175 | 175 | if ( !isset( $this->actualList[ $name ] ) ) { |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * @param string[] $names |
| 186 | 186 | * @return \stdClass |
| 187 | 187 | */ |
| 188 | - private function getRenameEntries( array $names ) : \stdClass { |
|
| 188 | + private function getRenameEntries ( array $names ) : \stdClass { |
|
| 189 | 189 | $titles = array_map( function ( $x ) { |
| 190 | 190 | return "Utente:$x"; |
| 191 | 191 | }, $names ); |
@@ -209,14 +209,14 @@ discard block |
||
| 209 | 209 | * @param string[] $names |
| 210 | 210 | * @return string[] [ old_name => new_name ] |
| 211 | 211 | */ |
| 212 | - protected function getRenamedUsers( array $names ) : array { |
|
| 212 | + protected function getRenamedUsers ( array $names ) : array { |
|
| 213 | 213 | if ( !$names ) { |
| 214 | - return []; |
|
| 214 | + return [ ]; |
|
| 215 | 215 | } |
| 216 | 216 | $this->getLogger()->info( 'Checking rename for ' . implode( ', ', $names ) ); |
| 217 | 217 | |
| 218 | 218 | $data = $this->getRenameEntries( $names ); |
| 219 | - $ret = []; |
|
| 219 | + $ret = [ ]; |
|
| 220 | 220 | foreach ( $data->query->logevents as $entry ) { |
| 221 | 221 | $time = strtotime( $entry->timestamp ); |
| 222 | 222 | // 1 month is arbitrary |
@@ -235,22 +235,22 @@ discard block |
||
| 235 | 235 | * @param array &$newContent |
| 236 | 236 | * @param array $removed |
| 237 | 237 | */ |
| 238 | - private function handleRenames( array &$newContent, array $removed ) : void { |
|
| 238 | + private function handleRenames ( array &$newContent, array $removed ) : void { |
|
| 239 | 239 | $renameMap = $this->getRenamedUsers( array_keys( $removed ) ); |
| 240 | 240 | foreach ( $removed as $oldName => $info ) { |
| 241 | 241 | if ( |
| 242 | 242 | array_key_exists( $oldName, $renameMap ) && |
| 243 | - array_key_exists( $renameMap[$oldName], $newContent ) |
|
| 243 | + array_key_exists( $renameMap[ $oldName ], $newContent ) |
|
| 244 | 244 | ) { |
| 245 | 245 | // This user was renamed! Add this name as alias, if they're still listed |
| 246 | 246 | $newName = $renameMap[ $oldName ]; |
| 247 | 247 | $this->getLogger()->info( "Found rename $oldName -> $newName" ); |
| 248 | 248 | if ( array_key_exists( 'aliases', $newContent[ $newName ] ) ) { |
| 249 | - if ( !in_array( $oldName, $newContent[ $newName ]['aliases'] ) ) { |
|
| 250 | - $newContent[ $newName ]['aliases'][] = $oldName; |
|
| 249 | + if ( !in_array( $oldName, $newContent[ $newName ][ 'aliases' ] ) ) { |
|
| 250 | + $newContent[ $newName ][ 'aliases' ][ ] = $oldName; |
|
| 251 | 251 | } |
| 252 | 252 | } else { |
| 253 | - $newContent[ $newName ]['aliases'] = [ $oldName ]; |
|
| 253 | + $newContent[ $newName ][ 'aliases' ] = [ $oldName ]; |
|
| 254 | 254 | } |
| 255 | 255 | // Transfer overrides to the new name. |
| 256 | 256 | $overrides = array_diff_key( $info, [ 'override' => 1, 'override-perm' => 1 ] ); |
@@ -266,9 +266,9 @@ discard block |
||
| 266 | 266 | * @param array[] $extra |
| 267 | 267 | * @return array[] |
| 268 | 268 | */ |
| 269 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 269 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 270 | 270 | $newContent = $this->botList; |
| 271 | - $removed = []; |
|
| 271 | + $removed = [ ]; |
|
| 272 | 272 | foreach ( $newContent as $user => $groups ) { |
| 273 | 273 | if ( isset( $missing[ $user ] ) ) { |
| 274 | 274 | $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | if ( array_diff_key( $newGroups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ) ) { |
| 279 | 279 | $newContent[ $user ] = $newGroups; |
| 280 | 280 | } else { |
| 281 | - $removed[$user] = $newContent[$user]; |
|
| 281 | + $removed[ $user ] = $newContent[ $user ]; |
|
| 282 | 282 | unset( $newContent[ $user ] ); |
| 283 | 283 | } |
| 284 | 284 | } |
@@ -297,10 +297,10 @@ discard block |
||
| 297 | 297 | * @param array $groups |
| 298 | 298 | * @return bool |
| 299 | 299 | */ |
| 300 | - private function isOverrideExpired( array $groups ) : bool { |
|
| 300 | + private function isOverrideExpired ( array $groups ) : bool { |
|
| 301 | 301 | $flagTS = PageBotList::getValidFlagTimestamp( $groups ); |
| 302 | 302 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); |
| 303 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
| 303 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
| 304 | 304 | $delay = 60 * 60 * 24 * 3; |
| 305 | 305 | |
| 306 | 306 | return time() > $usualTS + $delay && time() > $overrideTS + $delay; |
@@ -313,16 +313,16 @@ discard block |
||
| 313 | 313 | * @param array[] $newContent |
| 314 | 314 | * @return array[] |
| 315 | 315 | */ |
| 316 | - protected function removeOverrides( array $newContent ) : array { |
|
| 317 | - $removed = []; |
|
| 316 | + protected function removeOverrides ( array $newContent ) : array { |
|
| 317 | + $removed = [ ]; |
|
| 318 | 318 | foreach ( $newContent as $user => $groups ) { |
| 319 | - if ( !isset( $groups['override'] ) ) { |
|
| 319 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
| 320 | 320 | continue; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | if ( $this->isOverrideExpired( $groups ) ) { |
| 324 | 324 | unset( $newContent[ $user ][ 'override' ] ); |
| 325 | - $removed[] = $user; |
|
| 325 | + $removed[ ] = $user; |
|
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |