@@ -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 | $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->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\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 | $failed = $this->getFailures(); |
| 22 | 22 | if ( !$failed ) { |
| 23 | 23 | return TaskResult::STATUS_NOTHING; |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @return PageRiconferma[] |
| 41 | 41 | */ |
| 42 | - private function getFailures() : array { |
|
| 43 | - $ret = []; |
|
| 42 | + private function getFailures () : array { |
|
| 43 | + $ret = [ ]; |
|
| 44 | 44 | $allPages = $this->getDataProvider()->getPagesToClose(); |
| 45 | 45 | foreach ( $allPages as $page ) { |
| 46 | 46 | if ( $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ) { |
| 47 | - $ret[] = $page; |
|
| 47 | + $ret[ ] = $page; |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | return $ret; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * @param User[] $users |
| 55 | 55 | */ |
| 56 | - protected function updateBurList( array $users ) { |
|
| 56 | + protected function updateBurList ( array $users ) { |
|
| 57 | 57 | $this->getLogger()->info( 'Updating bur list. Removing: ' . implode( ', ', $users ) ); |
| 58 | 58 | $remList = Element::regexFromArray( $users ); |
| 59 | 59 | $burList = $this->getPage( $this->getOpt( 'bur-list-title' ) ); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @param PageRiconferma[] $pages |
| 78 | 78 | */ |
| 79 | - protected function requestRemoval( array $pages ) { |
|
| 79 | + protected function requestRemoval ( array $pages ) { |
|
| 80 | 80 | $this->getLogger()->info( 'Requesting flag removal for: ' . implode( ', ', $pages ) ); |
| 81 | 81 | |
| 82 | 82 | $metaWiki = new Wiki( $this->getLogger(), META_URL ); |
@@ -113,15 +113,15 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @param PageRiconferma[] $pages |
| 115 | 115 | */ |
| 116 | - protected function updateAnnunci( array $pages ) { |
|
| 116 | + protected function updateAnnunci ( array $pages ) { |
|
| 117 | 117 | $this->getLogger()->info( 'Updating annunci' ); |
| 118 | 118 | $section = 1; |
| 119 | 119 | |
| 120 | - $names = []; |
|
| 120 | + $names = [ ]; |
|
| 121 | 121 | $text = ''; |
| 122 | 122 | foreach ( $pages as $page ) { |
| 123 | 123 | $user = $page->getUser()->getName(); |
| 124 | - $names[] = $user; |
|
| 124 | + $names[ ] = $user; |
|
| 125 | 125 | $text .= $this->msg( 'annunci-text' )->params( [ '$user' => $user ] )->text(); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -153,16 +153,16 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @param PageRiconferma[] $pages |
| 155 | 155 | */ |
| 156 | - protected function updateUltimeNotizie( array $pages ) { |
|
| 156 | + protected function updateUltimeNotizie ( array $pages ) { |
|
| 157 | 157 | $this->getLogger()->info( 'Updating ultime notizie' ); |
| 158 | 158 | $notiziePage = $this->getPage( $this->getOpt( 'ultimenotizie-page-title' ) ); |
| 159 | 159 | |
| 160 | - $names = []; |
|
| 160 | + $names = [ ]; |
|
| 161 | 161 | $text = ''; |
| 162 | 162 | $msg = $this->msg( 'ultimenotizie-text' ); |
| 163 | 163 | foreach ( $pages as $page ) { |
| 164 | 164 | $user = $page->getUser()->getName(); |
| 165 | - $names[] = $user; |
|
| 165 | + $names[ ] = $user; |
|
| 166 | 166 | $text .= $msg->params( [ '$user' => $user, '$title' => $page->getTitle() ] )->text(); |
| 167 | 167 | } |
| 168 | 168 | |
@@ -191,12 +191,12 @@ discard block |
||
| 191 | 191 | * @param PageRiconferma[] $pages |
| 192 | 192 | * @return User[] |
| 193 | 193 | */ |
| 194 | - private function getFailedBureaucrats( array $pages ) : array { |
|
| 195 | - $ret = []; |
|
| 194 | + private function getFailedBureaucrats ( array $pages ) : array { |
|
| 195 | + $ret = [ ]; |
|
| 196 | 196 | foreach ( $pages as $page ) { |
| 197 | 197 | $user = $page->getUser(); |
| 198 | 198 | if ( $user->inGroup( 'bureaucrat' ) ) { |
| 199 | - $ret[] = $user; |
|
| 199 | + $ret[ ] = $user; |
|
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | 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; |
| 4 | 4 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param LoggerInterface $logger |
| 56 | 56 | * @param Wiki $wiki |
| 57 | 57 | */ |
| 58 | - public function __construct( LoggerInterface $logger, Wiki $wiki ) { |
|
| 58 | + public function __construct ( LoggerInterface $logger, Wiki $wiki ) { |
|
| 59 | 59 | $this->logger = $logger; |
| 60 | 60 | $this->wiki = $wiki; |
| 61 | 61 | $this->provider = new TaskDataProvider( $this->logger, $this->wiki ); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @param string|null $name Only used in MODE_TASK and MODE_SUBTASK |
| 69 | 69 | * @return TaskResult |
| 70 | 70 | */ |
| 71 | - public function run( string $mode, string $name = null ) : TaskResult { |
|
| 71 | + public function run ( string $mode, string $name = null ) : TaskResult { |
|
| 72 | 72 | if ( $mode === self::MODE_COMPLETE ) { |
| 73 | 73 | return $this->runAllTasks(); |
| 74 | 74 | } elseif ( $name === null ) { |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @return TaskResult |
| 85 | 85 | */ |
| 86 | - protected function runAllTasks() : TaskResult { |
|
| 86 | + protected function runAllTasks () : TaskResult { |
|
| 87 | 87 | $orderedList = [ |
| 88 | 88 | 'update-list', |
| 89 | 89 | 'start-new', |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param string $name |
| 106 | 106 | * @return TaskResult |
| 107 | 107 | */ |
| 108 | - protected function runTask( string $name ) : TaskResult { |
|
| 108 | + protected function runTask ( string $name ) : TaskResult { |
|
| 109 | 109 | if ( !isset( self::TASKS_MAP[ $name ] ) ) { |
| 110 | 110 | throw new \InvalidArgumentException( "'$name' is not a valid task." ); |
| 111 | 111 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param string $name |
| 121 | 121 | * @return TaskResult |
| 122 | 122 | */ |
| 123 | - protected function runSubtask( string $name ) : TaskResult { |
|
| 123 | + protected function runSubtask ( string $name ) : TaskResult { |
|
| 124 | 124 | if ( !isset( self::SUBTASKS_MAP[ $name ] ) ) { |
| 125 | 125 | throw new \InvalidArgumentException( "'$name' is not a valid subtask." ); |
| 126 | 126 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param string $class |
| 136 | 136 | * @return Task |
| 137 | 137 | */ |
| 138 | - private function getTaskInstance( string $class ) : Task { |
|
| 138 | + private function getTaskInstance ( string $class ) : Task { |
|
| 139 | 139 | return new $class( $this->logger, $this->wiki, $this->provider ); |
| 140 | 140 | } |
| 141 | 141 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @param string $class |
| 146 | 146 | * @return Subtask |
| 147 | 147 | */ |
| 148 | - private function getSubtaskInstance( string $class ) : Subtask { |
|
| 148 | + private function getSubtaskInstance ( string $class ) : Subtask { |
|
| 149 | 149 | return new $class( $this->logger, $this->wiki, $this->provider ); |
| 150 | 150 | } |
| 151 | 151 | } |
@@ -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 | * @param LoggerInterface $logger |
| 21 | 21 | * @param Wiki $wiki |
| 22 | 22 | */ |
| 23 | - public function __construct( LoggerInterface $logger, Wiki $wiki ) { |
|
| 23 | + public function __construct ( LoggerInterface $logger, Wiki $wiki ) { |
|
| 24 | 24 | $this->logger = $logger; |
| 25 | 25 | $this->wiki = $wiki; |
| 26 | 26 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param string $mode |
| 32 | 32 | * @param string|null $name |
| 33 | 33 | */ |
| 34 | - private function run( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) { |
|
| 34 | + private function run ( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) { |
|
| 35 | 35 | $activity = $mode === TaskManager::MODE_COMPLETE ? TaskManager::MODE_COMPLETE : "$mode $name"; |
| 36 | 36 | $this->logger->info( "Running $activity" ); |
| 37 | 37 | $manager = new TaskManager( $this->logger, $this->wiki ); |
@@ -40,8 +40,7 @@ discard block |
||
| 40 | 40 | $base = "Execution of $activity"; |
| 41 | 41 | if ( $res->isOK() ) { |
| 42 | 42 | $msg = $res->getStatus() === TaskResult::STATUS_NOTHING ? |
| 43 | - ': nothing to do' : |
|
| 44 | - ' completed successfully'; |
|
| 43 | + ': nothing to do' : ' completed successfully'; |
|
| 45 | 44 | $this->logger->info( $base . $msg . ".\n$line\n\n" ); |
| 46 | 45 | } else { |
| 47 | 46 | $this->logger->error( "$base failed.\n$res\n$line\n\n" ); |
@@ -51,7 +50,7 @@ discard block |
||
| 51 | 50 | /** |
| 52 | 51 | * Entry point for the whole process |
| 53 | 52 | */ |
| 54 | - public function runAll() { |
|
| 53 | + public function runAll () { |
|
| 55 | 54 | $this->run(); |
| 56 | 55 | } |
| 57 | 56 | |
@@ -60,7 +59,7 @@ discard block |
||
| 60 | 59 | * |
| 61 | 60 | * @param string $task |
| 62 | 61 | */ |
| 63 | - public function runTask( string $task ) { |
|
| 62 | + public function runTask ( string $task ) { |
|
| 64 | 63 | $this->run( TaskManager::MODE_TASK, $task ); |
| 65 | 64 | } |
| 66 | 65 | |
@@ -69,7 +68,7 @@ discard block |
||
| 69 | 68 | * |
| 70 | 69 | * @param string $subtask |
| 71 | 70 | */ |
| 72 | - public function runSubtask( string $subtask ) { |
|
| 71 | + public function runSubtask ( string $subtask ) { |
|
| 73 | 72 | $this->run( TaskManager::MODE_SUBTASK, $subtask ); |
| 74 | 73 | } |
| 75 | 74 | } |
@@ -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 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * @param LoggerInterface $logger |
| 25 | 25 | * @param Wiki $wiki |
| 26 | 26 | */ |
| 27 | - public function __construct( LoggerInterface $logger, Wiki $wiki ) { |
|
| 27 | + public function __construct ( LoggerInterface $logger, Wiki $wiki ) { |
|
| 28 | 28 | $this->setLogger( $logger ); |
| 29 | 29 | $this->setConfig( Config::getInstance() ); |
| 30 | 30 | $this->setWiki( $wiki ); |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | /** |
| 34 | 34 | * @return LoggerInterface |
| 35 | 35 | */ |
| 36 | - protected function getLogger() : LoggerInterface { |
|
| 36 | + protected function getLogger () : LoggerInterface { |
|
| 37 | 37 | return $this->logger; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * @inheritDoc |
| 42 | 42 | */ |
| 43 | - public function setLogger( LoggerInterface $logger ) { |
|
| 43 | + public function setLogger ( LoggerInterface $logger ) { |
|
| 44 | 44 | $this->logger = $logger; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -50,35 +50,35 @@ discard block |
||
| 50 | 50 | * @param string $optname |
| 51 | 51 | * @return mixed |
| 52 | 52 | */ |
| 53 | - protected function getOpt( string $optname ) { |
|
| 53 | + protected function getOpt ( string $optname ) { |
|
| 54 | 54 | return $this->getConfig()->get( $optname ); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * @return Config |
| 59 | 59 | */ |
| 60 | - protected function getConfig() : Config { |
|
| 60 | + protected function getConfig () : Config { |
|
| 61 | 61 | return $this->config; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * @param Config $cfg |
| 66 | 66 | */ |
| 67 | - protected function setConfig( Config $cfg ) { |
|
| 67 | + protected function setConfig ( Config $cfg ) { |
|
| 68 | 68 | $this->config = $cfg; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @return Wiki |
| 73 | 73 | */ |
| 74 | - protected function getWiki() : Wiki { |
|
| 74 | + protected function getWiki () : Wiki { |
|
| 75 | 75 | return $this->wiki; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * @param Wiki $wiki |
| 80 | 80 | */ |
| 81 | - protected function setWiki( Wiki $wiki ) { |
|
| 81 | + protected function setWiki ( Wiki $wiki ) { |
|
| 82 | 82 | $this->wiki = $wiki; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * @param string $key |
| 89 | 89 | * @return Message |
| 90 | 90 | */ |
| 91 | - protected function msg( string $key ) : Message { |
|
| 91 | + protected function msg ( string $key ) : Message { |
|
| 92 | 92 | return new Message( $key ); |
| 93 | 93 | } |
| 94 | 94 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param string $title |
| 99 | 99 | * @return Page |
| 100 | 100 | */ |
| 101 | - protected function getPage( string $title ) : Page { |
|
| 101 | + protected function getPage ( string $title ) : Page { |
|
| 102 | 102 | return new Page( $title, $this->getWiki() ); |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -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 | // @phan-suppress-next-line PhanImpossibleTypeComparison $section can be null |
| 70 | 70 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param array $params |
| 80 | 80 | * @throws EditException |
| 81 | 81 | */ |
| 82 | - public function editPage( array $params ) { |
|
| 82 | + public function editPage ( array $params ) { |
|
| 83 | 83 | $this->login(); |
| 84 | 84 | |
| 85 | 85 | $params = [ |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | ] + $params; |
| 89 | 89 | |
| 90 | 90 | if ( Config::getInstance()->get( 'bot-edits' ) ) { |
| 91 | - $params['bot'] = 1; |
|
| 91 | + $params[ 'bot' ] = 1; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $res = $this->buildRequest( $params )->setPost()->execute(); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
| 107 | 107 | * @throws LoginException |
| 108 | 108 | */ |
| 109 | - public function login() { |
|
| 109 | + public function login () { |
|
| 110 | 110 | if ( self::$loggedIn ) { |
| 111 | 111 | return; |
| 112 | 112 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | self::$loggedIn = true; |
| 135 | 135 | // Clear tokens cache |
| 136 | - $this->tokens = []; |
|
| 136 | + $this->tokens = [ ]; |
|
| 137 | 137 | $this->logger->info( 'Login succeeded' ); |
| 138 | 138 | } |
| 139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @param string $type |
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | - public function getToken( string $type ) : string { |
|
| 146 | + public function getToken ( string $type ) : string { |
|
| 147 | 147 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 148 | 148 | $params = [ |
| 149 | 149 | 'action' => 'query', |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param string $title |
| 167 | 167 | * @return int |
| 168 | 168 | */ |
| 169 | - public function getPageCreationTS( string $title ) : int { |
|
| 169 | + public function getPageCreationTS ( string $title ) : int { |
|
| 170 | 170 | $params = [ |
| 171 | 171 | 'action' => 'query', |
| 172 | 172 | 'prop' => 'revisions', |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | $res = $this->buildRequest( $params )->execute(); |
| 181 | 181 | $data = $res->query->pages; |
| 182 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
| 182 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @param string $title |
| 189 | 189 | * @param string $reason |
| 190 | 190 | */ |
| 191 | - public function protectPage( string $title, string $reason ) { |
|
| 191 | + public function protectPage ( string $title, string $reason ) { |
|
| 192 | 192 | $this->logger->info( "Protecting page $title" ); |
| 193 | 193 | $this->login(); |
| 194 | 194 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * @param array $params |
| 210 | 210 | * @return RequestBase |
| 211 | 211 | */ |
| 212 | - private function buildRequest( array $params ) : RequestBase { |
|
| 212 | + private function buildRequest ( array $params ) : RequestBase { |
|
| 213 | 213 | return RequestBase::newFromParams( $params )->setUrl( $this->domain ); |
| 214 | 214 | } |
| 215 | 215 | } |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** @var self */ |
| 14 | 14 | private static $instance; |
| 15 | 15 | /** @var array */ |
| 16 | - private $opts = []; |
|
| 16 | + private $opts = [ ]; |
|
| 17 | 17 | /** @var array|null Lazy-loaded to avoid unnecessary requests */ |
| 18 | 18 | private $messages; |
| 19 | 19 | /** @var Wiki */ |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @param Wiki $wiki |
| 26 | 26 | */ |
| 27 | - private function __construct( Wiki $wiki ) { |
|
| 27 | + private function __construct ( Wiki $wiki ) { |
|
| 28 | 28 | $this->wiki = $wiki; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -35,16 +35,16 @@ discard block |
||
| 35 | 35 | * @param Wiki $wiki |
| 36 | 36 | * @throws ConfigException |
| 37 | 37 | */ |
| 38 | - public static function init( array $defaults, Wiki $wiki ) { |
|
| 38 | + public static function init ( array $defaults, Wiki $wiki ) { |
|
| 39 | 39 | if ( self::$instance ) { |
| 40 | 40 | throw new ConfigException( 'Config was already initialized' ); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $inst = new self( $wiki ); |
| 44 | - $inst->set( 'list-title', $defaults['list-title'] ); |
|
| 45 | - $inst->set( 'msg-title', $defaults['msg-title'] ); |
|
| 46 | - $inst->set( 'username', $defaults['username'] ); |
|
| 47 | - $inst->set( 'password', $defaults['password'] ); |
|
| 44 | + $inst->set( 'list-title', $defaults[ 'list-title' ] ); |
|
| 45 | + $inst->set( 'msg-title', $defaults[ 'msg-title' ] ); |
|
| 46 | + $inst->set( 'username', $defaults[ 'username' ] ); |
|
| 47 | + $inst->set( 'password', $defaults[ 'password' ] ); |
|
| 48 | 48 | |
| 49 | 49 | // On-wiki values |
| 50 | 50 | try { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return string |
| 65 | 65 | * @throws ConfigException |
| 66 | 66 | */ |
| 67 | - public function getWikiMessage( string $key ) : string { |
|
| 67 | + public function getWikiMessage ( string $key ) : string { |
|
| 68 | 68 | if ( $this->messages === null ) { |
| 69 | 69 | try { |
| 70 | 70 | $cont = $this->wiki->getPageContent( $this->opts[ 'msg-title' ] ); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | if ( !isset( $this->messages[ $key ] ) ) { |
| 77 | 77 | throw new ConfigException( "Message '$key' does not exist." ); |
| 78 | 78 | } |
| 79 | - return $this->messages[$key]; |
|
| 79 | + return $this->messages[ $key ]; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param string $key |
| 86 | 86 | * @param mixed $value |
| 87 | 87 | */ |
| 88 | - protected function set( string $key, $value ) { |
|
| 88 | + protected function set ( string $key, $value ) { |
|
| 89 | 89 | $this->opts[ $key ] = $value; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @return self |
| 96 | 96 | * @throws ConfigException |
| 97 | 97 | */ |
| 98 | - public static function getInstance() : self { |
|
| 98 | + public static function getInstance () : self { |
|
| 99 | 99 | if ( !self::$instance ) { |
| 100 | 100 | throw new ConfigException( 'Config not yet initialized' ); |
| 101 | 101 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @return mixed |
| 110 | 110 | * @throws ConfigException |
| 111 | 111 | */ |
| 112 | - public function get( string $opt ) { |
|
| 112 | + public function get ( string $opt ) { |
|
| 113 | 113 | if ( !isset( $this->opts[ $opt ] ) ) { |
| 114 | 114 | throw new ConfigException( "Config option '$opt' not set." ); |
| 115 | 115 | } |
@@ -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 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * @param string $minlevel |
| 19 | 19 | */ |
| 20 | - public function __construct( $minlevel = LogLevel::INFO ) { |
|
| 20 | + public function __construct ( $minlevel = LogLevel::INFO ) { |
|
| 21 | 21 | $this->minLevel = $this->levelToInt( $minlevel ); |
| 22 | 22 | } |
| 23 | 23 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @inheritDoc |
| 26 | 26 | * @suppress PhanUnusedPublicMethodParameter |
| 27 | 27 | */ |
| 28 | - public function log( $level, $message, array $context = [] ) { |
|
| 28 | + public function log ( $level, $message, array $context = [ ] ) { |
|
| 29 | 29 | if ( $this->levelToInt( $level ) >= $this->minLevel ) { |
| 30 | 30 | echo $this->getFormattedMessage( $level, $message ); |
| 31 | 31 | } |
@@ -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 | |
@@ -10,12 +10,12 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class MultiLogger extends AbstractLogger { |
| 12 | 12 | /** @var LoggerInterface[] */ |
| 13 | - private $loggers = []; |
|
| 13 | + private $loggers = [ ]; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * @param LoggerInterface ...$loggers |
| 17 | 17 | */ |
| 18 | - public function __construct( LoggerInterface ...$loggers ) { |
|
| 18 | + public function __construct ( LoggerInterface ...$loggers ) { |
|
| 19 | 19 | $this->loggers = $loggers; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @inheritDoc |
| 24 | 24 | * @suppress PhanUnusedPublicMethodParameter |
| 25 | 25 | */ |
| 26 | - public function log( $level, $message, array $context = [] ) { |
|
| 26 | + public function log ( $level, $message, array $context = [ ] ) { |
|
| 27 | 27 | foreach ( $this->loggers as $logger ) { |
| 28 | 28 | $logger->log( $level, $message ); |
| 29 | 29 | } |