@@ -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 | |
@@ -22,15 +22,15 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @inheritDoc |
| 24 | 24 | */ |
| 25 | - protected function getSubtasksMap(): array { |
|
| 25 | + protected function getSubtasksMap (): array { |
|
| 26 | 26 | // Everything is done here. |
| 27 | - return []; |
|
| 27 | + return [ ]; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * @inheritDoc |
| 32 | 32 | */ |
| 33 | - public function runInternal(): int { |
|
| 33 | + public function runInternal (): int { |
|
| 34 | 34 | $this->actualList = $this->getActualAdmins(); |
| 35 | 35 | $pageBotList = $this->getBotList(); |
| 36 | 36 | $this->botList = $pageBotList->getDecodedContent(); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @return string[][] |
| 59 | 59 | * @phan-return array<string,string[]> |
| 60 | 60 | */ |
| 61 | - protected function getActualAdmins(): array { |
|
| 61 | + protected function getActualAdmins (): array { |
|
| 62 | 62 | $params = [ |
| 63 | 63 | 'action' => 'query', |
| 64 | 64 | 'list' => 'allusers', |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | * @return string[][] |
| 77 | 77 | * @phan-return array<string,string[]> |
| 78 | 78 | */ |
| 79 | - protected function extractAdmins( Generator $data ): array { |
|
| 80 | - $ret = []; |
|
| 79 | + protected function extractAdmins ( Generator $data ): array { |
|
| 80 | + $ret = [ ]; |
|
| 81 | 81 | $blacklist = $this->getOpt( 'exclude-admins' ); |
| 82 | 82 | foreach ( $data as $u ) { |
| 83 | 83 | if ( in_array( $u->name, $blacklist, true ) ) { |
@@ -94,16 +94,16 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * @return string[][] |
| 96 | 96 | */ |
| 97 | - protected function getMissingGroups(): array { |
|
| 98 | - $missing = []; |
|
| 97 | + protected function getMissingGroups (): array { |
|
| 98 | + $missing = [ ]; |
|
| 99 | 99 | foreach ( $this->actualList as $adm => $groups ) { |
| 100 | - $curMissing = array_diff( $groups, array_keys( $this->botList[$adm] ?? [] ) ); |
|
| 100 | + $curMissing = array_diff( $groups, array_keys( $this->botList[ $adm ] ?? [ ] ) ); |
|
| 101 | 101 | |
| 102 | 102 | foreach ( $curMissing as $group ) { |
| 103 | 103 | try { |
| 104 | 104 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 105 | 105 | } catch ( TaskException $e ) { |
| 106 | - $this->errors[] = $e->getMessage(); |
|
| 106 | + $this->errors[ ] = $e->getMessage(); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @return string |
| 119 | 119 | * @throws TaskException |
| 120 | 120 | */ |
| 121 | - protected function getFlagDate( string $admin, string $group ): string { |
|
| 121 | + protected function getFlagDate ( string $admin, string $group ): string { |
|
| 122 | 122 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 123 | 123 | |
| 124 | 124 | $wiki = $this->getWiki(); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param string $group |
| 154 | 154 | * @return string|null |
| 155 | 155 | */ |
| 156 | - private function extractTimestamp( Generator $data, string $group ): ?string { |
|
| 156 | + private function extractTimestamp ( Generator $data, string $group ): ?string { |
|
| 157 | 157 | $ts = null; |
| 158 | 158 | foreach ( $data as $entry ) { |
| 159 | 159 | if ( |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * |
| 173 | 173 | * @return string[][] |
| 174 | 174 | */ |
| 175 | - protected function getExtraGroups(): array { |
|
| 176 | - $extra = []; |
|
| 175 | + protected function getExtraGroups (): array { |
|
| 176 | + $extra = [ ]; |
|
| 177 | 177 | foreach ( $this->botList as $name => $groups ) { |
| 178 | 178 | $groups = array_diff_key( $groups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ); |
| 179 | 179 | if ( !isset( $this->actualList[ $name ] ) ) { |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @param string[] $names |
| 190 | 190 | * @return Generator |
| 191 | 191 | */ |
| 192 | - private function getRenameEntries( array $names ): Generator { |
|
| 192 | + private function getRenameEntries ( array $names ): Generator { |
|
| 193 | 193 | $titles = array_map( static function ( string $x ): string { |
| 194 | 194 | return "Utente:$x"; |
| 195 | 195 | }, $names ); |
@@ -213,14 +213,14 @@ discard block |
||
| 213 | 213 | * @param string[] $names |
| 214 | 214 | * @return string[] [ old_name => new_name ] |
| 215 | 215 | */ |
| 216 | - protected function getRenamedUsers( array $names ): array { |
|
| 216 | + protected function getRenamedUsers ( array $names ): array { |
|
| 217 | 217 | if ( !$names ) { |
| 218 | - return []; |
|
| 218 | + return [ ]; |
|
| 219 | 219 | } |
| 220 | 220 | $this->getLogger()->info( 'Checking rename for ' . implode( ', ', $names ) ); |
| 221 | 221 | |
| 222 | 222 | $data = $this->getRenameEntries( $names ); |
| 223 | - $ret = []; |
|
| 223 | + $ret = [ ]; |
|
| 224 | 224 | foreach ( $data as $entry ) { |
| 225 | 225 | // 1 month is arbitrary |
| 226 | 226 | if ( strtotime( $entry->timestamp ) > strtotime( '-1 month' ) ) { |
@@ -239,18 +239,18 @@ discard block |
||
| 239 | 239 | * @phan-param array<string,array<string,string|string[]>> $newContent |
| 240 | 240 | * @param string[][] $removed |
| 241 | 241 | */ |
| 242 | - private function handleRenames( array &$newContent, array $removed ): void { |
|
| 242 | + private function handleRenames ( array &$newContent, array $removed ): void { |
|
| 243 | 243 | $renameMap = $this->getRenamedUsers( array_keys( $removed ) ); |
| 244 | 244 | foreach ( $removed as $oldName => $info ) { |
| 245 | 245 | if ( |
| 246 | 246 | array_key_exists( $oldName, $renameMap ) && |
| 247 | - array_key_exists( $renameMap[$oldName], $newContent ) |
|
| 247 | + array_key_exists( $renameMap[ $oldName ], $newContent ) |
|
| 248 | 248 | ) { |
| 249 | 249 | // This user was renamed! Add this name as alias, if they're still listed |
| 250 | 250 | $newName = $renameMap[ $oldName ]; |
| 251 | 251 | $this->getLogger()->info( "Found rename $oldName -> $newName" ); |
| 252 | - $aliases = array_unique( array_merge( $newContent[ $newName ]['aliases'] ?? [], [ $oldName ] ) ); |
|
| 253 | - $newContent[ $newName ]['aliases'] = $aliases; |
|
| 252 | + $aliases = array_unique( array_merge( $newContent[ $newName ][ 'aliases' ] ?? [ ], [ $oldName ] ) ); |
|
| 253 | + $newContent[ $newName ][ 'aliases' ] = $aliases; |
|
| 254 | 254 | // Transfer overrides to the new name. |
| 255 | 255 | $overrides = array_diff_key( $info, [ 'override' => 1, 'override-perm' => 1 ] ); |
| 256 | 256 | $newContent[ $newName ] = array_merge( $newContent[ $newName ], $overrides ); |
@@ -265,12 +265,12 @@ discard block |
||
| 265 | 265 | * @param string[][] $extra |
| 266 | 266 | * @return string[][] Removed users |
| 267 | 267 | */ |
| 268 | - private function handleExtraAndMissing( |
|
| 268 | + private function handleExtraAndMissing ( |
|
| 269 | 269 | array &$newContent, |
| 270 | 270 | array $missing, |
| 271 | 271 | array $extra |
| 272 | 272 | ): array { |
| 273 | - $removed = []; |
|
| 273 | + $removed = [ ]; |
|
| 274 | 274 | foreach ( $newContent as $user => $groups ) { |
| 275 | 275 | if ( isset( $missing[ $user ] ) ) { |
| 276 | 276 | $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | if ( array_diff_key( $newGroups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ) ) { |
| 281 | 281 | $newContent[ $user ] = $newGroups; |
| 282 | 282 | } else { |
| 283 | - $removed[$user] = $newContent[$user]; |
|
| 283 | + $removed[ $user ] = $newContent[ $user ]; |
|
| 284 | 284 | unset( $newContent[ $user ] ); |
| 285 | 285 | } |
| 286 | 286 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @param string[][] $extra |
| 298 | 298 | * @return array[] |
| 299 | 299 | */ |
| 300 | - protected function getNewContent( array $missing, array $extra ): array { |
|
| 300 | + protected function getNewContent ( array $missing, array $extra ): array { |
|
| 301 | 301 | $newContent = $this->botList; |
| 302 | 302 | |
| 303 | 303 | $removed = $this->handleExtraAndMissing( $newContent, $missing, $extra ); |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | * |
| 317 | 317 | * @param array[] &$newContent |
| 318 | 318 | */ |
| 319 | - protected function removeOverrides( array &$newContent ): void { |
|
| 320 | - $removed = []; |
|
| 319 | + protected function removeOverrides ( array &$newContent ): void { |
|
| 320 | + $removed = [ ]; |
|
| 321 | 321 | foreach ( $newContent as $user => $groups ) { |
| 322 | 322 | if ( PageBotList::isOverrideExpired( $groups ) ) { |
| 323 | 323 | unset( $newContent[ $user ][ 'override' ] ); |
| 324 | - $removed[] = $user; |
|
| 324 | + $removed[ ] = $user; |
|
| 325 | 325 | } |
| 326 | 326 | } |
| 327 | 327 | |