@@ -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 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | /** |
| 12 | 12 | * @private Use self::get() |
| 13 | 13 | */ |
| 14 | - public function __construct() { |
|
| 14 | + public function __construct () { |
|
| 15 | 15 | parent::__construct( Config::getInstance()->get( 'list-title' ) ); |
| 16 | 16 | } |
| 17 | 17 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return self |
| 22 | 22 | */ |
| 23 | - public static function get() : self { |
|
| 23 | + public static function get () : self { |
|
| 24 | 24 | static $instance = null; |
| 25 | 25 | if ( $instance === null ) { |
| 26 | 26 | $instance = new self; |
@@ -32,16 +32,16 @@ discard block |
||
| 32 | 32 | * @param string[] $groups |
| 33 | 33 | * @return int|null |
| 34 | 34 | */ |
| 35 | - public static function getOverrideTimestamp( array $groups ) : ?int { |
|
| 35 | + public static function getOverrideTimestamp ( array $groups ) : ?int { |
|
| 36 | 36 | if ( !array_intersect_key( $groups, [ 'override-perm' => true, 'override' => true ] ) ) { |
| 37 | 37 | return null; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // A one-time override takes precedence |
| 41 | 41 | if ( array_key_exists( 'override', $groups ) ) { |
| 42 | - $date = $groups['override']; |
|
| 42 | + $date = $groups[ 'override' ]; |
|
| 43 | 43 | } else { |
| 44 | - $date = $groups['override-prem'] . '/' . date( 'Y' ); |
|
| 44 | + $date = $groups[ 'override-prem' ] . '/' . date( 'Y' ); |
|
| 45 | 45 | } |
| 46 | 46 | return \DateTime::createFromFormat( 'd/m/Y', $date )->getTimestamp(); |
| 47 | 47 | } |
@@ -52,17 +52,15 @@ discard block |
||
| 52 | 52 | * @param array $groups |
| 53 | 53 | * @return int |
| 54 | 54 | */ |
| 55 | - public static function getValidFlagTimestamp( array $groups ): int { |
|
| 56 | - $checkuser = isset( $groups['checkuser'] ) ? |
|
| 57 | - \DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() : |
|
| 58 | - 0; |
|
| 59 | - $bureaucrat = isset( $groups['bureaucrat'] ) ? |
|
| 60 | - \DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() : |
|
| 61 | - 0; |
|
| 55 | + public static function getValidFlagTimestamp ( array $groups ): int { |
|
| 56 | + $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
| 57 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
| 58 | + $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
| 59 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
| 62 | 60 | |
| 63 | 61 | $timestamp = max( $bureaucrat, $checkuser ); |
| 64 | 62 | if ( $timestamp === 0 ) { |
| 65 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp(); |
|
| 63 | + $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
| 66 | 64 | } |
| 67 | 65 | return $timestamp; |
| 68 | 66 | } |
@@ -72,7 +70,7 @@ discard block |
||
| 72 | 70 | * |
| 73 | 71 | * @return array[] |
| 74 | 72 | */ |
| 75 | - public function getAdminsList() : array { |
|
| 73 | + public function getAdminsList () : array { |
|
| 76 | 74 | return json_decode( $this->getContent(), true ); |
| 77 | 75 | } |
| 78 | 76 | } |
@@ -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 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * @inheritDoc |
| 19 | 19 | */ |
| 20 | - public function runInternal() : int { |
|
| 20 | + public function runInternal () : int { |
|
| 21 | 21 | $pages = $this->getDataProvider()->getPagesToClose(); |
| 22 | 22 | |
| 23 | 23 | if ( !$pages ) { |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | * @param PageRiconferma[] $pages |
| 40 | 40 | * @see OpenUpdates::addToVotazioni() |
| 41 | 41 | */ |
| 42 | - protected function updateVotazioni( array $pages ) { |
|
| 42 | + protected function updateVotazioni ( array $pages ) { |
|
| 43 | 43 | $this->getLogger()->info( |
| 44 | 44 | 'Updating votazioni: ' . implode( ', ', $pages ) |
| 45 | 45 | ); |
| 46 | 46 | $votePage = new Page( $this->getOpt( 'vote-page-title' ) ); |
| 47 | 47 | |
| 48 | - $users = []; |
|
| 48 | + $users = [ ]; |
|
| 49 | 49 | foreach ( $pages as $page ) { |
| 50 | - $users[] = $page->getUser(); |
|
| 50 | + $users[ ] = $page->getUser(); |
|
| 51 | 51 | } |
| 52 | 52 | $usersReg = Element::regexFromArray( $users ); |
| 53 | 53 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @param array $pages |
| 69 | 69 | * @see OpenUpdates::addToNews() |
| 70 | 70 | */ |
| 71 | - protected function updateNews( array $pages ) { |
|
| 71 | + protected function updateNews ( array $pages ) { |
|
| 72 | 72 | $simpleAmount = $voteAmount = 0; |
| 73 | 73 | foreach ( $pages as $page ) { |
| 74 | 74 | if ( $page->isVote() ) { |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | $simpleMatches = $newsPage->getMatch( $simpleReg ); |
| 89 | 89 | $voteMatches = $newsPage->getMatch( $voteReg ); |
| 90 | 90 | |
| 91 | - $newSimp = (int)$simpleMatches[2] - $simpleAmount ?: ''; |
|
| 92 | - $newVote = (int)$voteMatches[2] - $voteAmount ?: ''; |
|
| 91 | + $newSimp = (int)$simpleMatches[ 2 ] - $simpleAmount ?: ''; |
|
| 92 | + $newVote = (int)$voteMatches[ 2 ] - $voteAmount ?: ''; |
|
| 93 | 93 | $newContent = preg_replace( $simpleReg, '${1}' . $newSimp, $newsPage->getContent() ); |
| 94 | 94 | $newContent = preg_replace( $voteReg, '${1}' . $newVote, $newContent ); |
| 95 | 95 | |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @param bool[] $outcomes |
| 109 | 109 | */ |
| 110 | - protected function updateAdminList( array $outcomes ) { |
|
| 110 | + protected function updateAdminList ( array $outcomes ) { |
|
| 111 | 111 | $this->getLogger()->info( 'Updating admin list' ); |
| 112 | 112 | $adminsPage = new Page( $this->getOpt( 'admins-list-title' ) ); |
| 113 | 113 | $newContent = $adminsPage->getContent(); |
| 114 | 114 | |
| 115 | - $riconfNames = $removeNames = []; |
|
| 115 | + $riconfNames = $removeNames = [ ]; |
|
| 116 | 116 | foreach ( $outcomes as $username => $confirmed ) { |
| 117 | 117 | $user = new User( $username ); |
| 118 | 118 | $userReg = $user->getRegex(); |
@@ -124,10 +124,10 @@ discard block |
||
| 124 | 124 | '${1}' . date( 'Ymd' ) . '|' . $nextDate . '$2', |
| 125 | 125 | $newContent |
| 126 | 126 | ); |
| 127 | - $riconfNames[] = $username; |
|
| 127 | + $riconfNames[ ] = $username; |
|
| 128 | 128 | } else { |
| 129 | 129 | $newContent = preg_replace( $reg, '', $newContent ); |
| 130 | - $removeNames[] = $username; |
|
| 130 | + $removeNames[ ] = $username; |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
@@ -150,12 +150,12 @@ discard block |
||
| 150 | 150 | * @param User $user |
| 151 | 151 | * @return int |
| 152 | 152 | */ |
| 153 | - private function getNextTs( User $user ) : int { |
|
| 153 | + private function getNextTs ( User $user ) : int { |
|
| 154 | 154 | $groups = $user->getGroupsWithDates(); |
| 155 | - if ( isset( $groups['override-perm'] ) ) { |
|
| 155 | + if ( isset( $groups[ 'override-perm' ] ) ) { |
|
| 156 | 156 | $date = \DateTime::createFromFormat( |
| 157 | 157 | 'd/m/Y', |
| 158 | - $groups['override-perm'] . '/' . date( 'Y' ) |
|
| 158 | + $groups[ 'override-perm' ] . '/' . date( 'Y' ) |
|
| 159 | 159 | ); |
| 160 | 160 | if ( $date < new \DateTime ) { |
| 161 | 161 | $date->modify( '+1 year' ); |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | } else { |
| 165 | 165 | $ts = PageBotList::getValidFlagTimestamp( $groups ); |
| 166 | 166 | $res = strtotime( date( 'Y', strtotime( '+1 year' ) ) . date( '-m-d', $ts ) ); |
| 167 | - if ( isset( $groups['override'] ) ) { |
|
| 168 | - $date = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] ); |
|
| 167 | + if ( isset( $groups[ 'override' ] ) ) { |
|
| 168 | + $date = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] ); |
|
| 169 | 169 | if ( $date > new \DateTime ) { |
| 170 | 170 | $res = $date->getTimestamp(); |
| 171 | 171 | } |
@@ -177,21 +177,21 @@ discard block |
||
| 177 | 177 | /** |
| 178 | 178 | * @param bool[] $outcomes |
| 179 | 179 | */ |
| 180 | - protected function updateCUList( array $outcomes ) { |
|
| 180 | + protected function updateCUList ( array $outcomes ) { |
|
| 181 | 181 | $this->getLogger()->info( 'Updating CU list.' ); |
| 182 | 182 | $cuList = new Page( $this->getOpt( 'cu-list-title' ) ); |
| 183 | 183 | $newContent = $cuList->getContent(); |
| 184 | 184 | |
| 185 | - $riconfNames = $removeNames = []; |
|
| 185 | + $riconfNames = $removeNames = [ ]; |
|
| 186 | 186 | foreach ( $outcomes as $user => $confirmed ) { |
| 187 | 187 | $userReg = ( new User( $user ) )->getRegex(); |
| 188 | 188 | $reg = "!(\{\{ *Checkuser *\| *$userReg *\|[^}]+\| *)[\w \d]+(}}.*\n)!"; |
| 189 | 189 | if ( $confirmed ) { |
| 190 | 190 | $newContent = preg_replace( $reg, '${1}{{subst:#time:j F Y}}$2', $newContent ); |
| 191 | - $riconfNames[] = $user; |
|
| 191 | + $riconfNames[ ] = $user; |
|
| 192 | 192 | } else { |
| 193 | 193 | $newContent = preg_replace( $reg, '', $newContent ); |
| 194 | - $removeNames[] = $user; |
|
| 194 | + $removeNames[ ] = $user; |
|
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | * @param PageRiconferma[] $pages |
| 216 | 216 | * @return bool[] |
| 217 | 217 | */ |
| 218 | - private function getGroupOutcomes( string $group, array $pages ) : array { |
|
| 219 | - $ret = []; |
|
| 218 | + private function getGroupOutcomes ( string $group, array $pages ) : array { |
|
| 219 | + $ret = [ ]; |
|
| 220 | 220 | foreach ( $pages as $page ) { |
| 221 | 221 | $user = $page->getUser(); |
| 222 | 222 | if ( $user->inGroup( $group ) ) { |
@@ -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 | $this->botList = PageBotList::get()->getAdminsList(); |
| 33 | 33 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * @return array |
| 55 | 55 | */ |
| 56 | - protected function getActualAdmins() : array { |
|
| 56 | + protected function getActualAdmins () : array { |
|
| 57 | 57 | $params = [ |
| 58 | 58 | 'action' => 'query', |
| 59 | 59 | 'list' => 'allusers', |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | * @param \stdClass $data |
| 71 | 71 | * @return array |
| 72 | 72 | */ |
| 73 | - protected function extractAdmins( \stdClass $data ) : array { |
|
| 74 | - $ret = []; |
|
| 73 | + protected function extractAdmins ( \stdClass $data ) : array { |
|
| 74 | + $ret = [ ]; |
|
| 75 | 75 | $blacklist = $this->getOpt( 'exclude-admins' ); |
| 76 | 76 | foreach ( $data->query->allusers as $u ) { |
| 77 | 77 | if ( in_array( $u->name, $blacklist ) ) { |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return array[] |
| 90 | 90 | */ |
| 91 | - protected function getMissingGroups() : array { |
|
| 92 | - $missing = []; |
|
| 91 | + protected function getMissingGroups () : array { |
|
| 92 | + $missing = [ ]; |
|
| 93 | 93 | foreach ( $this->actualList as $adm => $groups ) { |
| 94 | - $curMissing = array_diff( $groups, array_keys( $this->botList[$adm] ?? [] ) ); |
|
| 94 | + $curMissing = array_diff( $groups, array_keys( $this->botList[ $adm ] ?? [ ] ) ); |
|
| 95 | 95 | |
| 96 | 96 | foreach ( $curMissing as $group ) { |
| 97 | 97 | try { |
| 98 | 98 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 99 | 99 | } catch ( TaskException $e ) { |
| 100 | - $this->errors[] = $e->getMessage(); |
|
| 100 | + $this->errors[ ] = $e->getMessage(); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @return string |
| 113 | 113 | * @throws TaskException |
| 114 | 114 | */ |
| 115 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 115 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
| 116 | 116 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 117 | 117 | |
| 118 | 118 | $url = DEFAULT_URL; |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @param string $group |
| 148 | 148 | * @return string|null |
| 149 | 149 | */ |
| 150 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
| 150 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
| 151 | 151 | $ts = null; |
| 152 | 152 | foreach ( $data->query->logevents as $entry ) { |
| 153 | 153 | if ( isset( $entry->params ) ) { |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return array[] |
| 168 | 168 | */ |
| 169 | - protected function getExtraGroups() : array { |
|
| 170 | - $extra = []; |
|
| 169 | + protected function getExtraGroups () : array { |
|
| 170 | + $extra = [ ]; |
|
| 171 | 171 | foreach ( $this->botList as $name => $groups ) { |
| 172 | 172 | // These are not groups |
| 173 | 173 | unset( $groups[ 'override' ], $groups[ 'override-perm' ] ); |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @param array[] $extra |
| 188 | 188 | * @return array[] |
| 189 | 189 | */ |
| 190 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 190 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 191 | 191 | $newContent = $this->botList; |
| 192 | 192 | foreach ( $newContent as $user => $groups ) { |
| 193 | 193 | if ( isset( $missing[ $user ] ) ) { |
@@ -211,20 +211,20 @@ discard block |
||
| 211 | 211 | * @param array[] $newContent |
| 212 | 212 | * @return array[] |
| 213 | 213 | */ |
| 214 | - protected function removeOverrides( array $newContent ) : array { |
|
| 215 | - $removed = []; |
|
| 214 | + protected function removeOverrides ( array $newContent ) : array { |
|
| 215 | + $removed = [ ]; |
|
| 216 | 216 | foreach ( $newContent as $user => $groups ) { |
| 217 | - if ( !isset( $groups['override'] ) ) { |
|
| 217 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
| 218 | 218 | continue; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | $flagTS = PageBotList::getValidFlagTimestamp( $groups ); |
| 222 | 222 | $usualTS = strtotime( date( 'd/m', $flagTS ) . date( 'Y' ) ); |
| 223 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
| 223 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
| 224 | 224 | |
| 225 | - if ( time() > $usualTS && time () > $overrideTS ) { |
|
| 225 | + if ( time() > $usualTS && time() > $overrideTS ) { |
|
| 226 | 226 | unset( $newContent[ $user ][ 'override' ] ); |
| 227 | - $removed[] = $user; |
|
| 227 | + $removed[ ] = $user; |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |