@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | /** |
3 | 3 | * Entry point for the bot, called by CLI |
4 | 4 | */ |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | /* URL (for debugging purpose) */ |
41 | 41 | $urlParam = getopt( '', [ 'force-url:' ] ); |
42 | -$url = $urlParam['force-url'] ?? 'https://it.wikipedia.org/w/api.php'; |
|
42 | +$url = $urlParam[ 'force-url' ] ?? 'https://it.wikipedia.org/w/api.php'; |
|
43 | 43 | |
44 | 44 | define( 'DEFAULT_URL', $url ); |
45 | 45 | define( 'META_URL', 'https://meta.wikimedia.org/w/api.php' ); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | /* START */ |
77 | 77 | |
78 | 78 | $errParam = getopt( '', [ 'error-title::' ] ); |
79 | -$errTitle = $errParam['error-title'] ?? null; |
|
79 | +$errTitle = $errParam[ 'error-title' ] ?? null; |
|
80 | 80 | |
81 | 81 | $simpleLogger = new \BotRiconferme\Logger\SimpleLogger(); |
82 | 82 | // @fixme |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | try { |
128 | - if ( isset( $taskOpts['task'] ) ) { |
|
129 | - $bot->runTask( $taskOpts['task'] ); |
|
130 | - } elseif ( isset( $taskOpts['subtask'] ) ) { |
|
131 | - $bot->runSubtask( $taskOpts['subtask'] ); |
|
128 | + if ( isset( $taskOpts[ 'task' ] ) ) { |
|
129 | + $bot->runTask( $taskOpts[ 'task' ] ); |
|
130 | + } elseif ( isset( $taskOpts[ 'subtask' ] ) ) { |
|
131 | + $bot->runSubtask( $taskOpts[ 'subtask' ] ); |
|
132 | 132 | } else { |
133 | 133 | $bot->runAll(); |
134 | 134 | } |
@@ -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 ); |
@@ -39,8 +39,7 @@ discard block |
||
39 | 39 | $base = "Execution of $activity"; |
40 | 40 | if ( $res->isOK() ) { |
41 | 41 | $msg = $res->getStatus() === TaskResult::STATUS_NOTHING ? |
42 | - ': nothing to do' : |
|
43 | - ' completed successfully'; |
|
42 | + ': nothing to do' : ' completed successfully'; |
|
44 | 43 | $this->logger->info( $base . $msg ); |
45 | 44 | } else { |
46 | 45 | $this->logger->error( "$base failed.\n$res" ); |
@@ -50,7 +49,7 @@ discard block |
||
50 | 49 | /** |
51 | 50 | * Entry point for the whole process |
52 | 51 | */ |
53 | - public function runAll() { |
|
52 | + public function runAll () { |
|
54 | 53 | $this->run(); |
55 | 54 | } |
56 | 55 | |
@@ -59,7 +58,7 @@ discard block |
||
59 | 58 | * |
60 | 59 | * @param string $task |
61 | 60 | */ |
62 | - public function runTask( string $task ) { |
|
61 | + public function runTask ( string $task ) { |
|
63 | 62 | $this->run( TaskManager::MODE_TASK, $task ); |
64 | 63 | } |
65 | 64 | |
@@ -68,7 +67,7 @@ discard block |
||
68 | 67 | * |
69 | 68 | * @param string $subtask |
70 | 69 | */ |
71 | - public function runSubtask( string $subtask ) { |
|
70 | + public function runSubtask ( string $subtask ) { |
|
72 | 71 | $this->run( TaskManager::MODE_SUBTASK, $subtask ); |
73 | 72 | } |
74 | 73 | } |
@@ -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 | |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @param string $level |
12 | 12 | * @return int |
13 | 13 | */ |
14 | - protected function levelToInt( string $level ) : int { |
|
14 | + protected function levelToInt ( string $level ) : int { |
|
15 | 15 | // Order matters |
16 | 16 | $mapping = [ |
17 | 17 | LogLevel::DEBUG, |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param string $message |
32 | 32 | * @return string |
33 | 33 | */ |
34 | - protected function getFormattedMessage( string $level, string $message ) { |
|
34 | + protected function getFormattedMessage ( string $level, string $message ) { |
|
35 | 35 | return sprintf( "%s [%s] - %s", date( 'd M H:i:s' ), $level, $message ); |
36 | 36 | } |
37 | 37 | } |
@@ -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 implements IFlushingAwareLogger { |
12 | 12 | /** @var IFlushingAwareLogger[] */ |
13 | - private $loggers = []; |
|
13 | + private $loggers = [ ]; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * @param IFlushingAwareLogger ...$loggers |
17 | 17 | */ |
18 | - public function __construct( IFlushingAwareLogger ...$loggers ) { |
|
18 | + public function __construct ( IFlushingAwareLogger ...$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 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @inheritDoc |
34 | 34 | */ |
35 | - public function flush() : void { |
|
35 | + public function flush () : void { |
|
36 | 36 | foreach ( $this->loggers as $logger ) { |
37 | 37 | $logger->flush(); |
38 | 38 | } |
@@ -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 ) . "\n"; |
31 | 31 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @inheritDoc |
36 | 36 | */ |
37 | - public function flush() : void { |
|
37 | + public function flush () : void { |
|
38 | 38 | // Everything else is printed immediately |
39 | 39 | echo "\n" . str_repeat( '-', 80 ) . "\n\n"; |
40 | 40 | } |
@@ -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 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param Page $logPage |
27 | 27 | * @param string $minlevel |
28 | 28 | */ |
29 | - public function __construct( Page $logPage, $minlevel = LogLevel::INFO ) { |
|
29 | + public function __construct ( Page $logPage, $minlevel = LogLevel::INFO ) { |
|
30 | 30 | $this->minLevel = $this->levelToInt( $minlevel ); |
31 | 31 | $this->logPage = $logPage; |
32 | 32 | } |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | * @inheritDoc |
36 | 36 | * @suppress PhanUnusedPublicMethodParameter |
37 | 37 | */ |
38 | - public function log( $level, $message, array $context = [] ) { |
|
38 | + public function log ( $level, $message, array $context = [ ] ) { |
|
39 | 39 | if ( $this->levelToInt( $level ) >= $this->minLevel ) { |
40 | - $this->buffer[] = $this->getFormattedMessage( $level, $message ); |
|
40 | + $this->buffer[ ] = $this->getFormattedMessage( $level, $message ); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - protected function getOutput() : string { |
|
47 | + protected function getOutput () : string { |
|
48 | 48 | $line = str_repeat( '-', 80 ); |
49 | 49 | return implode( "\n", $this->buffer ) . "\n$line\n\n"; |
50 | 50 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @inheritDoc |
54 | 54 | */ |
55 | - public function flush() : void { |
|
55 | + public function flush () : void { |
|
56 | 56 | if ( $this->buffer ) { |
57 | 57 | $this->logPage->edit( [ |
58 | 58 | 'appendtext' => $this->getOutput(), |
@@ -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 | |
@@ -6,5 +6,5 @@ discard block |
||
6 | 6 | * Logger aware of flushing. Can be declared empty if the buffer is flushed immediately. |
7 | 7 | */ |
8 | 8 | interface IFlushingAwareLogger { |
9 | - public function flush() : void; |
|
9 | + public function flush () : void; |
|
10 | 10 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Task; |
4 | 4 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class TaskBase extends ContextSource { |
15 | 15 | /** @var string[] */ |
16 | - protected $errors = []; |
|
16 | + protected $errors = [ ]; |
|
17 | 17 | /** @var TaskDataProvider */ |
18 | 18 | protected $dataProvider; |
19 | 19 | |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @param Wiki $wiki |
25 | 25 | * @param TaskDataProvider $dataProvider |
26 | 26 | */ |
27 | - final public function __construct( |
|
27 | + final public function __construct ( |
|
28 | 28 | LoggerInterface $logger, |
29 | 29 | Wiki $wiki, |
30 | 30 | TaskDataProvider $dataProvider |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return TaskResult |
40 | 40 | */ |
41 | - final public function run() : TaskResult { |
|
41 | + final public function run () : TaskResult { |
|
42 | 42 | $class = ( new \ReflectionClass( $this ) )->getShortName(); |
43 | 43 | $opName = $this->getOperationName(); |
44 | 44 | $this->getLogger()->info( "Starting $opName $class" ); |
@@ -69,19 +69,19 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return int One of the STATUS_* constants |
71 | 71 | */ |
72 | - abstract protected function runInternal() : int; |
|
72 | + abstract protected function runInternal () : int; |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * How this operation should be called in logs |
76 | 76 | * |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - abstract public function getOperationName() : string; |
|
79 | + abstract public function getOperationName () : string; |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @return TaskDataProvider |
83 | 83 | */ |
84 | - protected function getDataProvider() : TaskDataProvider { |
|
84 | + protected function getDataProvider () : TaskDataProvider { |
|
85 | 85 | return $this->dataProvider; |
86 | 86 | } |
87 | 87 | } |