@@ -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, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ); |
| 175 | 175 | if ( !isset( $this->actualList[ $name ] ) ) { |
@@ -187,9 +187,9 @@ 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 | if ( !$names ) { |
| 192 | - return []; |
|
| 192 | + return [ ]; |
|
| 193 | 193 | } |
| 194 | 194 | $this->getLogger()->info( 'Checking rename for ' . implode( ', ', $names ) ); |
| 195 | 195 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | ]; |
| 208 | 208 | |
| 209 | 209 | $data = RequestBase::newFromParams( $params )->execute(); |
| 210 | - $ret = []; |
|
| 210 | + $ret = [ ]; |
|
| 211 | 211 | foreach ( $data->query->logevents as $entry ) { |
| 212 | 212 | $time = strtotime( $entry->timestamp ); |
| 213 | 213 | // 1 month is arbitrary |
@@ -226,10 +226,10 @@ discard block |
||
| 226 | 226 | * @param array[] $extra |
| 227 | 227 | * @return array[] |
| 228 | 228 | */ |
| 229 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 229 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 230 | 230 | $newContent = $this->botList; |
| 231 | 231 | $renameMap = $this->checkRenamedUsers( array_keys( $extra ) ); |
| 232 | - $removed = []; |
|
| 232 | + $removed = [ ]; |
|
| 233 | 233 | foreach ( $newContent as $user => $groups ) { |
| 234 | 234 | if ( isset( $missing[ $user ] ) ) { |
| 235 | 235 | $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | if ( array_diff_key( $newGroups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ) ) { |
| 240 | 240 | $newContent[ $user ] = $newGroups; |
| 241 | 241 | } else { |
| 242 | - $removed[$user] = $newContent[$user]; |
|
| 242 | + $removed[ $user ] = $newContent[ $user ]; |
|
| 243 | 243 | unset( $newContent[ $user ] ); |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -250,17 +250,17 @@ discard block |
||
| 250 | 250 | foreach ( $removed as $oldName => $info ) { |
| 251 | 251 | if ( |
| 252 | 252 | array_key_exists( $oldName, $renameMap ) && |
| 253 | - array_key_exists( $renameMap[$oldName], $newContent ) |
|
| 253 | + array_key_exists( $renameMap[ $oldName ], $newContent ) |
|
| 254 | 254 | ) { |
| 255 | 255 | // This user was renamed! Add this name as alias, if they're still listed |
| 256 | 256 | $newName = $renameMap[ $oldName ]; |
| 257 | 257 | $this->getLogger()->info( "Found rename $oldName -> $newName" ); |
| 258 | 258 | if ( array_key_exists( 'aliases', $newContent[ $newName ] ) ) { |
| 259 | - if ( !in_array( $oldName, $newContent[ $newName ]['aliases'] ) ) { |
|
| 260 | - $newContent[ $newName ]['aliases'][] = $oldName; |
|
| 259 | + if ( !in_array( $oldName, $newContent[ $newName ][ 'aliases' ] ) ) { |
|
| 260 | + $newContent[ $newName ][ 'aliases' ][ ] = $oldName; |
|
| 261 | 261 | } |
| 262 | 262 | } else { |
| 263 | - $newContent[ $newName ]['aliases'] = [ $oldName ]; |
|
| 263 | + $newContent[ $newName ][ 'aliases' ] = [ $oldName ]; |
|
| 264 | 264 | } |
| 265 | 265 | // Transfer overrides to the new name. |
| 266 | 266 | $overrides = array_diff_key( $info, [ 'override' => 1, 'override-perm' => 1 ] ); |
@@ -280,21 +280,21 @@ discard block |
||
| 280 | 280 | * @param array[] $newContent |
| 281 | 281 | * @return array[] |
| 282 | 282 | */ |
| 283 | - protected function removeOverrides( array $newContent ) : array { |
|
| 284 | - $removed = []; |
|
| 283 | + protected function removeOverrides ( array $newContent ) : array { |
|
| 284 | + $removed = [ ]; |
|
| 285 | 285 | foreach ( $newContent as $user => $groups ) { |
| 286 | - if ( !isset( $groups['override'] ) ) { |
|
| 286 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
| 287 | 287 | continue; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | $flagTS = PageBotList::getValidFlagTimestamp( $groups ); |
| 291 | 291 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); |
| 292 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
| 292 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
| 293 | 293 | $delay = 60 * 60 * 24 * 3; |
| 294 | 294 | |
| 295 | 295 | if ( time() > $usualTS + $delay && time() > $overrideTS + $delay ) { |
| 296 | 296 | unset( $newContent[ $user ][ 'override' ] ); |
| 297 | - $removed[] = $user; |
|
| 297 | + $removed[ ] = $user; |
|
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | |