@@ -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 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * @inheritDoc |
| 16 | 16 | */ |
| 17 | - public function runInternal() : int { |
|
| 17 | + public function runInternal () : int { |
|
| 18 | 18 | $users = $this->getDataProvider()->getUsersToProcess(); |
| 19 | 19 | |
| 20 | 20 | if ( !$users ) { |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param string $user |
| 35 | 35 | * @param array $groups |
| 36 | 36 | */ |
| 37 | - protected function processUser( string $user, array $groups ) { |
|
| 37 | + protected function processUser ( string $user, array $groups ) { |
|
| 38 | 38 | try { |
| 39 | 39 | $num = $this->getLastPageNum( $user ) + 1; |
| 40 | 40 | } catch ( TaskException $e ) { |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | * @return int |
| 67 | 67 | * @throws TaskException |
| 68 | 68 | */ |
| 69 | - protected function getLastPageNum( string $user ) : int { |
|
| 69 | + protected function getLastPageNum ( string $user ) : int { |
|
| 70 | 70 | $this->getLogger()->debug( "Retrieving previous pages for $user" ); |
| 71 | - $unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[1]; |
|
| 71 | + $unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[ 1 ]; |
|
| 72 | 72 | $params = [ |
| 73 | 73 | 'action' => 'query', |
| 74 | 74 | 'list' => 'allpages', |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | * @param string $user |
| 104 | 104 | * @param array $groups |
| 105 | 105 | */ |
| 106 | - protected function createPage( string $title, string $user, array $groups ) { |
|
| 106 | + protected function createPage ( string $title, string $user, array $groups ) { |
|
| 107 | 107 | $this->getLogger()->info( "Creating page $title" ); |
| 108 | 108 | $textParams = [ |
| 109 | 109 | '$user' => $user, |
| 110 | - '$date' => $groups['sysop'], |
|
| 111 | - '$burocrate' => $groups['bureaucrat'] ?? '', |
|
| 112 | - '$checkuser' => $groups['checkuser'] ?? '' |
|
| 110 | + '$date' => $groups[ 'sysop' ], |
|
| 111 | + '$burocrate' => $groups[ 'bureaucrat' ] ?? '', |
|
| 112 | + '$checkuser' => $groups[ 'checkuser' ] ?? '' |
|
| 113 | 113 | ]; |
| 114 | 114 | |
| 115 | 115 | $params = [ |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param string $title |
| 128 | 128 | * @param string $newText |
| 129 | 129 | */ |
| 130 | - protected function createBasePage( string $title, string $newText ) { |
|
| 130 | + protected function createBasePage ( string $title, string $newText ) { |
|
| 131 | 131 | $this->getLogger()->info( "Creating base page $title" ); |
| 132 | 132 | |
| 133 | 133 | $params = [ |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param string $title |
| 145 | 145 | * @param string $newText |
| 146 | 146 | */ |
| 147 | - protected function updateBasePage( string $title, string $newText ) { |
|
| 147 | + protected function updateBasePage ( string $title, string $newText ) { |
|
| 148 | 148 | $this->getLogger()->info( "Updating base page $title" ); |
| 149 | 149 | |
| 150 | 150 | $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\Task\Subtask; |
| 4 | 4 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | /** |
| 12 | 12 | * @inheritDoc |
| 13 | 13 | */ |
| 14 | - final protected function getOperationName(): string { |
|
| 14 | + final protected function getOperationName (): string { |
|
| 15 | 15 | return 'subtask'; |
| 16 | 16 | } |
| 17 | 17 | } |
@@ -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 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * @inheritDoc |
| 16 | 16 | */ |
| 17 | - public function runInternal() : int { |
|
| 17 | + public function runInternal () : int { |
|
| 18 | 18 | $pages = $this->getDataProvider()->getPagesToClose(); |
| 19 | 19 | $protectReason = $this->msg( 'close-protect-summary' )->text(); |
| 20 | 20 | foreach ( $pages as $page ) { |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * @param PageRiconferma $page |
| 33 | 33 | */ |
| 34 | - protected function addVoteCloseText( PageRiconferma $page ) { |
|
| 34 | + protected function addVoteCloseText ( PageRiconferma $page ) { |
|
| 35 | 35 | $content = $page->getContent(); |
| 36 | 36 | $beforeReg = '!è necessario ottenere una maggioranza .+ votanti\.!'; |
| 37 | 37 | $newContent = preg_replace( $beforeReg, '$0' . "\n" . $page->getOutcomeText(), $content ); |
@@ -46,15 +46,14 @@ discard block |
||
| 46 | 46 | * @param PageRiconferma $page |
| 47 | 47 | * @see CreatePages::updateBasePage() |
| 48 | 48 | */ |
| 49 | - protected function updateBasePage( PageRiconferma $page ) { |
|
| 49 | + protected function updateBasePage ( PageRiconferma $page ) { |
|
| 50 | 50 | $this->getLogger()->info( "Updating base page for $page" ); |
| 51 | 51 | |
| 52 | 52 | $basePage = new Page( $page->getBaseTitle() ); |
| 53 | 53 | $current = $basePage->getContent(); |
| 54 | 54 | |
| 55 | 55 | $outcomeText = $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ? |
| 56 | - 'non riconfermato' : |
|
| 57 | - 'riconfermato'; |
|
| 56 | + 'non riconfermato' : 'riconfermato'; |
|
| 58 | 57 | $text = $page->isVote() ? "votazione: $outcomeText" : 'riconferma tacita'; |
| 59 | 58 | |
| 60 | 59 | $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 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | abstract class TaskBase extends ContextSource { |
| 13 | 13 | /** @var string[] */ |
| 14 | - protected $errors = []; |
|
| 14 | + protected $errors = [ ]; |
|
| 15 | 15 | /** @var TaskDataProvider */ |
| 16 | 16 | protected $dataProvider; |
| 17 | 17 | |
@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @param TaskDataProvider $dataProvider |
| 22 | 22 | */ |
| 23 | - final public function __construct( TaskDataProvider $dataProvider ) { |
|
| 23 | + final public function __construct ( TaskDataProvider $dataProvider ) { |
|
| 24 | 24 | set_exception_handler( [ $this, 'handleException' ] ); |
| 25 | 25 | set_error_handler( [ $this, 'handleError' ] ); |
| 26 | 26 | parent::__construct(); |
| 27 | 27 | $this->dataProvider = $dataProvider; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function __destruct() { |
|
| 30 | + public function __destruct () { |
|
| 31 | 31 | restore_error_handler(); |
| 32 | 32 | restore_exception_handler(); |
| 33 | 33 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return TaskResult |
| 39 | 39 | */ |
| 40 | - final public function run() : TaskResult { |
|
| 40 | + final public function run () : TaskResult { |
|
| 41 | 41 | $class = ( new \ReflectionClass( $this ) )->getShortName(); |
| 42 | 42 | $opName = $this->getOperationName(); |
| 43 | 43 | $this->getLogger()->info( "Starting $opName $class" ); |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return int One of the STATUS_* constants |
| 70 | 70 | */ |
| 71 | - abstract protected function runInternal() : int; |
|
| 71 | + abstract protected function runInternal () : int; |
|
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * How this operation should be called in logs |
| 75 | 75 | * |
| 76 | 76 | * @return string |
| 77 | 77 | */ |
| 78 | - abstract protected function getOperationName() : string; |
|
| 78 | + abstract protected function getOperationName () : string; |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Exception handler. |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param \Throwable $ex |
| 84 | 84 | * @protected |
| 85 | 85 | */ |
| 86 | - public function handleException( \Throwable $ex ) { |
|
| 86 | + public function handleException ( \Throwable $ex ) { |
|
| 87 | 87 | $this->getLogger()->error( |
| 88 | 88 | get_class( $ex ) . ': ' . |
| 89 | 89 | $ex->getMessage() . "\nTrace:\n" . |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | * @param int $errline |
| 101 | 101 | * @protected |
| 102 | 102 | */ |
| 103 | - public function handleError( $errno, $errstr, $errfile, $errline ) { |
|
| 103 | + public function handleError ( $errno, $errstr, $errfile, $errline ) { |
|
| 104 | 104 | throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline ); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * @return TaskDataProvider |
| 109 | 109 | */ |
| 110 | - protected function getDataProvider() : TaskDataProvider { |
|
| 110 | + protected function getDataProvider () : TaskDataProvider { |
|
| 111 | 111 | return $this->dataProvider; |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -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 | |
@@ -15,15 +15,15 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * @inheritDoc |
| 17 | 17 | */ |
| 18 | - protected function getSubtasksMap(): array { |
|
| 18 | + protected function getSubtasksMap (): array { |
|
| 19 | 19 | // Everything is done here. |
| 20 | - return []; |
|
| 20 | + return [ ]; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @inheritDoc |
| 25 | 25 | */ |
| 26 | - public function runInternal() : int { |
|
| 26 | + public function runInternal () : int { |
|
| 27 | 27 | $pages = $this->getDataProvider()->getOpenPages(); |
| 28 | 28 | |
| 29 | 29 | if ( !$pages ) { |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | * @param PageRiconferma[] $pages |
| 38 | 38 | * @return int a STATUS_* constant |
| 39 | 39 | */ |
| 40 | - protected function processPages( array $pages ) : int { |
|
| 41 | - $actualPages = []; |
|
| 40 | + protected function processPages ( array $pages ) : int { |
|
| 41 | + $actualPages = [ ]; |
|
| 42 | 42 | foreach ( $pages as $page ) { |
| 43 | 43 | if ( $page->hasOpposition() && !$page->isVote() ) { |
| 44 | 44 | $this->openVote( $page ); |
| 45 | - $actualPages[] = $page; |
|
| 45 | + $actualPages[ ] = $page; |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @param PageRiconferma $page |
| 62 | 62 | */ |
| 63 | - protected function openVote( PageRiconferma $page ) { |
|
| 63 | + protected function openVote ( PageRiconferma $page ) { |
|
| 64 | 64 | $this->getLogger()->info( "Starting vote on $page" ); |
| 65 | 65 | |
| 66 | 66 | $content = $page->getContent(); |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | * @see SimpleUpdates::updateVote() |
| 100 | 100 | * @see UpdatesAround::addVote() |
| 101 | 101 | */ |
| 102 | - protected function updateVotePage( array $pages ) { |
|
| 102 | + protected function updateVotePage ( array $pages ) { |
|
| 103 | 103 | $votePage = new Page( $this->getConfig()->get( 'ric-vote-page' ) ); |
| 104 | 104 | $content = $votePage->getContent(); |
| 105 | 105 | |
| 106 | - $titles = []; |
|
| 106 | + $titles = [ ]; |
|
| 107 | 107 | foreach ( $pages as $page ) { |
| 108 | - $titles[] = preg_quote( $page->getTitle() ); |
|
| 108 | + $titles[ ] = preg_quote( $page->getTitle() ); |
|
| 109 | 109 | } |
| 110 | 110 | $titleReg = implode( '|', $titles ); |
| 111 | 111 | $search = "!^\*.+ La \[\[($titleReg)\|procedura]] termina.+\n!gm"; |
@@ -128,14 +128,14 @@ discard block |
||
| 128 | 128 | $newContent = preg_replace( $introReg, '$0' . "\n$newLines", $newContent, 1 ); |
| 129 | 129 | } else { |
| 130 | 130 | // Start section |
| 131 | - $matches = []; |
|
| 131 | + $matches = [ ]; |
|
| 132 | 132 | if ( preg_match( $introReg, $newContent, $matches ) === false ) { |
| 133 | 133 | throw new TaskException( 'Intro not found in vote page' ); |
| 134 | 134 | } |
| 135 | 135 | $beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m'; |
| 136 | 136 | // Replace semicolon with full stop |
| 137 | 137 | $newLines = substr( $newLines, 0, -2 ) . ".\n"; |
| 138 | - $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[0]}\n$newLines", $newContent, 1 ); |
|
| 138 | + $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[ 0 ]}\n$newLines", $newContent, 1 ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $summary = $this->msg( 'vote-start-vote-page-summary' ) |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @see UpdatesAround::addNews() |
| 158 | 158 | * @see SimpleUpdates::updateNews() |
| 159 | 159 | */ |
| 160 | - protected function updateNews( int $amount ) { |
|
| 160 | + protected function updateNews ( int $amount ) { |
|
| 161 | 161 | $this->getLogger()->info( "Turning $amount pages into votes" ); |
| 162 | 162 | $newsPage = new Page( $this->getConfig()->get( 'ric-news-page' ) ); |
| 163 | 163 | |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | throw new TaskException( 'Param "voto" not found in news page' ); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - $newTac = intval( $newsPage->getMatch( $regTac )[2] ) - $amount ?: ''; |
|
| 176 | - $newVot = intval( $newsPage->getMatch( $regVot )[2] ) + $amount ?: ''; |
|
| 175 | + $newTac = intval( $newsPage->getMatch( $regTac )[ 2 ] ) - $amount ?: ''; |
|
| 176 | + $newVot = intval( $newsPage->getMatch( $regVot )[ 2 ] ) + $amount ?: ''; |
|
| 177 | 177 | |
| 178 | 178 | $newContent = preg_replace( $regTac, '${1}' . $newTac, $content ); |
| 179 | 179 | $newContent = preg_replace( $regVot, '${1}' . $newVot, $newContent ); |
@@ -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 | |
@@ -14,13 +14,13 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @return string[] |
| 16 | 16 | */ |
| 17 | - abstract protected function getSubtasksMap() : array; |
|
| 17 | + abstract protected function getSubtasksMap () : array; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @param string $subtask Defined in self::SUBTASKS_MAP |
| 21 | 21 | * @return TaskResult |
| 22 | 22 | */ |
| 23 | - protected function runSubtask( string $subtask ) : TaskResult { |
|
| 23 | + protected function runSubtask ( string $subtask ) : TaskResult { |
|
| 24 | 24 | $map = $this->getSubtasksMap(); |
| 25 | 25 | if ( !isset( $map[ $subtask ] ) ) { |
| 26 | 26 | throw new \InvalidArgumentException( "'$subtask' is not a valid task." ); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | /** |
| 34 | 34 | * @inheritDoc |
| 35 | 35 | */ |
| 36 | - final protected function getOperationName(): string { |
|
| 36 | + final protected function getOperationName (): string { |
|
| 37 | 37 | return 'task'; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @param string $class |
| 44 | 44 | * @return Subtask |
| 45 | 45 | */ |
| 46 | - private function getSubtaskInstance( string $class ) : Subtask { |
|
| 46 | + private function getSubtaskInstance ( string $class ) : Subtask { |
|
| 47 | 47 | return new $class( $this->getDataProvider() ); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -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 | |
@@ -12,12 +12,12 @@ discard block |
||
| 12 | 12 | /** @var self */ |
| 13 | 13 | private static $instance; |
| 14 | 14 | /** @var array */ |
| 15 | - private $opts = []; |
|
| 15 | + private $opts = [ ]; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Use self::init() and self::getInstance() |
| 19 | 19 | */ |
| 20 | - private function __construct() { |
|
| 20 | + private function __construct () { |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | * @param array $defaults |
| 27 | 27 | * @throws ConfigException |
| 28 | 28 | */ |
| 29 | - public static function init( array $defaults ) { |
|
| 29 | + public static function init ( array $defaults ) { |
|
| 30 | 30 | if ( self::$instance ) { |
| 31 | 31 | throw new ConfigException( 'Config was already initialized' ); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $inst = new self; |
| 35 | - $inst->set( 'list-title', $defaults['list-title'] ); |
|
| 36 | - $inst->set( 'msg-title', $defaults['msg-title'] ); |
|
| 37 | - $inst->set( 'username', $defaults['username'] ); |
|
| 38 | - $inst->set( 'password', $defaults['password'] ); |
|
| 35 | + $inst->set( 'list-title', $defaults[ 'list-title' ] ); |
|
| 36 | + $inst->set( 'msg-title', $defaults[ 'msg-title' ] ); |
|
| 37 | + $inst->set( 'username', $defaults[ 'username' ] ); |
|
| 38 | + $inst->set( 'password', $defaults[ 'password' ] ); |
|
| 39 | 39 | self::$instance = $inst; |
| 40 | 40 | |
| 41 | 41 | // On-wiki values |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param string $key |
| 55 | 55 | * @return string |
| 56 | 56 | */ |
| 57 | - public function getWikiMessage( string $key ) : string { |
|
| 57 | + public function getWikiMessage ( string $key ) : string { |
|
| 58 | 58 | static $messages = null; |
| 59 | 59 | if ( $messages === null ) { |
| 60 | 60 | try { |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | throw new ConfigException( "Message '$key' does not exist." ); |
| 69 | 69 | } |
| 70 | 70 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
| 71 | - return $messages[$key]; |
|
| 71 | + return $messages[ $key ]; |
|
| 72 | 72 | } |
| 73 | 73 | /** |
| 74 | 74 | * Set a config value. |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param string $key |
| 77 | 77 | * @param mixed $value |
| 78 | 78 | */ |
| 79 | - protected function set( string $key, $value ) { |
|
| 79 | + protected function set ( string $key, $value ) { |
|
| 80 | 80 | $this->opts[ $key ] = $value; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return self |
| 87 | 87 | * @throws ConfigException |
| 88 | 88 | */ |
| 89 | - public static function getInstance() : self { |
|
| 89 | + public static function getInstance () : self { |
|
| 90 | 90 | if ( !self::$instance ) { |
| 91 | 91 | throw new ConfigException( 'Config not yet initialized' ); |
| 92 | 92 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @return mixed |
| 101 | 101 | * @throws ConfigException |
| 102 | 102 | */ |
| 103 | - public function get( string $opt ) { |
|
| 103 | + public function get ( string $opt ) { |
|
| 104 | 104 | if ( !isset( $this->opts[ $opt ] ) ) { |
| 105 | 105 | throw new ConfigException( "Config option '$opt' not set." ); |
| 106 | 106 | } |
@@ -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 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | /** |
| 26 | 26 | * @param string $domain The URL of the wiki, if different from default |
| 27 | 27 | */ |
| 28 | - public function __construct( string $domain = DEFAULT_URL ) { |
|
| 28 | + public function __construct ( string $domain = DEFAULT_URL ) { |
|
| 29 | 29 | $this->logger = new Logger; |
| 30 | 30 | $this->domain = $domain; |
| 31 | 31 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return string |
| 39 | 39 | * @throws MissingPageException |
| 40 | 40 | */ |
| 41 | - public function getPageContent( string $title, int $section = null ) : string { |
|
| 41 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
| 42 | 42 | $this->logger->debug( "Retrieving content of page $title" ); |
| 43 | 43 | $params = [ |
| 44 | 44 | 'action' => 'query', |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | ]; |
| 50 | 50 | |
| 51 | 51 | if ( $section !== null ) { |
| 52 | - $params['rvsection'] = $section; |
|
| 52 | + $params[ 'rvsection' ] = $section; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $req = RequestBase::newFromParams( $params )->setUrl( $this->domain ); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | throw new MissingPageException( $title ); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $mainSlot = $page->revisions[0]->slots->main; |
|
| 62 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
| 63 | 63 | |
| 64 | 64 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
| 65 | 65 | throw new MissingSectionException( $title, $section ); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param array $params |
| 74 | 74 | * @throws EditException |
| 75 | 75 | */ |
| 76 | - public function editPage( array $params ) { |
|
| 76 | + public function editPage ( array $params ) { |
|
| 77 | 77 | $this->login(); |
| 78 | 78 | |
| 79 | 79 | $params = [ |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
| 96 | 96 | * @throws LoginException |
| 97 | 97 | */ |
| 98 | - public function login() { |
|
| 98 | + public function login () { |
|
| 99 | 99 | if ( self::$loggedIn ) { |
| 100 | 100 | $this->logger->debug( 'Already logged in' ); |
| 101 | 101 | return; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | self::$loggedIn = true; |
| 124 | 124 | // Clear tokens cache |
| 125 | - $this->tokens = []; |
|
| 125 | + $this->tokens = [ ]; |
|
| 126 | 126 | $this->logger->info( 'Login succeeded' ); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @param string $type |
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | - public function getToken( string $type ) : string { |
|
| 135 | + public function getToken ( string $type ) : string { |
|
| 136 | 136 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 137 | 137 | $params = [ |
| 138 | 138 | 'action' => 'query', |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @param string $title |
| 156 | 156 | * @return int |
| 157 | 157 | */ |
| 158 | - public function getPageCreationTS( string $title ) : int { |
|
| 158 | + public function getPageCreationTS ( string $title ) : int { |
|
| 159 | 159 | $params = [ |
| 160 | 160 | 'action' => 'query', |
| 161 | 161 | 'prop' => 'revisions', |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | $res = RequestBase::newFromParams( $params )->setUrl( $this->domain )->execute(); |
| 170 | 170 | $data = $res->query->pages; |
| 171 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
| 171 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @param string $title |
| 178 | 178 | * @param string $reason |
| 179 | 179 | */ |
| 180 | - public function protectPage( string $title, string $reason ) { |
|
| 180 | + public function protectPage ( string $title, string $reason ) { |
|
| 181 | 181 | $this->logger->info( "Protecting page $title" ); |
| 182 | 182 | $this->login(); |
| 183 | 183 | |
@@ -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 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * @param string $key |
| 16 | 16 | */ |
| 17 | - public function __construct( string $key ) { |
|
| 17 | + public function __construct ( string $key ) { |
|
| 18 | 18 | $this->key = $key; |
| 19 | 19 | $this->value = Config::getInstance()->getWikiMessage( $key ); |
| 20 | 20 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param array $args |
| 24 | 24 | * @return self |
| 25 | 25 | */ |
| 26 | - public function params( array $args ) : self { |
|
| 26 | + public function params ( array $args ) : self { |
|
| 27 | 27 | $this->value = strtr( $this->value, $args ); |
| 28 | 28 | return $this; |
| 29 | 29 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | - public function text() : string { |
|
| 34 | + public function text () : string { |
|
| 35 | 35 | $this->parsePlurals(); |
| 36 | 36 | return $this->value; |
| 37 | 37 | } |
@@ -39,11 +39,11 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * Replace {{$plur|<amount>|sing|plur}} |
| 41 | 41 | */ |
| 42 | - protected function parsePlurals() { |
|
| 42 | + protected function parsePlurals () { |
|
| 43 | 43 | $this->value = preg_replace_callback( |
| 44 | 44 | '!\{\{$plur|(?P<amount>\d+)|(?P<sing>[^}|]+)|(?P<plur>[^|}]+)}}!', |
| 45 | 45 | function ( $matches ) { |
| 46 | - return intval( $matches['amount'] ) > 1 ? trim( $matches['plur'] ) : trim( $matches['sing'] ); |
|
| 46 | + return intval( $matches[ 'amount' ] ) > 1 ? trim( $matches[ 'plur' ] ) : trim( $matches[ 'sing' ] ); |
|
| 47 | 47 | }, |
| 48 | 48 | $this->value |
| 49 | 49 | ); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param int $timestamp |
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | - public static function getTimeWithArticle( int $timestamp ) : string { |
|
| 58 | + public static function getTimeWithArticle ( int $timestamp ) : string { |
|
| 59 | 59 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
| 60 | 60 | $timeString = strftime( '%e %B alle %R', $timestamp ); |
| 61 | 61 | // Remove the left space if day has a single digit |
@@ -73,16 +73,16 @@ discard block |
||
| 73 | 73 | * @return int |
| 74 | 74 | * @todo Is there a better way? |
| 75 | 75 | */ |
| 76 | - public static function getTimestampFromLocalTime( string $timeString ) : int { |
|
| 76 | + public static function getTimestampFromLocalTime ( string $timeString ) : int { |
|
| 77 | 77 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
| 78 | 78 | $bits = strptime( $timeString, '%e %m %Y alle %H:%M' ); |
| 79 | 79 | $timestamp = mktime( |
| 80 | - $bits['tm_hour'], |
|
| 81 | - $bits['tm_min'], |
|
| 80 | + $bits[ 'tm_hour' ], |
|
| 81 | + $bits[ 'tm_min' ], |
|
| 82 | 82 | 0, |
| 83 | - $bits['tm_mon'] + 1, |
|
| 84 | - $bits['tm_mday'], |
|
| 85 | - $bits['tm_year'] + 1900 |
|
| 83 | + $bits[ 'tm_mon' ] + 1, |
|
| 84 | + $bits[ 'tm_mday' ], |
|
| 85 | + $bits[ 'tm_year' ] + 1900 |
|
| 86 | 86 | ); |
| 87 | 87 | setlocale( LC_TIME, $oldLoc ); |
| 88 | 88 | |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | * @param string $emptyText |
| 98 | 98 | * @return string |
| 99 | 99 | */ |
| 100 | - public static function commaList( array $data, string $emptyText = 'nessuno' ) : string { |
|
| 100 | + public static function commaList ( array $data, string $emptyText = 'nessuno' ) : string { |
|
| 101 | 101 | if ( count( $data ) > 1 ) { |
| 102 | 102 | $last = array_pop( $data ); |
| 103 | 103 | $ret = implode( ', ', $data ) . " e $last"; |
| 104 | 104 | } elseif ( $data ) { |
| 105 | - $ret = $data[0]; |
|
| 105 | + $ret = $data[ 0 ]; |
|
| 106 | 106 | } else { |
| 107 | 107 | $ret = $emptyText; |
| 108 | 108 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | return $ret; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - public function __toString() { |
|
| 113 | + public function __toString () { |
|
| 114 | 114 | return $this->text(); |
| 115 | 115 | } |
| 116 | 116 | } |