@@ -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 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | /** |
| 17 | 17 | * @inheritDoc |
| 18 | 18 | */ |
| 19 | - public function runInternal() : int { |
|
| 19 | + public function runInternal () : int { |
|
| 20 | 20 | $pages = $this->getDataProvider()->getPagesToClose(); |
| 21 | 21 | |
| 22 | 22 | if ( !$pages ) { |
@@ -38,15 +38,15 @@ discard block |
||
| 38 | 38 | * @param PageRiconferma[] $pages |
| 39 | 39 | * @see OpenUpdates::addToVotazioni() |
| 40 | 40 | */ |
| 41 | - protected function updateVotazioni( array $pages ) { |
|
| 41 | + protected function updateVotazioni ( array $pages ) { |
|
| 42 | 42 | $this->getLogger()->info( |
| 43 | 43 | 'Updating votazioni: ' . implode( ', ', $pages ) |
| 44 | 44 | ); |
| 45 | 45 | $votePage = $this->getPage( $this->getOpt( 'vote-page-title' ) ); |
| 46 | 46 | |
| 47 | - $users = []; |
|
| 47 | + $users = [ ]; |
|
| 48 | 48 | foreach ( $pages as $page ) { |
| 49 | - $users[] = $page->getUser(); |
|
| 49 | + $users[ ] = $page->getUser(); |
|
| 50 | 50 | } |
| 51 | 51 | $usersReg = Element::regexFromArray( $users ); |
| 52 | 52 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param array $pages |
| 68 | 68 | * @see OpenUpdates::addToNews() |
| 69 | 69 | */ |
| 70 | - protected function updateNews( array $pages ) { |
|
| 70 | + protected function updateNews ( array $pages ) { |
|
| 71 | 71 | $simpleAmount = $voteAmount = 0; |
| 72 | 72 | foreach ( $pages as $page ) { |
| 73 | 73 | if ( $page->isVote() ) { |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | $simpleMatches = $newsPage->getMatch( $simpleReg ); |
| 88 | 88 | $voteMatches = $newsPage->getMatch( $voteReg ); |
| 89 | 89 | |
| 90 | - $newSimp = (int)$simpleMatches[2] - $simpleAmount ?: ''; |
|
| 91 | - $newVote = (int)$voteMatches[2] - $voteAmount ?: ''; |
|
| 90 | + $newSimp = (int)$simpleMatches[ 2 ] - $simpleAmount ?: ''; |
|
| 91 | + $newVote = (int)$voteMatches[ 2 ] - $voteAmount ?: ''; |
|
| 92 | 92 | $newContent = preg_replace( $simpleReg, '${1}' . $newSimp, $newsPage->getContent() ); |
| 93 | 93 | $newContent = preg_replace( $voteReg, '${1}' . $newVote, $newContent ); |
| 94 | 94 | |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @param bool[] $outcomes |
| 108 | 108 | */ |
| 109 | - protected function updateAdminList( array $outcomes ) { |
|
| 109 | + protected function updateAdminList ( array $outcomes ) { |
|
| 110 | 110 | $this->getLogger()->info( 'Updating admin list' ); |
| 111 | 111 | $adminsPage = $this->getPage( $this->getOpt( 'admins-list-title' ) ); |
| 112 | 112 | $newContent = $adminsPage->getContent(); |
| 113 | 113 | |
| 114 | - $riconfNames = $removeNames = []; |
|
| 114 | + $riconfNames = $removeNames = [ ]; |
|
| 115 | 115 | foreach ( $outcomes as $username => $confirmed ) { |
| 116 | 116 | $user = new User( $username, $this->getWiki() ); |
| 117 | 117 | $userReg = $user->getRegex(); |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | '${1}' . date( 'Ymd' ) . '|' . $nextDate . '$2', |
| 124 | 124 | $newContent |
| 125 | 125 | ); |
| 126 | - $riconfNames[] = $username; |
|
| 126 | + $riconfNames[ ] = $username; |
|
| 127 | 127 | } else { |
| 128 | 128 | $newContent = preg_replace( $reg, '', $newContent ); |
| 129 | - $removeNames[] = $username; |
|
| 129 | + $removeNames[ ] = $username; |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | * @param User $user |
| 150 | 150 | * @return int |
| 151 | 151 | */ |
| 152 | - private function getNextTs( User $user ) : int { |
|
| 152 | + private function getNextTs ( User $user ) : int { |
|
| 153 | 153 | $userInfo = $user->getUserInfo(); |
| 154 | - if ( isset( $userInfo['override-perm'] ) ) { |
|
| 154 | + if ( isset( $userInfo[ 'override-perm' ] ) ) { |
|
| 155 | 155 | $date = \DateTime::createFromFormat( |
| 156 | 156 | 'd/m/Y', |
| 157 | - $userInfo['override-perm'] . '/' . date( 'Y' ) |
|
| 157 | + $userInfo[ 'override-perm' ] . '/' . date( 'Y' ) |
|
| 158 | 158 | ); |
| 159 | 159 | if ( $date < new \DateTime ) { |
| 160 | 160 | $date->modify( '+1 year' ); |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | } else { |
| 164 | 164 | $ts = PageBotList::getValidFlagTimestamp( $userInfo ); |
| 165 | 165 | $res = strtotime( date( 'Y', strtotime( '+1 year' ) ) . date( '-m-d', $ts ) ); |
| 166 | - if ( isset( $userInfo['override'] ) ) { |
|
| 167 | - $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo['override'] ); |
|
| 166 | + if ( isset( $userInfo[ 'override' ] ) ) { |
|
| 167 | + $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo[ 'override' ] ); |
|
| 168 | 168 | if ( $date > new \DateTime ) { |
| 169 | 169 | $res = $date->getTimestamp(); |
| 170 | 170 | } |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | /** |
| 177 | 177 | * @param bool[] $outcomes |
| 178 | 178 | */ |
| 179 | - protected function updateCUList( array $outcomes ) { |
|
| 179 | + protected function updateCUList ( array $outcomes ) { |
|
| 180 | 180 | $this->getLogger()->info( 'Updating CU list.' ); |
| 181 | 181 | $cuList = $this->getPage( $this->getOpt( 'cu-list-title' ) ); |
| 182 | 182 | $newContent = $cuList->getContent(); |
| 183 | 183 | |
| 184 | - $riconfNames = $removeNames = []; |
|
| 184 | + $riconfNames = $removeNames = [ ]; |
|
| 185 | 185 | foreach ( $outcomes as $user => $confirmed ) { |
| 186 | 186 | $userReg = ( new User( $user, $this->getWiki() ) )->getRegex(); |
| 187 | 187 | $reg = "!(\{\{ *Checkuser *\| *$userReg *\|[^}]+\| *)[\w \d]+(}}.*\n)!"; |
| 188 | 188 | if ( $confirmed ) { |
| 189 | 189 | $newContent = preg_replace( $reg, '${1}{{subst:#time:j F Y}}$2', $newContent ); |
| 190 | - $riconfNames[] = $user; |
|
| 190 | + $riconfNames[ ] = $user; |
|
| 191 | 191 | } else { |
| 192 | 192 | $newContent = preg_replace( $reg, '', $newContent ); |
| 193 | - $removeNames[] = $user; |
|
| 193 | + $removeNames[ ] = $user; |
|
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | |
@@ -214,8 +214,8 @@ discard block |
||
| 214 | 214 | * @param PageRiconferma[] $pages |
| 215 | 215 | * @return bool[] |
| 216 | 216 | */ |
| 217 | - private function getGroupOutcomes( string $group, array $pages ) : array { |
|
| 218 | - $ret = []; |
|
| 217 | + private function getGroupOutcomes ( string $group, array $pages ) : array { |
|
| 218 | + $ret = [ ]; |
|
| 219 | 219 | foreach ( $pages as $page ) { |
| 220 | 220 | $user = $page->getUser(); |
| 221 | 221 | 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\Wiki; |
| 4 | 4 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param LoggerInterface $logger |
| 29 | 29 | * @param string $domain The URL of the wiki, if different from default |
| 30 | 30 | */ |
| 31 | - public function __construct( LoggerInterface $logger, string $domain = DEFAULT_URL ) { |
|
| 31 | + public function __construct ( LoggerInterface $logger, string $domain = DEFAULT_URL ) { |
|
| 32 | 32 | $this->logger = $logger; |
| 33 | 33 | $this->domain = $domain; |
| 34 | 34 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @throws MissingPageException |
| 43 | 43 | * @throws MissingSectionException |
| 44 | 44 | */ |
| 45 | - public function getPageContent( string $title, int $section = null ) : string { |
|
| 45 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
| 46 | 46 | $msg = "Retrieving content of $title" . ( $section !== null ? ", section $section" : '' ); |
| 47 | 47 | $this->logger->debug( $msg ); |
| 48 | 48 | $params = [ |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | ]; |
| 55 | 55 | |
| 56 | 56 | if ( $section !== null ) { |
| 57 | - $params['rvsection'] = $section; |
|
| 57 | + $params[ 'rvsection' ] = $section; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $req = $this->buildRequest( $params ); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | throw new MissingPageException( $title ); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $mainSlot = $page->revisions[0]->slots->main; |
|
| 67 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
| 68 | 68 | |
| 69 | 69 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
| 70 | 70 | throw new MissingSectionException( $title, $section ); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @param array $params |
| 79 | 79 | * @throws EditException |
| 80 | 80 | */ |
| 81 | - public function editPage( array $params ) { |
|
| 81 | + public function editPage ( array $params ) { |
|
| 82 | 82 | $this->login(); |
| 83 | 83 | |
| 84 | 84 | $params = [ |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | ] + $params; |
| 88 | 88 | |
| 89 | 89 | if ( Config::getInstance()->get( 'bot-edits' ) ) { |
| 90 | - $params['bot'] = 1; |
|
| 90 | + $params[ 'bot' ] = 1; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $res = $this->buildRequest( $params )->setPost()->execute(); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
| 106 | 106 | * @throws LoginException |
| 107 | 107 | */ |
| 108 | - public function login() { |
|
| 108 | + public function login () { |
|
| 109 | 109 | if ( self::$loggedIn ) { |
| 110 | 110 | return; |
| 111 | 111 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | self::$loggedIn = true; |
| 134 | 134 | // Clear tokens cache |
| 135 | - $this->tokens = []; |
|
| 135 | + $this->tokens = [ ]; |
|
| 136 | 136 | $this->logger->info( 'Login succeeded' ); |
| 137 | 137 | } |
| 138 | 138 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param string $type |
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | - public function getToken( string $type ) : string { |
|
| 145 | + public function getToken ( string $type ) : string { |
|
| 146 | 146 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 147 | 147 | $params = [ |
| 148 | 148 | 'action' => 'query', |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @param string $title |
| 166 | 166 | * @return int |
| 167 | 167 | */ |
| 168 | - public function getPageCreationTS( string $title ) : int { |
|
| 168 | + public function getPageCreationTS ( string $title ) : int { |
|
| 169 | 169 | $params = [ |
| 170 | 170 | 'action' => 'query', |
| 171 | 171 | 'prop' => 'revisions', |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | $res = $this->buildRequest( $params )->execute(); |
| 180 | 180 | $data = $res->query->pages; |
| 181 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
| 181 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @param string $title |
| 188 | 188 | * @param string $reason |
| 189 | 189 | */ |
| 190 | - public function protectPage( string $title, string $reason ) { |
|
| 190 | + public function protectPage ( string $title, string $reason ) { |
|
| 191 | 191 | $this->logger->info( "Protecting page $title" ); |
| 192 | 192 | $this->login(); |
| 193 | 193 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @param array $params |
| 209 | 209 | * @return RequestBase |
| 210 | 210 | */ |
| 211 | - private function buildRequest( array $params ) : RequestBase { |
|
| 211 | + private function buildRequest ( array $params ) : RequestBase { |
|
| 212 | 212 | return RequestBase::newFromParams( $params )->setUrl( $this->domain ); |
| 213 | 213 | } |
| 214 | 214 | } |
@@ -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 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * @inheritDoc |
| 17 | 17 | */ |
| 18 | - public function runInternal() : int { |
|
| 18 | + public function runInternal () : int { |
|
| 19 | 19 | $users = $this->getDataProvider()->getUsersToProcess(); |
| 20 | 20 | |
| 21 | 21 | if ( !$users ) { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @param string $user |
| 36 | 36 | * @param array $groups |
| 37 | 37 | */ |
| 38 | - protected function processUser( string $user, array $groups ) { |
|
| 38 | + protected function processUser ( string $user, array $groups ) { |
|
| 39 | 39 | try { |
| 40 | 40 | $num = $this->getLastPageNum( $user ) + 1; |
| 41 | 41 | } catch ( TaskException $e ) { |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return int |
| 68 | 68 | * @throws TaskException |
| 69 | 69 | */ |
| 70 | - protected function getLastPageNum( string $user ) : int { |
|
| 70 | + protected function getLastPageNum ( string $user ) : int { |
|
| 71 | 71 | $this->getLogger()->debug( "Retrieving previous pages for $user" ); |
| 72 | 72 | $userObj = new User( $user, $this->getWiki() ); |
| 73 | 73 | |
| 74 | - $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[1]; |
|
| 74 | + $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[ 1 ]; |
|
| 75 | 75 | |
| 76 | 76 | $prefixes = [ "$unprefixedTitle/$user/" ]; |
| 77 | 77 | foreach ( $userObj->getAliases() as $alias ) { |
| 78 | - $prefixes[] = "$unprefixedTitle/$alias/"; |
|
| 78 | + $prefixes[ ] = "$unprefixedTitle/$alias/"; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $params = [ |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | * @param string $user |
| 113 | 113 | * @param array $groups |
| 114 | 114 | */ |
| 115 | - protected function createPage( string $title, string $user, array $groups ) { |
|
| 115 | + protected function createPage ( string $title, string $user, array $groups ) { |
|
| 116 | 116 | $this->getLogger()->info( "Creating page $title" ); |
| 117 | 117 | $textParams = [ |
| 118 | 118 | '$user' => $user, |
| 119 | - '$date' => $groups['sysop'], |
|
| 120 | - '$burocrate' => $groups['bureaucrat'] ?? '', |
|
| 121 | - '$checkuser' => $groups['checkuser'] ?? '' |
|
| 119 | + '$date' => $groups[ 'sysop' ], |
|
| 120 | + '$burocrate' => $groups[ 'bureaucrat' ] ?? '', |
|
| 121 | + '$checkuser' => $groups[ 'checkuser' ] ?? '' |
|
| 122 | 122 | ]; |
| 123 | 123 | |
| 124 | 124 | $params = [ |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @param string $title |
| 137 | 137 | * @param string $newText |
| 138 | 138 | */ |
| 139 | - protected function createBasePage( string $title, string $newText ) { |
|
| 139 | + protected function createBasePage ( string $title, string $newText ) { |
|
| 140 | 140 | $this->getLogger()->info( "Creating base page $title" ); |
| 141 | 141 | |
| 142 | 142 | $params = [ |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param string $title |
| 154 | 154 | * @param string $newText |
| 155 | 155 | */ |
| 156 | - protected function updateBasePage( string $title, string $newText ) { |
|
| 156 | + protected function updateBasePage ( string $title, string $newText ) { |
|
| 157 | 157 | $this->getLogger()->info( "Updating base page $title" ); |
| 158 | 158 | |
| 159 | 159 | $params = [ |
@@ -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_diff( array_keys( $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,9 +66,9 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @inheritDoc |
| 68 | 68 | */ |
| 69 | - public function getRegex() : string { |
|
| 69 | + public function getRegex () : string { |
|
| 70 | 70 | $bits = $this->getAliases(); |
| 71 | - $bits[] = $this->name; |
|
| 71 | + $bits[ ] = $this->name; |
|
| 72 | 72 | $regexify = function ( $el ) { |
| 73 | 73 | return str_replace( ' ', '[ _]', preg_quote( $el ) ); |
| 74 | 74 | }; |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return string[] |
| 82 | 82 | */ |
| 83 | - public function getAliases() : array { |
|
| 84 | - return $this->getUserInfo()['aliases'] ?? []; |
|
| 83 | + public function getAliases () : array { |
|
| 84 | + return $this->getUserInfo()[ 'aliases' ] ?? [ ]; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * @return string |
| 89 | 89 | */ |
| 90 | - public function __toString() { |
|
| 90 | + public function __toString () { |
|
| 91 | 91 | return $this->name; |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -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 | |
| 195 | 195 | $titles = array_map( function ( $x ) { |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | ]; |
| 207 | 207 | |
| 208 | 208 | $data = RequestBase::newFromParams( $params )->execute(); |
| 209 | - $ret = []; |
|
| 209 | + $ret = [ ]; |
|
| 210 | 210 | foreach ( $data->query->logevents as $entry ) { |
| 211 | 211 | $time = strtotime( $entry->timestamp ); |
| 212 | 212 | // 1 month is arbitrary |
@@ -225,10 +225,10 @@ discard block |
||
| 225 | 225 | * @param array[] $extra |
| 226 | 226 | * @return array[] |
| 227 | 227 | */ |
| 228 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 228 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 229 | 229 | $newContent = $this->botList; |
| 230 | 230 | $renameMap = $this->checkRenamedUsers( array_keys( $extra ) ); |
| 231 | - $removed = []; |
|
| 231 | + $removed = [ ]; |
|
| 232 | 232 | foreach ( $newContent as $user => $groups ) { |
| 233 | 233 | if ( isset( $missing[ $user ] ) ) { |
| 234 | 234 | $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | if ( array_diff_key( $newGroups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ) ) { |
| 239 | 239 | $newContent[ $user ] = $newGroups; |
| 240 | 240 | } else { |
| 241 | - $removed[$user] = $newContent[$user]; |
|
| 241 | + $removed[ $user ] = $newContent[ $user ]; |
|
| 242 | 242 | unset( $newContent[ $user ] ); |
| 243 | 243 | } |
| 244 | 244 | } |
@@ -249,16 +249,16 @@ discard block |
||
| 249 | 249 | foreach ( $removed as $oldName => $info ) { |
| 250 | 250 | if ( |
| 251 | 251 | array_key_exists( $oldName, $renameMap ) && |
| 252 | - array_key_exists( $renameMap[$oldName], $newContent ) |
|
| 252 | + array_key_exists( $renameMap[ $oldName ], $newContent ) |
|
| 253 | 253 | ) { |
| 254 | 254 | // This user was renamed! Add this name as alias, if they're still listed |
| 255 | 255 | $newName = $renameMap[ $oldName ]; |
| 256 | 256 | if ( array_key_exists( 'aliases', $newContent[ $newName ] ) ) { |
| 257 | - if ( !in_array( $oldName, $newContent[ $newName ]['aliases'] ) ) { |
|
| 258 | - $newContent[ $newName ]['aliases'][] = $oldName; |
|
| 257 | + if ( !in_array( $oldName, $newContent[ $newName ][ 'aliases' ] ) ) { |
|
| 258 | + $newContent[ $newName ][ 'aliases' ][ ] = $oldName; |
|
| 259 | 259 | } |
| 260 | 260 | } else { |
| 261 | - $newContent[ $newName ]['aliases'] = [ $oldName ]; |
|
| 261 | + $newContent[ $newName ][ 'aliases' ] = [ $oldName ]; |
|
| 262 | 262 | } |
| 263 | 263 | // Transfer overrides to the new name. |
| 264 | 264 | $overrides = array_diff_key( $info, [ 'override' => 1, 'override-perm' => 1 ] ); |
@@ -278,21 +278,21 @@ discard block |
||
| 278 | 278 | * @param array[] $newContent |
| 279 | 279 | * @return array[] |
| 280 | 280 | */ |
| 281 | - protected function removeOverrides( array $newContent ) : array { |
|
| 282 | - $removed = []; |
|
| 281 | + protected function removeOverrides ( array $newContent ) : array { |
|
| 282 | + $removed = [ ]; |
|
| 283 | 283 | foreach ( $newContent as $user => $groups ) { |
| 284 | - if ( !isset( $groups['override'] ) ) { |
|
| 284 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
| 285 | 285 | continue; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | $flagTS = PageBotList::getValidFlagTimestamp( $groups ); |
| 289 | 289 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); |
| 290 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
| 290 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
| 291 | 291 | $delay = 60 * 60 * 24 * 3; |
| 292 | 292 | |
| 293 | 293 | if ( time() > $usualTS + $delay && time() > $overrideTS + $delay ) { |
| 294 | 294 | unset( $newContent[ $user ][ 'override' ] ); |
| 295 | - $removed[] = $user; |
|
| 295 | + $removed[ ] = $user; |
|
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Logger; |
| 4 | 4 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * @param Page $logPage |
| 27 | 27 | * @param string $minlevel |
| 28 | 28 | */ |
| 29 | - public function __construct( Page $logPage, $minlevel = LogLevel::INFO ) { |
|
| 29 | + public function __construct ( Page $logPage, $minlevel = LogLevel::INFO ) { |
|
| 30 | 30 | $this->minLevel = $this->levelToInt( $minlevel ); |
| 31 | 31 | $this->logPage = $logPage; |
| 32 | 32 | } |
@@ -35,16 +35,16 @@ discard block |
||
| 35 | 35 | * @inheritDoc |
| 36 | 36 | * @suppress PhanUnusedPublicMethodParameter |
| 37 | 37 | */ |
| 38 | - public function log( $level, $message, array $context = [] ) { |
|
| 38 | + public function log ( $level, $message, array $context = [ ] ) { |
|
| 39 | 39 | if ( $this->levelToInt( $level ) >= $this->minLevel ) { |
| 40 | - $this->buffer[] = $this->getFormattedMessage( $level, $message ); |
|
| 40 | + $this->buffer[ ] = $this->getFormattedMessage( $level, $message ); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * @return string |
| 46 | 46 | */ |
| 47 | - protected function getOutput() : string { |
|
| 47 | + protected function getOutput () : string { |
|
| 48 | 48 | $line = str_repeat( '-', 80 ); |
| 49 | 49 | return "\n\n" . implode( "\n", $this->buffer ) . "\n$line\n\n"; |
| 50 | 50 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * @inheritDoc |
| 54 | 54 | */ |
| 55 | - public function flush() : void { |
|
| 55 | + public function flush () : void { |
|
| 56 | 56 | if ( $this->buffer ) { |
| 57 | 57 | $this->logPage->edit( [ |
| 58 | 58 | 'appendtext' => $this->getOutput(), |