@@ -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 \BotRiconferme\TaskHelper\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 public function getOperationName(): string { |
|
| 36 | + final public 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 | /** @var Subtask $ret */ |
| 48 | 48 | $ret = new $class( |
| 49 | 49 | $this->getLogger(), |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\TaskHelper; |
| 4 | 4 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param int $status One of the Task::STATUS_* constants |
| 22 | 22 | * @param string[] $errors |
| 23 | 23 | */ |
| 24 | - public function __construct( int $status, array $errors = [] ) { |
|
| 24 | + public function __construct ( int $status, array $errors = [ ] ) { |
|
| 25 | 25 | $this->status = $status; |
| 26 | 26 | $this->errors = $errors; |
| 27 | 27 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * @return int |
| 31 | 31 | */ |
| 32 | - public function getStatus() : int { |
|
| 32 | + public function getStatus () : int { |
|
| 33 | 33 | return $this->status; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | * @return string[] |
| 38 | 38 | * @suppress PhanUnreferencedPublicMethod |
| 39 | 39 | */ |
| 40 | - public function getErrors() : array { |
|
| 40 | + public function getErrors () : array { |
|
| 41 | 41 | return $this->errors; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * @param TaskResult $that |
| 46 | 46 | */ |
| 47 | - public function merge( TaskResult $that ) : void { |
|
| 47 | + public function merge ( TaskResult $that ) : void { |
|
| 48 | 48 | $this->status |= $that->status; |
| 49 | 49 | $this->errors = array_merge( $this->errors, $that->errors ); |
| 50 | 50 | } |
@@ -52,15 +52,15 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * @return string |
| 54 | 54 | */ |
| 55 | - public function __toString() { |
|
| 55 | + public function __toString () { |
|
| 56 | 56 | if ( $this->isOK() ) { |
| 57 | 57 | $stat = 'OK'; |
| 58 | 58 | $errs = "\tNo errors."; |
| 59 | 59 | } else { |
| 60 | 60 | $stat = 'ERROR'; |
| 61 | - $formattedErrs = []; |
|
| 61 | + $formattedErrs = [ ]; |
|
| 62 | 62 | foreach ( $this->errors as $err ) { |
| 63 | - $formattedErrs[] = "\t - $err"; |
|
| 63 | + $formattedErrs[ ] = "\t - $err"; |
|
| 64 | 64 | } |
| 65 | 65 | $errs = implode( "\n", $formattedErrs ); |
| 66 | 66 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return bool |
| 74 | 74 | */ |
| 75 | - public function isOK() : bool { |
|
| 75 | + public function isOK () : bool { |
|
| 76 | 76 | return ( $this->status | self::STATUS_GOOD ) === self::STATUS_GOOD; |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\TaskHelper; |
| 4 | 4 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** @var User[]|null */ |
| 16 | 16 | private $processUsers; |
| 17 | 17 | /** @var PageRiconferma[] */ |
| 18 | - private $createdPages = []; |
|
| 18 | + private $createdPages = [ ]; |
|
| 19 | 19 | /** @var PageRiconferma[]|null */ |
| 20 | 20 | private $openPages; |
| 21 | 21 | /** @var PageRiconferma[]|null */ |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return User[] |
| 28 | 28 | */ |
| 29 | - public function getUsersToProcess() : array { |
|
| 29 | + public function getUsersToProcess () : array { |
|
| 30 | 30 | if ( $this->processUsers === null ) { |
| 31 | - $this->processUsers = []; |
|
| 31 | + $this->processUsers = [ ]; |
|
| 32 | 32 | foreach ( $this->getBotList()->getAdminsList() as $name => $userInfo ) { |
| 33 | 33 | if ( $this->shouldAddUser( $userInfo ) ) { |
| 34 | 34 | $this->processUsers[ $name ] = new User( $userInfo, $this->getWiki() ); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param UserInfo $ui |
| 46 | 46 | * @return bool |
| 47 | 47 | */ |
| 48 | - private function shouldAddUser( UserInfo $ui ) : bool { |
|
| 48 | + private function shouldAddUser ( UserInfo $ui ) : bool { |
|
| 49 | 49 | $timestamp = $this->getBotList()->getOverrideTimestamp( $ui ); |
| 50 | 50 | $override = $timestamp !== null; |
| 51 | 51 | |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return PageRiconferma[] |
| 65 | 65 | */ |
| 66 | - public function getOpenPages() : array { |
|
| 66 | + public function getOpenPages () : array { |
|
| 67 | 67 | if ( $this->openPages === null ) { |
| 68 | - $this->openPages = []; |
|
| 68 | + $this->openPages = [ ]; |
|
| 69 | 69 | $mainTitle = $this->getOpt( 'main-page-title' ); |
| 70 | 70 | $params = [ |
| 71 | 71 | 'action' => 'query', |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $pages = $this->getRequestFactory()->newFromParams( $params )->execute()->query->pages; |
| 80 | 80 | foreach ( reset( $pages )->templates as $page ) { |
| 81 | 81 | if ( preg_match( "!$titleReg/[^/]+/\d!", $page->title ) ) { |
| 82 | - $this->openPages[] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
| 82 | + $this->openPages[ ] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return PageRiconferma[] |
| 94 | 94 | */ |
| 95 | - public function getPagesToClose() : array { |
|
| 95 | + public function getPagesToClose () : array { |
|
| 96 | 96 | if ( $this->pagesToClose === null ) { |
| 97 | - $this->pagesToClose = []; |
|
| 97 | + $this->pagesToClose = [ ]; |
|
| 98 | 98 | foreach ( $this->getOpenPages() as $page ) { |
| 99 | 99 | if ( time() > $page->getEndTimestamp() ) { |
| 100 | - $this->pagesToClose[] = $page; |
|
| 100 | + $this->pagesToClose[ ] = $page; |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -109,21 +109,21 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @param string $name |
| 111 | 111 | */ |
| 112 | - public function removeUser( string $name ) : void { |
|
| 112 | + public function removeUser ( string $name ) : void { |
|
| 113 | 113 | unset( $this->processUsers[ $name ] ); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * @return PageRiconferma[] |
| 118 | 118 | */ |
| 119 | - public function getCreatedPages() : array { |
|
| 119 | + public function getCreatedPages () : array { |
|
| 120 | 120 | return $this->createdPages; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * @param PageRiconferma $page |
| 125 | 125 | */ |
| 126 | - public function addCreatedPage( PageRiconferma $page ) : void { |
|
| 127 | - $this->createdPages[] = $page; |
|
| 126 | + public function addCreatedPage ( PageRiconferma $page ) : void { |
|
| 127 | + $this->createdPages[ ] = $page; |
|
| 128 | 128 | } |
| 129 | 129 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Message; |
| 4 | 4 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | /** |
| 24 | 24 | * @param string $value |
| 25 | 25 | */ |
| 26 | - public function __construct( string $value ) { |
|
| 26 | + public function __construct ( string $value ) { |
|
| 27 | 27 | $this->value = $value; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $args |
| 32 | 32 | * @return self |
| 33 | 33 | */ |
| 34 | - public function params( array $args ) : self { |
|
| 34 | + public function params ( array $args ) : self { |
|
| 35 | 35 | $this->value = strtr( $this->value, $args ); |
| 36 | 36 | return $this; |
| 37 | 37 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * @return string |
| 41 | 41 | */ |
| 42 | - public function text() : string { |
|
| 42 | + public function text () : string { |
|
| 43 | 43 | $this->parsePlurals(); |
| 44 | 44 | return $this->value; |
| 45 | 45 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * Replace {{$plur|<amount>|sing|plur}} |
| 49 | 49 | */ |
| 50 | - protected function parsePlurals() : void { |
|
| 50 | + protected function parsePlurals () : void { |
|
| 51 | 51 | $reg = '!\{\{\$plur\|(?P<amount>\d+)\|(?P<sing>[^}|]+)\|(?P<plur>[^|}]+)}}!'; |
| 52 | 52 | |
| 53 | 53 | if ( preg_match( $reg, $this->value ) === 0 ) { |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $this->value = preg_replace_callback( |
| 57 | 57 | $reg, |
| 58 | 58 | static function ( $matches ) { |
| 59 | - return (int)$matches['amount'] > 1 ? trim( $matches['plur'] ) : trim( $matches['sing'] ); |
|
| 59 | + return (int)$matches[ 'amount' ] > 1 ? trim( $matches[ 'plur' ] ) : trim( $matches[ 'sing' ] ); |
|
| 60 | 60 | }, |
| 61 | 61 | $this->value |
| 62 | 62 | ); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @param string $timeString Full format, e.g. "15 aprile 2019 18:27" |
| 69 | 69 | * @return int |
| 70 | 70 | */ |
| 71 | - public static function getTimestampFromLocalTime( string $timeString ) : int { |
|
| 71 | + public static function getTimestampFromLocalTime ( string $timeString ) : int { |
|
| 72 | 72 | $englishTime = str_ireplace( |
| 73 | 73 | array_values( self::MONTHS ), |
| 74 | 74 | array_keys( self::MONTHS ), |
@@ -86,12 +86,12 @@ discard block |
||
| 86 | 86 | * @param string $emptyText |
| 87 | 87 | * @return string |
| 88 | 88 | */ |
| 89 | - public static function commaList( array $data, string $emptyText = 'nessuno' ) : string { |
|
| 89 | + public static function commaList ( array $data, string $emptyText = 'nessuno' ) : string { |
|
| 90 | 90 | if ( count( $data ) > 1 ) { |
| 91 | 91 | $last = array_pop( $data ); |
| 92 | 92 | $ret = implode( ', ', $data ) . " e $last"; |
| 93 | 93 | } elseif ( $data ) { |
| 94 | - $ret = (string)$data[0]; |
|
| 94 | + $ret = (string)$data[ 0 ]; |
|
| 95 | 95 | } else { |
| 96 | 96 | $ret = $emptyText; |
| 97 | 97 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | return $ret; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - public function __toString() { |
|
| 102 | + public function __toString () { |
|
| 103 | 103 | return $this->text(); |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -1,4 +1,4 @@ |
||
| 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 | */ |
@@ -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,7 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | abstract class TaskBase extends ContextSource { |
| 17 | 17 | /** @var string[] */ |
| 18 | - protected $errors = []; |
|
| 18 | + protected $errors = [ ]; |
|
| 19 | 19 | /** @var TaskDataProvider */ |
| 20 | 20 | protected $dataProvider; |
| 21 | 21 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param MessageProvider $mp |
| 29 | 29 | * @param PageBotList $pbl |
| 30 | 30 | */ |
| 31 | - final public function __construct( |
|
| 31 | + final public function __construct ( |
|
| 32 | 32 | LoggerInterface $logger, |
| 33 | 33 | WikiGroup $wikiGroup, |
| 34 | 34 | TaskDataProvider $dataProvider, |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return \BotRiconferme\TaskHelper\TaskResult |
| 46 | 46 | */ |
| 47 | - final public function run() : TaskResult { |
|
| 47 | + final public function run () : TaskResult { |
|
| 48 | 48 | $class = ( new \ReflectionClass( $this ) )->getShortName(); |
| 49 | 49 | $opName = $this->getOperationName(); |
| 50 | 50 | $this->getLogger()->info( "Starting $opName $class" ); |
@@ -75,19 +75,19 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return int One of the STATUS_* constants |
| 77 | 77 | */ |
| 78 | - abstract protected function runInternal() : int; |
|
| 78 | + abstract protected function runInternal () : int; |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * How this operation should be called in logs |
| 82 | 82 | * |
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | - abstract public function getOperationName() : string; |
|
| 85 | + abstract public function getOperationName () : string; |
|
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * @return TaskDataProvider |
| 89 | 89 | */ |
| 90 | - protected function getDataProvider() : TaskDataProvider { |
|
| 90 | + protected function getDataProvider () : TaskDataProvider { |
|
| 91 | 91 | return $this->dataProvider; |
| 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; |
| 4 | 4 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | /** |
| 34 | 34 | * @param CLI $cli |
| 35 | 35 | */ |
| 36 | - public function __construct( CLI $cli ) { |
|
| 36 | + public function __construct ( CLI $cli ) { |
|
| 37 | 37 | $this->cli = $cli; |
| 38 | 38 | $this->initialize(); |
| 39 | 39 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * Initialize all members. |
| 43 | 43 | */ |
| 44 | - private function initialize() : void { |
|
| 44 | + private function initialize () : void { |
|
| 45 | 45 | $simpleLogger = new SimpleLogger(); |
| 46 | 46 | $this->createWikiGroup( $simpleLogger ); |
| 47 | 47 | $this->messageProvider = new MessageProvider( |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | /** |
| 56 | 56 | * Main entry point |
| 57 | 57 | */ |
| 58 | - public function run() : void { |
|
| 58 | + public function run () : void { |
|
| 59 | 59 | $taskOpt = $this->cli->getTaskOpt(); |
| 60 | 60 | $type = current( array_keys( $taskOpt ) ); |
| 61 | 61 | try { |
| 62 | 62 | if ( $type === 'task' ) { |
| 63 | - $this->runInternal( TaskManager::MODE_TASK, $taskOpt['task'] ); |
|
| 63 | + $this->runInternal( TaskManager::MODE_TASK, $taskOpt[ 'task' ] ); |
|
| 64 | 64 | } elseif ( $type === 'subtask' ) { |
| 65 | - $this->runInternal( TaskManager::MODE_SUBTASK, $taskOpt['subtask'] ); |
|
| 65 | + $this->runInternal( TaskManager::MODE_SUBTASK, $taskOpt[ 'subtask' ] ); |
|
| 66 | 66 | } else { |
| 67 | 67 | $this->runInternal(); |
| 68 | 68 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | /** |
| 77 | 77 | * @param LoggerInterface $baseLogger |
| 78 | 78 | */ |
| 79 | - private function createWikiGroup( LoggerInterface $baseLogger ) : void { |
|
| 79 | + private function createWikiGroup ( LoggerInterface $baseLogger ) : void { |
|
| 80 | 80 | // FIXME Hardcoded |
| 81 | 81 | $url = $this->cli->getURL() ?? 'https://it.wikipedia.org/w/api.php'; |
| 82 | 82 | $localUserIdentifier = '@itwiki'; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @param IFlushingAwareLogger $baseLogger |
| 102 | 102 | */ |
| 103 | - private function createMainLogger( IFlushingAwareLogger $baseLogger ) : void { |
|
| 103 | + private function createMainLogger ( IFlushingAwareLogger $baseLogger ) : void { |
|
| 104 | 104 | $mainWiki = $this->wikiGroup->getMainWiki(); |
| 105 | 105 | $mp = $this->messageProvider; |
| 106 | 106 | $errTitle = $this->cli->getOpt( 'error-title' ); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | /** |
| 128 | 128 | * Create the Config |
| 129 | 129 | */ |
| 130 | - private function initConfig() : void { |
|
| 130 | + private function initConfig () : void { |
|
| 131 | 131 | $wiki = $this->wikiGroup->getMainWiki(); |
| 132 | 132 | try { |
| 133 | 133 | $confValues = json_decode( $wiki->getPageContent( $this->cli->getOpt( 'config-title' ) ), true ); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param string $mode |
| 145 | 145 | * @param string|null $name |
| 146 | 146 | */ |
| 147 | - private function runInternal( |
|
| 147 | + private function runInternal ( |
|
| 148 | 148 | string $mode = TaskManager::MODE_COMPLETE, |
| 149 | 149 | string $name = null |
| 150 | 150 | ) : void { |
@@ -164,8 +164,7 @@ discard block |
||
| 164 | 164 | $base = "Execution of $activity"; |
| 165 | 165 | if ( $res->isOK() ) { |
| 166 | 166 | $msg = $res->getStatus() === TaskResult::STATUS_NOTHING ? |
| 167 | - ': nothing to do' : |
|
| 168 | - ' completed successfully'; |
|
| 167 | + ': nothing to do' : ' completed successfully'; |
|
| 169 | 168 | $this->mainLogger->info( $base . $msg ); |
| 170 | 169 | } else { |
| 171 | 170 | $this->mainLogger->error( "$base failed.\n$res" ); |
@@ -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 ) { |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param User $user |
| 36 | 36 | */ |
| 37 | - protected function processUser( User $user ) : void { |
|
| 37 | + protected function processUser ( User $user ) : void { |
|
| 38 | 38 | $this->getLogger()->info( "Processing user $user" ); |
| 39 | 39 | try { |
| 40 | 40 | $num = $this->getLastPageNum( $user ) + 1; |
@@ -69,14 +69,14 @@ discard block |
||
| 69 | 69 | * @return int |
| 70 | 70 | * @throws TaskException |
| 71 | 71 | */ |
| 72 | - protected function getLastPageNum( User $user ) : int { |
|
| 72 | + protected function getLastPageNum ( User $user ) : int { |
|
| 73 | 73 | $this->getLogger()->info( "Retrieving previous pages for $user" ); |
| 74 | 74 | |
| 75 | - $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[1]; |
|
| 75 | + $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[ 1 ]; |
|
| 76 | 76 | |
| 77 | 77 | $prefixes = [ "$unprefixedTitle/$user/" ]; |
| 78 | 78 | foreach ( $user->getAliases() as $alias ) { |
| 79 | - $prefixes[] = "$unprefixedTitle/$alias/"; |
|
| 79 | + $prefixes[ ] = "$unprefixedTitle/$alias/"; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $params = [ |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | 'apprefix' => implode( '|', $prefixes ), |
| 87 | 87 | 'aplimit' => 'max' |
| 88 | 88 | ]; |
| 89 | - $foundPages = []; |
|
| 89 | + $foundPages = [ ]; |
|
| 90 | 90 | foreach ( $prefixes as $prefix ) { |
| 91 | - $params['apprefix'] = $prefix; |
|
| 91 | + $params[ 'apprefix' ] = $prefix; |
|
| 92 | 92 | $res = $this->getRequestFactory()->newFromParams( $params )->execute(); |
| 93 | 93 | $foundPages = array_merge( $foundPages, $res->query->allpages ); |
| 94 | 94 | } |
@@ -114,14 +114,14 @@ discard block |
||
| 114 | 114 | * @param string $title |
| 115 | 115 | * @param User $user |
| 116 | 116 | */ |
| 117 | - protected function createPage( string $title, User $user ) : void { |
|
| 117 | + protected function createPage ( string $title, User $user ) : void { |
|
| 118 | 118 | $this->getLogger()->info( "Creating page $title" ); |
| 119 | 119 | $groups = $user->getGroupsWithDates(); |
| 120 | 120 | $textParams = [ |
| 121 | 121 | '$user' => $user->getName(), |
| 122 | - '$date' => $groups['sysop'], |
|
| 123 | - '$burocrate' => $groups['bureaucrat'] ?? '', |
|
| 124 | - '$checkuser' => $groups['checkuser'] ?? '' |
|
| 122 | + '$date' => $groups[ 'sysop' ], |
|
| 123 | + '$burocrate' => $groups[ 'bureaucrat' ] ?? '', |
|
| 124 | + '$checkuser' => $groups[ 'checkuser' ] ?? '' |
|
| 125 | 125 | ]; |
| 126 | 126 | |
| 127 | 127 | $params = [ |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param Page $basePage |
| 140 | 140 | * @param string $newText |
| 141 | 141 | */ |
| 142 | - protected function createBasePage( Page $basePage, string $newText ) : void { |
|
| 142 | + protected function createBasePage ( Page $basePage, string $newText ) : void { |
|
| 143 | 143 | $this->getLogger()->info( "Creating base page $basePage" ); |
| 144 | 144 | |
| 145 | 145 | $params = [ |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @param Page $basePage |
| 156 | 156 | * @param string $newText |
| 157 | 157 | */ |
| 158 | - protected function updateBasePage( Page $basePage, string $newText ) : void { |
|
| 158 | + protected function updateBasePage ( Page $basePage, string $newText ) : void { |
|
| 159 | 159 | $this->getLogger()->info( "Updating base page $basePage" ); |
| 160 | 160 | |
| 161 | 161 | $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\Page; |
| 4 | 4 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | /** @var int */ |
| 15 | 15 | private $opposeSection; |
| 16 | 16 | /** @var array Counts of votes for each section */ |
| 17 | - private $sectionCounts = []; |
|
| 17 | + private $sectionCounts = [ ]; |
|
| 18 | 18 | |
| 19 | 19 | // Possible outcomes of a vote |
| 20 | 20 | public const OUTCOME_OK = 0; |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * because they can vary depending on whether the page is a vote, which is relatively |
| 34 | 34 | * expensive to know since it requires parsing the content of the page. |
| 35 | 35 | */ |
| 36 | - private function defineSections() : void { |
|
| 36 | + private function defineSections () : void { |
|
| 37 | 37 | $this->supportSection = $this->isVote() ? 3 : 0; |
| 38 | 38 | $this->opposeSection = $this->isVote() ? 4 : 3; |
| 39 | 39 | } |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - public function getUserName() : string { |
|
| 47 | - return explode( '/', $this->title )[2]; |
|
| 46 | + public function getUserName () : string { |
|
| 47 | + return explode( '/', $this->title )[ 2 ]; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return int |
| 54 | 54 | */ |
| 55 | - public function getNum() : int { |
|
| 55 | + public function getNum () : int { |
|
| 56 | 56 | $bits = explode( '/', $this->getTitle() ); |
| 57 | 57 | return (int)end( $bits ); |
| 58 | 58 | } |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return string |
| 64 | 64 | */ |
| 65 | - public function getUserNum() : string { |
|
| 66 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
| 65 | + public function getUserNum () : string { |
|
| 66 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return int |
| 73 | 73 | */ |
| 74 | - public function getOpposingCount() : int { |
|
| 74 | + public function getOpposingCount () : int { |
|
| 75 | 75 | $this->defineSections(); |
| 76 | 76 | return $this->getCountForSection( $this->opposeSection ); |
| 77 | 77 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @return int |
| 83 | 83 | * @throws \BadMethodCallException |
| 84 | 84 | */ |
| 85 | - public function getSupportCount() : int { |
|
| 85 | + public function getSupportCount () : int { |
|
| 86 | 86 | if ( !$this->isVote() ) { |
| 87 | 87 | throw new \BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
| 88 | 88 | } |
@@ -96,13 +96,13 @@ discard block |
||
| 96 | 96 | * @param int $secNum |
| 97 | 97 | * @return int |
| 98 | 98 | */ |
| 99 | - protected function getCountForSection( int $secNum ) : int { |
|
| 99 | + protected function getCountForSection ( int $secNum ) : int { |
|
| 100 | 100 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
| 101 | 101 | $content = $this->wiki->getPageContent( $this->title, $secNum ); |
| 102 | 102 | // Let's hope that this is good enough... |
| 103 | - $this->sectionCounts[$secNum] = preg_match_all( "/^# *(?![# *:]|\.\.\.$)/m", $content ); |
|
| 103 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^# *(?![# *:]|\.\.\.$)/m", $content ); |
|
| 104 | 104 | } |
| 105 | - return $this->sectionCounts[$secNum]; |
|
| 105 | + return $this->sectionCounts[ $secNum ]; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -110,9 +110,9 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return int |
| 112 | 112 | */ |
| 113 | - protected function getQuorum() : int { |
|
| 113 | + protected function getQuorum () : int { |
|
| 114 | 114 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
| 115 | - return (int)$this->getMatch( $reg )[1]; |
|
| 115 | + return (int)$this->getMatch( $reg )[ 1 ]; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return bool |
| 122 | 122 | */ |
| 123 | - public function hasOpposition() : bool { |
|
| 123 | + public function hasOpposition () : bool { |
|
| 124 | 124 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return int One of the OUTCOME_* constants |
| 131 | 131 | */ |
| 132 | - public function getOutcome() : int { |
|
| 132 | + public function getOutcome () : int { |
|
| 133 | 133 | if ( !$this->isVote() ) { |
| 134 | 134 | return self::OUTCOME_OK; |
| 135 | 135 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @throws \BadMethodCallException |
| 153 | 153 | * @throws \LogicException |
| 154 | 154 | */ |
| 155 | - public function getOutcomeText() : string { |
|
| 155 | + public function getOutcomeText () : string { |
|
| 156 | 156 | if ( !$this->isVote() ) { |
| 157 | 157 | throw new \BadMethodCallException( 'No need for an outcome text.' ); |
| 158 | 158 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | * @return bool |
| 188 | 188 | */ |
| 189 | - public function isVote() : bool { |
|
| 189 | + public function isVote () : bool { |
|
| 190 | 190 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
| 191 | 191 | return !$this->matches( $sectionReg ); |
| 192 | 192 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * |
| 197 | 197 | * @return int |
| 198 | 198 | */ |
| 199 | - public function getCreationTimestamp() : int { |
|
| 199 | + public function getCreationTimestamp () : int { |
|
| 200 | 200 | return $this->wiki->getPageCreationTS( $this->title ); |
| 201 | 201 | } |
| 202 | 202 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @return int |
| 207 | 207 | */ |
| 208 | - public function getEndTimestamp() : int { |
|
| 208 | + public function getEndTimestamp () : int { |
|
| 209 | 209 | if ( $this->isVote() ) { |
| 210 | 210 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
| 211 | 211 | [ , $hours, $day ] = $this->getMatch( $reg ); |