@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | /** |
| 3 | 3 | * Entry point for the bot, called by CLI |
| 4 | 4 | */ |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | /* URL (for debugging purpose) */ |
| 41 | 41 | $urlParam = getopt( '', [ 'force-url:' ] ); |
| 42 | -$url = $urlParam['force-url'] ?? 'https://it.wikipedia.org/w/api.php'; |
|
| 42 | +$url = $urlParam[ 'force-url' ] ?? 'https://it.wikipedia.org/w/api.php'; |
|
| 43 | 43 | |
| 44 | 44 | define( 'DEFAULT_URL', $url ); |
| 45 | 45 | define( 'META_URL', 'https://meta.wikimedia.org/w/api.php' ); |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | if ( count( $taskOpts ) === 2 ) { |
| 95 | 95 | throw new InvalidArgumentException( 'Cannot specify both task and subtask.' ); |
| 96 | -} elseif ( isset( $taskOpts['task'] ) ) { |
|
| 96 | +} elseif ( isset( $taskOpts[ 'task' ] ) ) { |
|
| 97 | 97 | $bot->runTask( $taskOpts[ 'task' ] ); |
| 98 | -} elseif ( isset( $taskOpts['subtask'] ) ) { |
|
| 98 | +} elseif ( isset( $taskOpts[ 'subtask' ] ) ) { |
|
| 99 | 99 | $bot->runSubtask( $taskOpts[ 'subtask' ] ); |
| 100 | 100 | } else { |
| 101 | 101 | $bot->runAll(); |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme; |
| 4 | 4 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** @var Controller */ |
| 21 | 21 | private $controller; |
| 22 | 22 | |
| 23 | - public function __construct( Logger $logger, Controller $controller ) { |
|
| 23 | + public function __construct ( Logger $logger, Controller $controller ) { |
|
| 24 | 24 | $this->setLogger( $logger ); |
| 25 | 25 | $this->setConfig( Config::getInstance() ); |
| 26 | 26 | $this->setController( $controller ); |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * @return LoggerInterface |
| 31 | 31 | */ |
| 32 | - protected function getLogger() : LoggerInterface { |
|
| 32 | + protected function getLogger () : LoggerInterface { |
|
| 33 | 33 | return $this->logger; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * @inheritDoc |
| 38 | 38 | */ |
| 39 | - public function setLogger( LoggerInterface $logger ) { |
|
| 39 | + public function setLogger ( LoggerInterface $logger ) { |
|
| 40 | 40 | $this->logger = $logger; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -46,35 +46,35 @@ discard block |
||
| 46 | 46 | * @param string $optname |
| 47 | 47 | * @return mixed |
| 48 | 48 | */ |
| 49 | - protected function getOpt( string $optname ) { |
|
| 49 | + protected function getOpt ( string $optname ) { |
|
| 50 | 50 | return $this->getConfig()->get( $optname ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @return Config |
| 55 | 55 | */ |
| 56 | - protected function getConfig() : Config { |
|
| 56 | + protected function getConfig () : Config { |
|
| 57 | 57 | return $this->config; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @param Config $cfg |
| 62 | 62 | */ |
| 63 | - protected function setConfig( Config $cfg ) { |
|
| 63 | + protected function setConfig ( Config $cfg ) { |
|
| 64 | 64 | $this->config = $cfg; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @return Controller |
| 69 | 69 | */ |
| 70 | - protected function getController() : Controller { |
|
| 70 | + protected function getController () : Controller { |
|
| 71 | 71 | return $this->controller; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * @param Controller $controller |
| 76 | 76 | */ |
| 77 | - protected function setController( Controller $controller ) { |
|
| 77 | + protected function setController ( Controller $controller ) { |
|
| 78 | 78 | $this->controller = $controller; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param string $key |
| 85 | 85 | * @return Message |
| 86 | 86 | */ |
| 87 | - protected function msg( string $key ) : Message { |
|
| 87 | + protected function msg ( string $key ) : Message { |
|
| 88 | 88 | return new Message( $key ); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @param string $title |
| 95 | 95 | * @return Page |
| 96 | 96 | */ |
| 97 | - protected function getPage( string $title ) : Page { |
|
| 97 | + protected function getPage ( string $title ) : Page { |
|
| 98 | 98 | return new Page( $title, $this->getController() ); |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * @inheritDoc |
| 15 | 15 | */ |
| 16 | - public function runInternal() : int { |
|
| 16 | + public function runInternal () : int { |
|
| 17 | 17 | $pages = $this->getDataProvider()->getCreatedPages(); |
| 18 | 18 | |
| 19 | 19 | if ( !$pages ) { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @param PageRiconferma[] $pages |
| 37 | 37 | */ |
| 38 | - protected function addToMainPage( array $pages ) { |
|
| 38 | + protected function addToMainPage ( array $pages ) { |
|
| 39 | 39 | $this->getLogger()->info( |
| 40 | 40 | 'Adding the following to main: ' . implode( ', ', $pages ) |
| 41 | 41 | ); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @param PageRiconferma[] $pages |
| 70 | 70 | */ |
| 71 | - protected function addToVotazioni( array $pages ) { |
|
| 71 | + protected function addToVotazioni ( array $pages ) { |
|
| 72 | 72 | $this->getLogger()->info( |
| 73 | 73 | 'Adding the following to votes: ' . implode( ', ', $pages ) |
| 74 | 74 | ); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param int $amount |
| 106 | 106 | * @throws TaskException |
| 107 | 107 | */ |
| 108 | - protected function addToNews( int $amount ) { |
|
| 108 | + protected function addToNews ( int $amount ) { |
|
| 109 | 109 | $this->getLogger()->info( "Increasing the news counter by $amount" ); |
| 110 | 110 | $newsPage = $this->getPage( $this->getOpt( 'news-page-title' ) ); |
| 111 | 111 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | throw new TaskException( 'Param not found in news page' ); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $newNum = (int)$matches[2] + $amount; |
|
| 121 | + $newNum = (int)$matches[ 2 ] + $amount; |
|
| 122 | 122 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
| 123 | 123 | |
| 124 | 124 | $summary = $this->msg( 'news-page-summary' ) |
@@ -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->getController() ); |
| 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 | $groups = $user->getGroupsWithDates(); |
| 154 | - if ( isset( $groups['override-perm'] ) ) { |
|
| 154 | + if ( isset( $groups[ 'override-perm' ] ) ) { |
|
| 155 | 155 | $date = \DateTime::createFromFormat( |
| 156 | 156 | 'd/m/Y', |
| 157 | - $groups['override-perm'] . '/' . date( 'Y' ) |
|
| 157 | + $groups[ '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( $groups ); |
| 165 | 165 | $res = strtotime( date( 'Y', strtotime( '+1 year' ) ) . date( '-m-d', $ts ) ); |
| 166 | - if ( isset( $groups['override'] ) ) { |
|
| 167 | - $date = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] ); |
|
| 166 | + if ( isset( $groups[ 'override' ] ) ) { |
|
| 167 | + $date = \DateTime::createFromFormat( 'd/m/Y', $groups[ '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->getController() ) )->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\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 | $failed = $this->getFailures(); |
| 21 | 21 | if ( !$failed ) { |
| 22 | 22 | return TaskResult::STATUS_NOTHING; |
@@ -38,12 +38,12 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return PageRiconferma[] |
| 40 | 40 | */ |
| 41 | - private function getFailures() : array { |
|
| 42 | - $ret = []; |
|
| 41 | + private function getFailures () : array { |
|
| 42 | + $ret = [ ]; |
|
| 43 | 43 | $allPages = $this->getDataProvider()->getPagesToClose(); |
| 44 | 44 | foreach ( $allPages as $page ) { |
| 45 | 45 | if ( $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ) { |
| 46 | - $ret[] = $page; |
|
| 46 | + $ret[ ] = $page; |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | return $ret; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * @param User[] $users |
| 54 | 54 | */ |
| 55 | - protected function updateBurList( array $users ) { |
|
| 55 | + protected function updateBurList ( array $users ) { |
|
| 56 | 56 | $this->getLogger()->info( 'Updating bur list. Removing: ' . implode( ', ', $users ) ); |
| 57 | 57 | $remList = Element::regexFromArray( $users ); |
| 58 | 58 | $burList = $this->getPage( $this->getOpt( 'bur-list-title' ) ); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @param PageRiconferma[] $pages |
| 77 | 77 | */ |
| 78 | - protected function requestRemoval( array $pages ) { |
|
| 78 | + protected function requestRemoval ( array $pages ) { |
|
| 79 | 79 | $this->getLogger()->info( 'Requesting flag removal for: ' . implode( ', ', $pages ) ); |
| 80 | 80 | |
| 81 | 81 | $metaController = $this->getController()->cloneWithDomain( META_URL ); |
@@ -112,15 +112,15 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @param PageRiconferma[] $pages |
| 114 | 114 | */ |
| 115 | - protected function updateAnnunci( array $pages ) { |
|
| 115 | + protected function updateAnnunci ( array $pages ) { |
|
| 116 | 116 | $this->getLogger()->info( 'Updating annunci' ); |
| 117 | 117 | $section = 1; |
| 118 | 118 | |
| 119 | - $names = []; |
|
| 119 | + $names = [ ]; |
|
| 120 | 120 | $text = ''; |
| 121 | 121 | foreach ( $pages as $page ) { |
| 122 | 122 | $user = $page->getUser()->getName(); |
| 123 | - $names[] = $user; |
|
| 123 | + $names[ ] = $user; |
|
| 124 | 124 | $text .= $this->msg( 'annunci-text' )->params( [ '$user' => $user ] )->text(); |
| 125 | 125 | } |
| 126 | 126 | |
@@ -152,16 +152,16 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @param PageRiconferma[] $pages |
| 154 | 154 | */ |
| 155 | - protected function updateUltimeNotizie( array $pages ) { |
|
| 155 | + protected function updateUltimeNotizie ( array $pages ) { |
|
| 156 | 156 | $this->getLogger()->info( 'Updating ultime notizie' ); |
| 157 | 157 | $notiziePage = $this->getPage( $this->getOpt( 'ultimenotizie-page-title' ) ); |
| 158 | 158 | |
| 159 | - $names = []; |
|
| 159 | + $names = [ ]; |
|
| 160 | 160 | $text = ''; |
| 161 | 161 | $msg = $this->msg( 'ultimenotizie-text' ); |
| 162 | 162 | foreach ( $pages as $page ) { |
| 163 | 163 | $user = $page->getUser()->getName(); |
| 164 | - $names[] = $user; |
|
| 164 | + $names[ ] = $user; |
|
| 165 | 165 | $text .= $msg->params( [ '$user' => $user, '$title' => $page->getTitle() ] )->text(); |
| 166 | 166 | } |
| 167 | 167 | |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | * @param PageRiconferma[] $pages |
| 191 | 191 | * @return User[] |
| 192 | 192 | */ |
| 193 | - private function getFailedBureaucrats( array $pages ) : array { |
|
| 194 | - $ret = []; |
|
| 193 | + private function getFailedBureaucrats ( array $pages ) : array { |
|
| 194 | + $ret = [ ]; |
|
| 195 | 195 | foreach ( $pages as $page ) { |
| 196 | 196 | $user = $page->getUser(); |
| 197 | 197 | if ( $user->inGroup( 'bureaucrat' ) ) { |
| 198 | - $ret[] = $user; |
|
| 198 | + $ret[ ] = $user; |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | return $ret; |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * @inheritDoc |
| 15 | 15 | */ |
| 16 | - public function runInternal() : int { |
|
| 16 | + public function runInternal () : int { |
|
| 17 | 17 | $pages = $this->getDataProvider()->getPagesToClose(); |
| 18 | 18 | |
| 19 | 19 | if ( !$pages ) { |
@@ -32,18 +32,18 @@ discard block |
||
| 32 | 32 | * @param PageRiconferma[] $pages |
| 33 | 33 | * @see OpenUpdates::addToMainPage() |
| 34 | 34 | */ |
| 35 | - protected function removeFromMainPage( array $pages ) { |
|
| 35 | + protected function removeFromMainPage ( array $pages ) { |
|
| 36 | 36 | $this->getLogger()->info( |
| 37 | 37 | 'Removing from main: ' . implode( ', ', $pages ) |
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | 40 | $mainPage = $this->getPage( $this->getOpt( 'main-page-title' ) ); |
| 41 | - $remove = []; |
|
| 41 | + $remove = [ ]; |
|
| 42 | 42 | foreach ( $pages as $page ) { |
| 43 | 43 | // Order matters here. It's not guaranteed that there'll be a newline, but avoid |
| 44 | 44 | // regexps for that single character. |
| 45 | - $remove[] = '{{' . $page->getTitle() . "}}\n"; |
|
| 46 | - $remove[] = '{{' . $page->getTitle() . '}}'; |
|
| 45 | + $remove[ ] = '{{' . $page->getTitle() . "}}\n"; |
|
| 46 | + $remove[ ] = '{{' . $page->getTitle() . '}}'; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $newContent = str_replace( $remove, '', $mainPage->getContent() ); |
@@ -72,17 +72,17 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param PageRiconferma[] $pages |
| 74 | 74 | */ |
| 75 | - protected function addToArchive( array $pages ) { |
|
| 75 | + protected function addToArchive ( array $pages ) { |
|
| 76 | 76 | $this->getLogger()->info( |
| 77 | 77 | 'Adding to archive: ' . implode( ', ', $pages ) |
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | - $simple = $votes = []; |
|
| 80 | + $simple = $votes = [ ]; |
|
| 81 | 81 | foreach ( $pages as $page ) { |
| 82 | 82 | if ( $page->isVote() ) { |
| 83 | - $votes[] = $page; |
|
| 83 | + $votes[ ] = $page; |
|
| 84 | 84 | } else { |
| 85 | - $simple[] = $page; |
|
| 85 | + $simple[ ] = $page; |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
@@ -103,15 +103,15 @@ discard block |
||
| 103 | 103 | * @param string $archiveTitle |
| 104 | 104 | * @param array $pages |
| 105 | 105 | */ |
| 106 | - private function reallyAddToArchive( string $archiveTitle, array $pages ) { |
|
| 106 | + private function reallyAddToArchive ( string $archiveTitle, array $pages ) { |
|
| 107 | 107 | $archivePage = $this->getPage( "$archiveTitle/" . date( 'Y' ) ); |
| 108 | 108 | $exists = $archivePage->exists(); |
| 109 | 109 | |
| 110 | 110 | $append = "\n"; |
| 111 | - $archivedList = []; |
|
| 111 | + $archivedList = [ ]; |
|
| 112 | 112 | foreach ( $pages as $page ) { |
| 113 | 113 | $append .= '{{' . $page->getTitle() . "}}\n"; |
| 114 | - $archivedList[] = $page->getUserNum(); |
|
| 114 | + $archivedList[ ] = $page->getUserNum(); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $summary = $this->msg( 'close-archive-summary' ) |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @param string $archiveTitle |
| 134 | 134 | */ |
| 135 | - private function addArchiveYear( string $archiveTitle ) { |
|
| 135 | + private function addArchiveYear ( string $archiveTitle ) { |
|
| 136 | 136 | $page = $this->getPage( $archiveTitle ); |
| 137 | 137 | $year = date( 'Y' ); |
| 138 | 138 | |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * @inheritDoc |
| 15 | 15 | */ |
| 16 | - public function runInternal() : int { |
|
| 16 | + public function runInternal () : int { |
|
| 17 | 17 | $pages = $this->getDataProvider()->getPagesToClose(); |
| 18 | 18 | |
| 19 | 19 | if ( !$pages ) { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * @param PageRiconferma $page |
| 37 | 37 | */ |
| 38 | - protected function addVoteCloseText( PageRiconferma $page ) { |
|
| 38 | + protected function addVoteCloseText ( PageRiconferma $page ) { |
|
| 39 | 39 | $content = $page->getContent(); |
| 40 | 40 | $beforeReg = '!è necessario ottenere una maggioranza .+ votanti\.!'; |
| 41 | 41 | $newContent = preg_replace( $beforeReg, '$0' . "\n" . $page->getOutcomeText(), $content ); |
@@ -50,15 +50,14 @@ discard block |
||
| 50 | 50 | * @param PageRiconferma $page |
| 51 | 51 | * @see CreatePages::updateBasePage() |
| 52 | 52 | */ |
| 53 | - protected function updateBasePage( PageRiconferma $page ) { |
|
| 53 | + protected function updateBasePage ( PageRiconferma $page ) { |
|
| 54 | 54 | $this->getLogger()->info( "Updating base page for $page" ); |
| 55 | 55 | |
| 56 | 56 | $basePage = $this->getPage( $page->getBaseTitle() ); |
| 57 | 57 | $current = $basePage->getContent(); |
| 58 | 58 | |
| 59 | 59 | $outcomeText = $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ? |
| 60 | - 'non riconfermato' : |
|
| 61 | - 'riconfermato'; |
|
| 60 | + 'non riconfermato' : 'riconfermato'; |
|
| 62 | 61 | $text = $page->isVote() ? "votazione: $outcomeText" : 'riconferma tacita'; |
| 63 | 62 | |
| 64 | 63 | $newContent = str_replace( 'riconferma in corso', $text, $current ); |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class TaskBase extends ContextSource { |
| 15 | 15 | /** @var string[] */ |
| 16 | - protected $errors = []; |
|
| 16 | + protected $errors = [ ]; |
|
| 17 | 17 | /** @var TaskDataProvider */ |
| 18 | 18 | protected $dataProvider; |
| 19 | 19 | |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | * @param Controller $controller |
| 25 | 25 | * @param TaskDataProvider $dataProvider |
| 26 | 26 | */ |
| 27 | - final public function __construct( Logger $logger, Controller $controller, TaskDataProvider $dataProvider ) { |
|
| 27 | + final public function __construct ( Logger $logger, Controller $controller, TaskDataProvider $dataProvider ) { |
|
| 28 | 28 | parent::__construct( $logger, $controller ); |
| 29 | 29 | set_exception_handler( [ $this, 'handleException' ] ); |
| 30 | 30 | set_error_handler( [ $this, 'handleError' ] ); |
| 31 | 31 | $this->dataProvider = $dataProvider; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function __destruct() { |
|
| 34 | + public function __destruct () { |
|
| 35 | 35 | restore_error_handler(); |
| 36 | 36 | restore_exception_handler(); |
| 37 | 37 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return TaskResult |
| 43 | 43 | */ |
| 44 | - final public function run() : TaskResult { |
|
| 44 | + final public function run () : TaskResult { |
|
| 45 | 45 | $class = ( new \ReflectionClass( $this ) )->getShortName(); |
| 46 | 46 | $opName = $this->getOperationName(); |
| 47 | 47 | $this->getLogger()->info( "Starting $opName $class" ); |
@@ -72,14 +72,14 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return int One of the STATUS_* constants |
| 74 | 74 | */ |
| 75 | - abstract protected function runInternal() : int; |
|
| 75 | + abstract protected function runInternal () : int; |
|
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * How this operation should be called in logs |
| 79 | 79 | * |
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | - abstract public function getOperationName() : string; |
|
| 82 | + abstract public function getOperationName () : string; |
|
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * Exception handler. |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param \Throwable $ex |
| 88 | 88 | * @protected |
| 89 | 89 | */ |
| 90 | - public function handleException( \Throwable $ex ) { |
|
| 90 | + public function handleException ( \Throwable $ex ) { |
|
| 91 | 91 | $this->getLogger()->error( |
| 92 | 92 | ( new \ReflectionClass( $ex ) )->getShortName() . ': ' . |
| 93 | 93 | $ex->getMessage() . "\nin " . $ex->getFile() . ' line ' . |
@@ -105,14 +105,14 @@ discard block |
||
| 105 | 105 | * @throws \ErrorException |
| 106 | 106 | * @protected |
| 107 | 107 | */ |
| 108 | - public function handleError( $errno, $errstr, $errfile, $errline ) { |
|
| 108 | + public function handleError ( $errno, $errstr, $errfile, $errline ) { |
|
| 109 | 109 | throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline ); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * @return TaskDataProvider |
| 114 | 114 | */ |
| 115 | - protected function getDataProvider() : TaskDataProvider { |
|
| 115 | + protected function getDataProvider () : TaskDataProvider { |
|
| 116 | 116 | return $this->dataProvider; |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -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->getController() ); |
| 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 | // These are not groups |
| 175 | 175 | unset( $groups[ 'override' ], $groups[ 'override-perm' ] ); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @param array[] $extra |
| 190 | 190 | * @return array[] |
| 191 | 191 | */ |
| 192 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 192 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 193 | 193 | $newContent = $this->botList; |
| 194 | 194 | foreach ( $newContent as $user => $groups ) { |
| 195 | 195 | if ( isset( $missing[ $user ] ) ) { |
@@ -213,21 +213,21 @@ discard block |
||
| 213 | 213 | * @param array[] $newContent |
| 214 | 214 | * @return array[] |
| 215 | 215 | */ |
| 216 | - protected function removeOverrides( array $newContent ) : array { |
|
| 217 | - $removed = []; |
|
| 216 | + protected function removeOverrides ( array $newContent ) : array { |
|
| 217 | + $removed = [ ]; |
|
| 218 | 218 | foreach ( $newContent as $user => $groups ) { |
| 219 | - if ( !isset( $groups['override'] ) ) { |
|
| 219 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
| 220 | 220 | continue; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | $flagTS = PageBotList::getValidFlagTimestamp( $groups ); |
| 224 | 224 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); |
| 225 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
| 225 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
| 226 | 226 | $delay = 60 * 60 * 24 * 3; |
| 227 | 227 | |
| 228 | 228 | if ( time() > $usualTS + $delay && time() > $overrideTS + $delay ) { |
| 229 | 229 | unset( $newContent[ $user ][ 'override' ] ); |
| 230 | - $removed[] = $user; |
|
| 230 | + $removed[ ] = $user; |
|
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | |