@@ -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 ) : string { |
|
34 | + protected function getFormattedMessage ( string $level, string $message ) : string { |
|
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 | |
@@ -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 = [] ) :void { |
|
38 | + public function log ( $level, $message, array $context = [ ] ) :void { |
|
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 "\n\n" . 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; |
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 ) : void { |
|
34 | + private function run ( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) : void { |
|
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() : void { |
|
52 | + public function runAll () : void { |
|
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 ) : void { |
|
61 | + public function runTask ( string $task ) : void { |
|
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 ) : void { |
|
70 | + public function runSubtask ( string $subtask ) : void { |
|
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; |
4 | 4 | |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * @return bool |
59 | 59 | */ |
60 | - public static function isCLI() : bool { |
|
60 | + public static function isCLI () : bool { |
|
61 | 61 | return PHP_SAPI === 'cli'; |
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Populate options and check for required ones |
66 | 66 | */ |
67 | - public function __construct() { |
|
67 | + public function __construct () { |
|
68 | 68 | $opts = getopt( self::SHORT_OPTS, self::LONG_OPTS ); |
69 | 69 | $this->checkRequiredOpts( $opts ); |
70 | 70 | $this->checkConflictingOpts( $opts ); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | /** |
76 | 76 | * @param array $opts |
77 | 77 | */ |
78 | - private function checkRequiredOpts( array $opts ) : void { |
|
78 | + private function checkRequiredOpts ( array $opts ) : void { |
|
79 | 79 | $missingOpts = array_diff( self::REQUIRED_OPTS, array_keys( $opts ) ); |
80 | 80 | if ( $missingOpts ) { |
81 | 81 | exit( 'Required options missing: ' . implode( ', ', $missingOpts ) ); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | /** |
92 | 92 | * @param array $opts |
93 | 93 | */ |
94 | - private function checkConflictingOpts( array $opts ) : void { |
|
94 | + private function checkConflictingOpts ( array $opts ) : void { |
|
95 | 95 | $hasPw = array_key_exists( 'password', $opts ); |
96 | 96 | $hasPwFile = array_key_exists( 'use-password-file', $opts ); |
97 | 97 | if ( $hasPw && $hasPwFile ) { |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | /** |
109 | 109 | * @param array &$opts |
110 | 110 | */ |
111 | - private function canonicalize( array &$opts ) : void { |
|
111 | + private function canonicalize ( array &$opts ) : void { |
|
112 | 112 | if ( array_key_exists( 'use-password-file', $opts ) ) { |
113 | 113 | $pw = trim( file_get_contents( self::PASSWORD_FILE ) ); |
114 | - $opts['password'] = $pw; |
|
115 | - unset( $opts['use-password-file'] ); |
|
114 | + $opts[ 'password' ] = $pw; |
|
115 | + unset( $opts[ 'use-password-file' ] ); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * These are the options required by Config. |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - public function getMainOpts() : array { |
|
123 | + public function getMainOpts () : array { |
|
124 | 124 | return array_intersect_key( |
125 | 125 | $this->opts, |
126 | 126 | array_fill_keys( Config::REQUIRED_OPTS, true ) |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | * @param mixed|null $default |
133 | 133 | * @return mixed |
134 | 134 | */ |
135 | - public function getOpt( string $opt, $default = null ) { |
|
136 | - return $this->opts[$opt] ?? $default; |
|
135 | + public function getOpt ( string $opt, $default = null ) { |
|
136 | + return $this->opts[ $opt ] ?? $default; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @return array Either [ 'task' => taskname ] or [ 'subtask' => subtaskname ] |
141 | 141 | */ |
142 | - public function getTaskOpt() : array { |
|
142 | + public function getTaskOpt () : array { |
|
143 | 143 | return array_intersect_key( |
144 | 144 | $this->opts, |
145 | 145 | [ 'task' => true, 'subtask' => true ] |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | /** |
150 | 150 | * @return string|null |
151 | 151 | */ |
152 | - public function getURL() : ?string { |
|
152 | + public function getURL () : ?string { |
|
153 | 153 | return $this->getOpt( 'force-url' ); |
154 | 154 | } |
155 | 155 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Request; |
4 | 4 | |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | /** @var string */ |
31 | 31 | protected $method = 'GET'; |
32 | 32 | /** @var string[] */ |
33 | - protected $newCookies = []; |
|
33 | + protected $newCookies = [ ]; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Use self::newFromParams, which will provide the right class to use |
37 | 37 | * |
38 | 38 | * @param array $params |
39 | 39 | */ |
40 | - protected function __construct( array $params ) { |
|
40 | + protected function __construct ( array $params ) { |
|
41 | 41 | $this->params = [ 'format' => 'json' ] + $params; |
42 | 42 | $this->url = DEFAULT_URL; |
43 | 43 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param array $params |
49 | 49 | * @return self |
50 | 50 | */ |
51 | - public static function newFromParams( array $params ) : self { |
|
51 | + public static function newFromParams ( array $params ) : self { |
|
52 | 52 | if ( extension_loaded( 'curl' ) ) { |
53 | 53 | $ret = new CurlRequest( $params ); |
54 | 54 | } else { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return self For chaining |
64 | 64 | */ |
65 | - public function setPost() : self { |
|
65 | + public function setPost () : self { |
|
66 | 66 | $this->method = 'POST'; |
67 | 67 | return $this; |
68 | 68 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param string $url |
74 | 74 | * @return self for chaining |
75 | 75 | */ |
76 | - public function setUrl( string $url ) : self { |
|
76 | + public function setUrl ( string $url ) : self { |
|
77 | 77 | $this->url = $url; |
78 | 78 | return $this; |
79 | 79 | } |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | * @todo Return an iterable object which automatically continues the query only if the last |
86 | 86 | * entry available is reached. |
87 | 87 | */ |
88 | - public function execute() : \stdClass { |
|
88 | + public function execute () : \stdClass { |
|
89 | 89 | $curParams = $this->params; |
90 | - $sets = []; |
|
90 | + $sets = [ ]; |
|
91 | 91 | do { |
92 | 92 | $res = $this->makeRequestInternal( $curParams ); |
93 | 93 | |
94 | 94 | $this->handleErrorAndWarnings( $res ); |
95 | - $sets[] = $res; |
|
95 | + $sets[ ] = $res; |
|
96 | 96 | |
97 | 97 | $finished = true; |
98 | 98 | if ( isset( $res->continue ) ) { |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * @param array $params |
111 | 111 | * @return \stdClass |
112 | 112 | */ |
113 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
113 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
114 | 114 | if ( $this->method === 'POST' ) { |
115 | - $params['maxlag'] = self::MAXLAG; |
|
115 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
116 | 116 | } |
117 | 117 | $query = http_build_query( $params ); |
118 | 118 | |
@@ -128,17 +128,17 @@ discard block |
||
128 | 128 | * @param string $params |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
131 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * After a request, set cookies for the next ones |
135 | 135 | * |
136 | 136 | * @param array $cookies |
137 | 137 | */ |
138 | - protected function setCookies( array $cookies ) : void { |
|
138 | + protected function setCookies ( array $cookies ) : void { |
|
139 | 139 | foreach ( $cookies as $cookie ) { |
140 | 140 | $bits = explode( ';', $cookie ); |
141 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
141 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
142 | 142 | self::$cookiesToSet[ $name ] = $value; |
143 | 143 | } |
144 | 144 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param \stdClass $res |
150 | 150 | * @return APIRequestException |
151 | 151 | */ |
152 | - private function getException( \stdClass $res ) : APIRequestException { |
|
152 | + private function getException ( \stdClass $res ) : APIRequestException { |
|
153 | 153 | switch ( $res->error->code ) { |
154 | 154 | case 'missingtitle': |
155 | 155 | $ex = new MissingPageException; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param \stdClass $res |
173 | 173 | * @throws APIRequestException |
174 | 174 | */ |
175 | - protected function handleErrorAndWarnings( \stdClass $res ) : void { |
|
175 | + protected function handleErrorAndWarnings ( \stdClass $res ) : void { |
|
176 | 176 | if ( isset( $res->error ) ) { |
177 | 177 | throw $this->getException( $res ); |
178 | 178 | } elseif ( isset( $res->warnings ) ) { |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @param \stdClass[] $sets |
189 | 189 | * @return \stdClass |
190 | 190 | */ |
191 | - private function mergeSets( array $sets ) : \stdClass { |
|
191 | + private function mergeSets ( array $sets ) : \stdClass { |
|
192 | 192 | // Use the first set as template |
193 | 193 | $ret = array_shift( $sets ); |
194 | 194 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @param array|\stdClass $second |
206 | 206 | * @return array|\stdClass array |
207 | 207 | */ |
208 | - private function recursiveMerge( $first, $second ) { |
|
208 | + private function recursiveMerge ( $first, $second ) { |
|
209 | 209 | $ret = $first; |
210 | 210 | if ( is_array( $second ) ) { |
211 | 211 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -223,14 +223,14 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return array |
225 | 225 | */ |
226 | - protected function getHeaders() :array { |
|
226 | + protected function getHeaders () :array { |
|
227 | 227 | $ret = self::HEADERS; |
228 | 228 | if ( self::$cookiesToSet ) { |
229 | - $cookies = []; |
|
229 | + $cookies = [ ]; |
|
230 | 230 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
231 | - $cookies[] = trim( "$cname=$cval" ); |
|
231 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
232 | 232 | } |
233 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
233 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
234 | 234 | } |
235 | 235 | return $ret; |
236 | 236 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param array $headers |
242 | 242 | * @return string |
243 | 243 | */ |
244 | - protected function buildHeadersString( array $headers ) : string { |
|
244 | + protected function buildHeadersString ( array $headers ) : string { |
|
245 | 245 | $ret = ''; |
246 | 246 | foreach ( $headers as $header ) { |
247 | 247 | $ret .= "$header\r\n"; |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Exception; |
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; |
4 | 4 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** @var self */ |
22 | 22 | private static $instance; |
23 | 23 | /** @var array */ |
24 | - private $opts = []; |
|
24 | + private $opts = [ ]; |
|
25 | 25 | /** @var array|null Lazy-loaded to avoid unnecessary requests */ |
26 | 26 | private $messages; |
27 | 27 | /** @var Wiki */ |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @param Wiki $wiki |
34 | 34 | */ |
35 | - private function __construct( Wiki $wiki ) { |
|
35 | + private function __construct ( Wiki $wiki ) { |
|
36 | 36 | $this->wiki = $wiki; |
37 | 37 | } |
38 | 38 | |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | * @param Wiki $wiki |
44 | 44 | * @throws ConfigException |
45 | 45 | */ |
46 | - public static function init( array $defaults, Wiki $wiki ) : void { |
|
46 | + public static function init ( array $defaults, Wiki $wiki ) : void { |
|
47 | 47 | if ( self::$instance ) { |
48 | 48 | throw new ConfigException( 'Config was already initialized' ); |
49 | 49 | } |
50 | 50 | |
51 | 51 | $inst = new self( $wiki ); |
52 | - $inst->set( 'list-title', $defaults['list-title'] ); |
|
53 | - $inst->set( 'msg-title', $defaults['msg-title'] ); |
|
54 | - $inst->set( 'username', $defaults['username'] ); |
|
55 | - $inst->set( 'password', $defaults['password'] ); |
|
52 | + $inst->set( 'list-title', $defaults[ 'list-title' ] ); |
|
53 | + $inst->set( 'msg-title', $defaults[ 'msg-title' ] ); |
|
54 | + $inst->set( 'username', $defaults[ 'username' ] ); |
|
55 | + $inst->set( 'password', $defaults[ 'password' ] ); |
|
56 | 56 | |
57 | 57 | // On-wiki values |
58 | 58 | try { |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @return string |
73 | 73 | * @throws ConfigException |
74 | 74 | */ |
75 | - public function getWikiMessage( string $key ) : string { |
|
75 | + public function getWikiMessage ( string $key ) : string { |
|
76 | 76 | if ( $this->messages === null ) { |
77 | 77 | try { |
78 | 78 | $cont = $this->wiki->getPageContent( $this->opts[ 'msg-title' ] ); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | if ( !isset( $this->messages[ $key ] ) ) { |
85 | 85 | throw new ConfigException( "Message '$key' does not exist." ); |
86 | 86 | } |
87 | - return $this->messages[$key]; |
|
87 | + return $this->messages[ $key ]; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param string $key |
94 | 94 | * @param mixed $value |
95 | 95 | */ |
96 | - protected function set( string $key, $value ) : void { |
|
96 | + protected function set ( string $key, $value ) : void { |
|
97 | 97 | $this->opts[ $key ] = $value; |
98 | 98 | } |
99 | 99 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @return self |
104 | 104 | * @throws ConfigException |
105 | 105 | */ |
106 | - public static function getInstance() : self { |
|
106 | + public static function getInstance () : self { |
|
107 | 107 | if ( !self::$instance ) { |
108 | 108 | throw new ConfigException( 'Config not yet initialized' ); |
109 | 109 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @return mixed |
118 | 118 | * @throws ConfigException |
119 | 119 | */ |
120 | - public function get( string $opt ) { |
|
120 | + public function get ( string $opt ) { |
|
121 | 121 | if ( !isset( $this->opts[ $opt ] ) ) { |
122 | 122 | throw new ConfigException( "Config option '$opt' not set." ); |
123 | 123 | } |