@@ -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,7 +14,7 @@ discard block |
||
| 14 | 14 | const STATUS_OK = 0; |
| 15 | 15 | const STATUS_ERROR = 1; |
| 16 | 16 | /** @var string[] */ |
| 17 | - protected $errors = []; |
|
| 17 | + protected $errors = [ ]; |
|
| 18 | 18 | /** @var TaskDataProvider */ |
| 19 | 19 | protected $dataProvider; |
| 20 | 20 | |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @param TaskDataProvider $dataProvider |
| 25 | 25 | */ |
| 26 | - final public function __construct( TaskDataProvider $dataProvider ) { |
|
| 26 | + final public function __construct ( TaskDataProvider $dataProvider ) { |
|
| 27 | 27 | set_exception_handler( [ $this, 'handleException' ] ); |
| 28 | 28 | set_error_handler( [ $this, 'handleError' ] ); |
| 29 | 29 | parent::__construct(); |
| 30 | 30 | $this->dataProvider = $dataProvider; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function __destruct() { |
|
| 33 | + public function __destruct () { |
|
| 34 | 34 | restore_error_handler(); |
| 35 | 35 | restore_exception_handler(); |
| 36 | 36 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return TaskResult |
| 42 | 42 | */ |
| 43 | - abstract public function run() : TaskResult; |
|
| 43 | + abstract public function run () : TaskResult; |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * Exception handler. |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param \Throwable $ex |
| 49 | 49 | * @protected |
| 50 | 50 | */ |
| 51 | - public function handleException( \Throwable $ex ) { |
|
| 51 | + public function handleException ( \Throwable $ex ) { |
|
| 52 | 52 | $this->getLogger()->error( |
| 53 | 53 | get_class( $ex ) . ': ' . |
| 54 | 54 | $ex->getMessage() . "\nTrace:\n" . |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | * @param int $errline |
| 66 | 66 | * @protected |
| 67 | 67 | */ |
| 68 | - public function handleError( $errno, $errstr, $errfile, $errline ) { |
|
| 68 | + public function handleError ( $errno, $errstr, $errfile, $errline ) { |
|
| 69 | 69 | throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * @return TaskDataProvider |
| 74 | 74 | */ |
| 75 | - protected function getDataProvider() : TaskDataProvider { |
|
| 75 | + protected function getDataProvider () : TaskDataProvider { |
|
| 76 | 76 | return $this->dataProvider; |
| 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; |
| 4 | 4 | |
@@ -11,14 +11,14 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | const VERSION = 1.0; |
| 13 | 13 | |
| 14 | - public function __construct() { |
|
| 14 | + public function __construct () { |
|
| 15 | 15 | $this->logger = new Logger; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Entry point for the whole process |
| 20 | 20 | */ |
| 21 | - public function run() { |
|
| 21 | + public function run () { |
|
| 22 | 22 | $this->logger->info( 'Starting full process.' ); |
| 23 | 23 | $manager = new TaskManager; |
| 24 | 24 | $res = $manager->run( TaskManager::MODE_COMPLETE ); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @param string $task |
| 37 | 37 | */ |
| 38 | - public function runTask( string $task ) { |
|
| 38 | + public function runTask ( string $task ) { |
|
| 39 | 39 | $this->logger->info( "Starting single task $task." ); |
| 40 | 40 | $manager = new TaskManager; |
| 41 | 41 | $res = $manager->run( TaskManager::MODE_TASK, $task ); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @param string $subtask |
| 54 | 54 | */ |
| 55 | - public function runSubtask( string $subtask ) { |
|
| 55 | + public function runSubtask ( string $subtask ) { |
|
| 56 | 56 | $this->logger->info( "Starting single subtask $subtask." ); |
| 57 | 57 | $manager = new TaskManager; |
| 58 | 58 | $res = $manager->run( TaskManager::MODE_SUBTASK, $subtask ); |
@@ -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 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param string|null $name Only used in MODE_TASK and MODE_SUBTASK |
| 48 | 48 | * @return TaskResult |
| 49 | 49 | */ |
| 50 | - public function run( int $mode, string $name = null ) : TaskResult { |
|
| 50 | + public function run ( int $mode, string $name = null ) : TaskResult { |
|
| 51 | 51 | $this->provider = new TaskDataProvider; |
| 52 | 52 | |
| 53 | 53 | if ( $mode === self::MODE_COMPLETE ) { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return TaskResult |
| 66 | 66 | */ |
| 67 | - protected function runAllTasks() : TaskResult { |
|
| 67 | + protected function runAllTasks () : TaskResult { |
|
| 68 | 68 | if ( self::getLastFullRunDate() === date( 'd/m/Y' ) ) { |
| 69 | 69 | // Really avoid executing twice the same day |
| 70 | 70 | return new TaskResult( TaskResult::STATUS_ERROR, [ 'A full run was already executed today.' ] ); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @param string $name |
| 96 | 96 | * @return TaskResult |
| 97 | 97 | */ |
| 98 | - protected function runTask( string $name ) : TaskResult { |
|
| 98 | + protected function runTask ( string $name ) : TaskResult { |
|
| 99 | 99 | if ( !isset( self::TASKS_MAP[ $name ] ) ) { |
| 100 | 100 | throw new \InvalidArgumentException( "'$name' is not a valid task." ); |
| 101 | 101 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param string $name |
| 111 | 111 | * @return TaskResult |
| 112 | 112 | */ |
| 113 | - protected function runSubtask( string $name ) : TaskResult { |
|
| 113 | + protected function runSubtask ( string $name ) : TaskResult { |
|
| 114 | 114 | if ( !isset( self::SUBTASKS_MAP[ $name ] ) ) { |
| 115 | 115 | throw new \InvalidArgumentException( "'$name' is not a valid subtask." ); |
| 116 | 116 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @return string|null d/m/Y or null if no last run registered |
| 125 | 125 | * @fixme Is this even necessary? |
| 126 | 126 | */ |
| 127 | - public static function getLastFullRunDate() : ?string { |
|
| 127 | + public static function getLastFullRunDate () : ?string { |
|
| 128 | 128 | if ( file_exists( self::LOG_FILE ) ) { |
| 129 | 129 | return file_get_contents( self::LOG_FILE ) ?: null; |
| 130 | 130 | } else { |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param string $class |
| 139 | 139 | * @return Task |
| 140 | 140 | */ |
| 141 | - private function getTaskInstance( string $class ) : Task { |
|
| 141 | + private function getTaskInstance ( string $class ) : Task { |
|
| 142 | 142 | return new $class( $this->provider ); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -148,11 +148,11 @@ discard block |
||
| 148 | 148 | * @param string $class |
| 149 | 149 | * @return Subtask |
| 150 | 150 | */ |
| 151 | - private function getSubtaskInstance( string $class ) : Subtask { |
|
| 151 | + private function getSubtaskInstance ( string $class ) : Subtask { |
|
| 152 | 152 | return new $class( $this->provider ); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - public static function setLastFullRunDate() { |
|
| 155 | + public static function setLastFullRunDate () { |
|
| 156 | 156 | file_put_contents( self::LOG_FILE, date( 'd/m/Y' ) ); |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -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 | */ |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | /* URL (for debugging purpose) */ |
| 39 | 39 | $urlParam = getopt( '', [ 'force-url:' ] ); |
| 40 | -$url = $urlParam['force-url'] ?? 'https://it.wikipedia.org/w/api.php'; |
|
| 40 | +$url = $urlParam[ 'force-url' ] ?? 'https://it.wikipedia.org/w/api.php'; |
|
| 41 | 41 | |
| 42 | 42 | define( 'DEFAULT_URL', $url ); |
| 43 | 43 | |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | if ( count( $taskOpts ) === 2 ) { |
| 89 | 89 | throw new InvalidArgumentException( 'Cannot specify both task and subtask.' ); |
| 90 | -} elseif ( isset( $taskOpts['task'] ) ) { |
|
| 90 | +} elseif ( isset( $taskOpts[ 'task' ] ) ) { |
|
| 91 | 91 | $bot->runTask( $taskOpts[ 'task' ] ); |
| 92 | -} elseif ( isset( $taskOpts['subtask'] ) ) { |
|
| 92 | +} elseif ( isset( $taskOpts[ 'subtask' ] ) ) { |
|
| 93 | 93 | $bot->runSubtask( $taskOpts[ 'subtask' ] ); |
| 94 | 94 | } else { |
| 95 | 95 | $bot->run(); |