@@ -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 | |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * @return bool |
67 | 67 | */ |
68 | - public static function isCLI() : bool { |
|
68 | + public static function isCLI () : bool { |
|
69 | 69 | return PHP_SAPI === 'cli'; |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Populate options and check for required ones |
74 | 74 | */ |
75 | - public function __construct() { |
|
75 | + public function __construct () { |
|
76 | 76 | $opts = getopt( self::SHORT_OPTS, self::LONG_OPTS ); |
77 | 77 | $this->checkRequiredOpts( $opts ); |
78 | 78 | $this->checkConflictingOpts( $opts ); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @param string[] $opts |
85 | 85 | */ |
86 | - private function checkRequiredOpts( array $opts ) : void { |
|
86 | + private function checkRequiredOpts ( array $opts ) : void { |
|
87 | 87 | $missingOpts = array_diff( self::REQUIRED_OPTS, array_keys( $opts ) ); |
88 | 88 | if ( $missingOpts ) { |
89 | 89 | $this->fatal( 'Required options missing: ' . implode( ', ', $missingOpts ) ); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | /** |
106 | 106 | * @param string[] $opts |
107 | 107 | */ |
108 | - private function checkConflictingOpts( array $opts ) : void { |
|
108 | + private function checkConflictingOpts ( array $opts ) : void { |
|
109 | 109 | $this->checkNotBothSet( $opts, 'password', 'use-password-file' ); |
110 | 110 | if ( array_key_exists( 'use-password-file', $opts ) && !file_exists( self::PASSWORD_FILE ) ) { |
111 | 111 | $this->fatal( 'Please create the password file (' . self::PASSWORD_FILE . ')' ); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param string $first |
127 | 127 | * @param string $second |
128 | 128 | */ |
129 | - private function checkNotBothSet( array $opts, string $first, string $second ) : void { |
|
129 | + private function checkNotBothSet ( array $opts, string $first, string $second ) : void { |
|
130 | 130 | if ( array_key_exists( $first, $opts ) && array_key_exists( $second, $opts ) ) { |
131 | 131 | $this->fatal( "Can only use one of '$first' and '$second'" ); |
132 | 132 | } |
@@ -135,23 +135,23 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * @param string[] &$opts |
137 | 137 | */ |
138 | - private function canonicalize( array &$opts ) : void { |
|
138 | + private function canonicalize ( array &$opts ) : void { |
|
139 | 139 | if ( array_key_exists( 'use-password-file', $opts ) ) { |
140 | 140 | $pw = trim( file_get_contents( self::PASSWORD_FILE ) ); |
141 | - $opts['password'] = $pw; |
|
142 | - unset( $opts['use-password-file'] ); |
|
141 | + $opts[ 'password' ] = $pw; |
|
142 | + unset( $opts[ 'use-password-file' ] ); |
|
143 | 143 | } |
144 | 144 | if ( array_key_exists( 'use-private-password-file', $opts ) ) { |
145 | 145 | $pw = trim( file_get_contents( self::PRIVATE_PASSWORD_FILE ) ); |
146 | - $opts['private-password'] = $pw; |
|
147 | - unset( $opts['use-private-password-file'] ); |
|
146 | + $opts[ 'private-password' ] = $pw; |
|
147 | + unset( $opts[ 'use-private-password-file' ] ); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
152 | 152 | * @param string $msg |
153 | 153 | */ |
154 | - private function fatal( string $msg ) : void { |
|
154 | + private function fatal ( string $msg ) : void { |
|
155 | 155 | exit( $msg . "\n" ); |
156 | 156 | } |
157 | 157 | |
@@ -160,14 +160,14 @@ discard block |
||
160 | 160 | * @param mixed|null $default |
161 | 161 | * @return mixed |
162 | 162 | */ |
163 | - public function getOpt( string $opt, $default = null ) { |
|
164 | - return $this->opts[$opt] ?? $default; |
|
163 | + public function getOpt ( string $opt, $default = null ) { |
|
164 | + return $this->opts[ $opt ] ?? $default; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | 168 | * @return string[] Either [ 'task' => taskname ] or [ 'subtask' => subtaskname ] |
169 | 169 | */ |
170 | - public function getTaskOpt() : array { |
|
170 | + public function getTaskOpt () : array { |
|
171 | 171 | return array_intersect_key( |
172 | 172 | $this->opts, |
173 | 173 | [ 'task' => true, 'subtask' => true ] |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | /** |
178 | 178 | * @return string|null |
179 | 179 | */ |
180 | - public function getURL() : ?string { |
|
180 | + public function getURL () : ?string { |
|
181 | 181 | return $this->getOpt( 'force-url' ); |
182 | 182 | } |
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\Logger; |
4 | 4 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string $summary |
30 | 30 | * @param string $minlevel |
31 | 31 | */ |
32 | - public function __construct( Page $logPage, string $summary, $minlevel = LogLevel::INFO ) { |
|
32 | + public function __construct ( Page $logPage, string $summary, $minlevel = LogLevel::INFO ) { |
|
33 | 33 | $this->minLevel = $this->levelToInt( $minlevel ); |
34 | 34 | $this->logPage = $logPage; |
35 | 35 | $this->summary = $summary; |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | * @inheritDoc |
40 | 40 | * @suppress PhanUnusedPublicMethodParameter,PhanPluginUnknownArrayMethodParamType |
41 | 41 | */ |
42 | - public function log( $level, $message, array $context = [] ) :void { |
|
42 | + public function log ( $level, $message, array $context = [ ] ) :void { |
|
43 | 43 | if ( $this->levelToInt( $level ) >= $this->minLevel ) { |
44 | - $this->buffer[] = $this->getFormattedMessage( $level, $message ); |
|
44 | + $this->buffer[ ] = $this->getFormattedMessage( $level, $message ); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - protected function getOutput() : string { |
|
51 | + protected function getOutput () : string { |
|
52 | 52 | $line = str_repeat( '-', 80 ); |
53 | 53 | return "\n\n" . implode( "\n", $this->buffer ) . "\n$line\n\n"; |
54 | 54 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * @inheritDoc |
58 | 58 | */ |
59 | - public function flush() : void { |
|
59 | + public function flush () : void { |
|
60 | 60 | if ( $this->buffer ) { |
61 | 61 | $this->logPage->edit( [ |
62 | 62 | '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 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @param IFlushingAwareLogger ...$loggers |
16 | 16 | */ |
17 | - public function __construct( IFlushingAwareLogger ...$loggers ) { |
|
17 | + public function __construct ( IFlushingAwareLogger ...$loggers ) { |
|
18 | 18 | $this->loggers = $loggers; |
19 | 19 | } |
20 | 20 | |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @inheritDoc |
23 | 23 | * @suppress PhanUnusedPublicMethodParameter,PhanPluginUnknownArrayMethodParamType |
24 | 24 | */ |
25 | - public function log( $level, $message, array $context = [] ) :void { |
|
25 | + public function log ( $level, $message, array $context = [ ] ) :void { |
|
26 | 26 | foreach ( $this->loggers as $logger ) { |
27 | 27 | $logger->log( $level, $message ); |
28 | 28 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @inheritDoc |
33 | 33 | */ |
34 | - public function flush() : void { |
|
34 | + public function flush () : void { |
|
35 | 35 | foreach ( $this->loggers as $logger ) { |
36 | 36 | $logger->flush(); |
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 | |
@@ -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,PhanPluginUnknownArrayMethodParamType |
27 | 27 | */ |
28 | - public function log( $level, $message, array $context = [] ) : void { |
|
28 | + public function log ( $level, $message, array $context = [ ] ) : void { |
|
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\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 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @phan-param list<int|string> $args |
33 | 33 | * @return self |
34 | 34 | */ |
35 | - public function params( array $args ) : self { |
|
35 | + public function params ( array $args ) : self { |
|
36 | 36 | $this->value = strtr( $this->value, $args ); |
37 | 37 | return $this; |
38 | 38 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * @return string |
42 | 42 | */ |
43 | - public function text() : string { |
|
43 | + public function text () : string { |
|
44 | 44 | $this->parsePlurals(); |
45 | 45 | return $this->value; |
46 | 46 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * Replace {{$plur|<amount>|sing|plur}} |
50 | 50 | */ |
51 | - protected function parsePlurals() : void { |
|
51 | + protected function parsePlurals () : void { |
|
52 | 52 | $reg = '!\{\{\$plur\|(?P<amount>\d+)\|(?P<sing>[^}|]+)\|(?P<plur>[^|}]+)}}!'; |
53 | 53 | |
54 | 54 | if ( preg_match( $reg, $this->value ) === 0 ) { |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | static function ( array $matches ) : string { |
64 | - return (int)$matches['amount'] > 1 ? trim( $matches['plur'] ) : trim( $matches['sing'] ); |
|
64 | + return (int)$matches[ 'amount' ] > 1 ? trim( $matches[ 'plur' ] ) : trim( $matches[ 'sing' ] ); |
|
65 | 65 | }, |
66 | 66 | $this->value |
67 | 67 | ); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param string $timeString Full format, e.g. "15 aprile 2019 18:27" |
74 | 74 | * @return int |
75 | 75 | */ |
76 | - public static function getTimestampFromLocalTime( string $timeString ) : int { |
|
76 | + public static function getTimestampFromLocalTime ( string $timeString ) : int { |
|
77 | 77 | $englishTime = str_ireplace( |
78 | 78 | array_values( self::MONTHS ), |
79 | 79 | array_keys( self::MONTHS ), |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | * @param string $emptyText |
93 | 93 | * @return string |
94 | 94 | */ |
95 | - public static function commaList( array $data, string $emptyText = 'nessuno' ) : string { |
|
95 | + public static function commaList ( array $data, string $emptyText = 'nessuno' ) : string { |
|
96 | 96 | if ( count( $data ) > 1 ) { |
97 | 97 | $last = array_pop( $data ); |
98 | 98 | $ret = implode( ', ', $data ) . " e $last"; |
99 | 99 | } elseif ( $data ) { |
100 | - $ret = (string)$data[0]; |
|
100 | + $ret = (string)$data[ 0 ]; |
|
101 | 101 | } else { |
102 | 102 | $ret = $emptyText; |
103 | 103 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | return $ret; |
106 | 106 | } |
107 | 107 | |
108 | - public function __toString() { |
|
108 | + public function __toString () { |
|
109 | 109 | return $this->text(); |
110 | 110 | } |
111 | 111 | } |
@@ -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,12 +11,12 @@ discard block |
||
11 | 11 | /** @var self */ |
12 | 12 | private static $instance; |
13 | 13 | /** @var string[] */ |
14 | - private $opts = []; |
|
14 | + private $opts = [ ]; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Use self::init() and self::getInstance() |
18 | 18 | */ |
19 | - private function __construct() { |
|
19 | + private function __construct () { |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param string[] $confValues |
26 | 26 | * @throws ConfigException |
27 | 27 | */ |
28 | - public static function init( array $confValues ) : void { |
|
28 | + public static function init ( array $confValues ) : void { |
|
29 | 29 | if ( self::$instance ) { |
30 | 30 | throw new ConfigException( 'Config was already initialized' ); |
31 | 31 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param string $key |
45 | 45 | * @param mixed $value |
46 | 46 | */ |
47 | - protected function set( string $key, $value ) : void { |
|
47 | + protected function set ( string $key, $value ) : void { |
|
48 | 48 | $this->opts[ $key ] = $value; |
49 | 49 | } |
50 | 50 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return self |
55 | 55 | * @throws ConfigException |
56 | 56 | */ |
57 | - public static function getInstance() : self { |
|
57 | + public static function getInstance () : self { |
|
58 | 58 | if ( !self::$instance ) { |
59 | 59 | throw new ConfigException( 'Config not yet initialized' ); |
60 | 60 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return mixed |
69 | 69 | * @throws ConfigException |
70 | 70 | */ |
71 | - public function get( string $opt ) { |
|
71 | + public function get ( string $opt ) { |
|
72 | 72 | if ( !isset( $this->opts[ $opt ] ) ) { |
73 | 73 | throw new ConfigException( "Config option '$opt' not set." ); |
74 | 74 | } |