@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | private $supportSection; |
14 | 14 | private $opposeSection; |
15 | 15 | /** @var array Counts of votes for each section */ |
16 | - private $sectionCounts = []; |
|
16 | + private $sectionCounts = [ ]; |
|
17 | 17 | |
18 | 18 | // Possible outcomes of a vote |
19 | 19 | public const OUTCOME_OK = 0; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * because they can vary depending on whether the page is a vote, which is relatively |
33 | 33 | * expensive to know since it requires parsing the content of the page. |
34 | 34 | */ |
35 | - private function defineSections() : void { |
|
35 | + private function defineSections () : void { |
|
36 | 36 | $this->supportSection = $this->isVote() ? 3 : 0; |
37 | 37 | $this->opposeSection = $this->isVote() ? 4 : 3; |
38 | 38 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return User |
44 | 44 | */ |
45 | - public function getUser() : User { |
|
46 | - $name = explode( '/', $this->title )[2]; |
|
45 | + public function getUser () : User { |
|
46 | + $name = explode( '/', $this->title )[ 2 ]; |
|
47 | 47 | return new User( $name, $this->wiki ); |
48 | 48 | } |
49 | 49 | |
@@ -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 ); |
@@ -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; |
4 | 4 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param LoggerInterface $logger |
29 | 29 | * @param string $domain The URL of the wiki, if different from default |
30 | 30 | */ |
31 | - public function __construct( LoggerInterface $logger, string $domain = DEFAULT_URL ) { |
|
31 | + public function __construct ( LoggerInterface $logger, string $domain = DEFAULT_URL ) { |
|
32 | 32 | $this->logger = $logger; |
33 | 33 | $this->domain = $domain; |
34 | 34 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @throws MissingPageException |
43 | 43 | * @throws MissingSectionException |
44 | 44 | */ |
45 | - public function getPageContent( string $title, int $section = null ) : string { |
|
45 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
46 | 46 | $msg = "Retrieving content of $title" . ( $section !== null ? ", section $section" : '' ); |
47 | 47 | $this->logger->debug( $msg ); |
48 | 48 | $params = [ |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | ]; |
55 | 55 | |
56 | 56 | if ( $section !== null ) { |
57 | - $params['rvsection'] = $section; |
|
57 | + $params[ 'rvsection' ] = $section; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $req = $this->buildRequest( $params ); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | throw new MissingPageException( $title ); |
65 | 65 | } |
66 | 66 | |
67 | - $mainSlot = $page->revisions[0]->slots->main; |
|
67 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
68 | 68 | |
69 | 69 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
70 | 70 | throw new MissingSectionException( $title, $section ); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param array $params |
79 | 79 | * @throws EditException |
80 | 80 | */ |
81 | - public function editPage( array $params ) : void { |
|
81 | + public function editPage ( array $params ) : void { |
|
82 | 82 | $this->login(); |
83 | 83 | |
84 | 84 | $params = [ |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | ] + $params; |
88 | 88 | |
89 | 89 | if ( Config::getInstance()->get( 'bot-edits' ) ) { |
90 | - $params['bot'] = 1; |
|
90 | + $params[ 'bot' ] = 1; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $res = $this->buildRequest( $params )->setPost()->execute(); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
106 | 106 | * @throws LoginException |
107 | 107 | */ |
108 | - public function login() : void { |
|
108 | + public function login () : void { |
|
109 | 109 | if ( self::$loggedIn ) { |
110 | 110 | return; |
111 | 111 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | self::$loggedIn = true; |
134 | 134 | // Clear tokens cache |
135 | - $this->tokens = []; |
|
135 | + $this->tokens = [ ]; |
|
136 | 136 | $this->logger->info( 'Login succeeded' ); |
137 | 137 | } |
138 | 138 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string $type |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function getToken( string $type ) : string { |
|
145 | + public function getToken ( string $type ) : string { |
|
146 | 146 | if ( !isset( $this->tokens[ $type ] ) ) { |
147 | 147 | $params = [ |
148 | 148 | 'action' => 'query', |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param string $title |
166 | 166 | * @return int |
167 | 167 | */ |
168 | - public function getPageCreationTS( string $title ) : int { |
|
168 | + public function getPageCreationTS ( string $title ) : int { |
|
169 | 169 | $params = [ |
170 | 170 | 'action' => 'query', |
171 | 171 | 'prop' => 'revisions', |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | |
179 | 179 | $res = $this->buildRequest( $params )->execute(); |
180 | 180 | $data = $res->query->pages; |
181 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
181 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param string $title |
188 | 188 | * @param string $reason |
189 | 189 | */ |
190 | - public function protectPage( string $title, string $reason ) : void { |
|
190 | + public function protectPage ( string $title, string $reason ) : void { |
|
191 | 191 | $this->logger->info( "Protecting page $title" ); |
192 | 192 | $this->login(); |
193 | 193 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @param array $params |
209 | 209 | * @return RequestBase |
210 | 210 | */ |
211 | - private function buildRequest( array $params ) : RequestBase { |
|
211 | + private function buildRequest ( array $params ) : RequestBase { |
|
212 | 212 | return RequestBase::newFromParams( $params )->setUrl( $this->domain ); |
213 | 213 | } |
214 | 214 | } |
@@ -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; |
4 | 4 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @param string $name |
21 | 21 | * @param Wiki $wiki |
22 | 22 | */ |
23 | - public function __construct( string $name, Wiki $wiki ) { |
|
23 | + public function __construct ( string $name, Wiki $wiki ) { |
|
24 | 24 | parent::__construct( $wiki ); |
25 | 25 | $this->name = $name; |
26 | 26 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function getName() : string { |
|
31 | + public function getName () : string { |
|
32 | 32 | return $this->name; |
33 | 33 | } |
34 | 34 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return string[] |
39 | 39 | */ |
40 | - public function getGroups() : array { |
|
40 | + public function getGroups () : array { |
|
41 | 41 | return array_diff( array_keys( $this->getUserInfo() ), PageBotList::NON_GROUP_KEYS ); |
42 | 42 | } |
43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return string[] [ group => date ] |
48 | 48 | */ |
49 | - public function getGroupsWithDates() : array { |
|
49 | + public function getGroupsWithDates () : array { |
|
50 | 50 | return array_intersect_key( $this->getUserInfo(), array_fill_keys( $this->getGroups(), 1 ) ); |
51 | 51 | } |
52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return string[] |
57 | 57 | */ |
58 | - public function getUserInfo() : array { |
|
58 | + public function getUserInfo () : array { |
|
59 | 59 | if ( $this->info === null ) { |
60 | 60 | $usersList = PageBotList::get( $this->wiki )->getAdminsList(); |
61 | 61 | $this->info = $usersList[ $this->name ]->getUserInfo(); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | /** |
67 | 67 | * @param array|null $info |
68 | 68 | */ |
69 | - public function setInfo( ?array $info ) : void { |
|
69 | + public function setInfo ( ?array $info ) : void { |
|
70 | 70 | $this->info = $info; |
71 | 71 | } |
72 | 72 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param string $groupName |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - public function inGroup( string $groupName ) : bool { |
|
79 | + public function inGroup ( string $groupName ) : bool { |
|
80 | 80 | return in_array( $groupName, $this->getGroups(), true ); |
81 | 81 | } |
82 | 82 | |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @inheritDoc |
87 | 87 | */ |
88 | - public function getRegex( string $delimiter = '/' ) : string { |
|
88 | + public function getRegex ( string $delimiter = '/' ) : string { |
|
89 | 89 | $bits = $this->getAliases(); |
90 | - $bits[] = $this->name; |
|
90 | + $bits[ ] = $this->name; |
|
91 | 91 | $regexify = static function ( $el ) use ( $delimiter ) { |
92 | 92 | return str_replace( ' ', '[ _]', preg_quote( $el, $delimiter ) ); |
93 | 93 | }; |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return string[] |
101 | 101 | */ |
102 | - public function getAliases() : array { |
|
103 | - return $this->getUserInfo()['aliases'] ?? []; |
|
102 | + public function getAliases () : array { |
|
103 | + return $this->getUserInfo()[ 'aliases' ] ?? [ ]; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @return Page |
108 | 108 | */ |
109 | - public function getTalkPage() : Page { |
|
109 | + public function getTalkPage () : Page { |
|
110 | 110 | return new Page( "User talk:{$this->name}", $this->wiki ); |
111 | 111 | } |
112 | 112 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * Get the default base page, e.g. WP:A/Riconferma annuale/XXX |
115 | 115 | * @return Page |
116 | 116 | */ |
117 | - public function getBasePage() : Page { |
|
117 | + public function getBasePage () : Page { |
|
118 | 118 | $prefix = Config::getInstance()->get( 'main-page-title' ); |
119 | 119 | return new Page( "$prefix/$this", $this->wiki ); |
120 | 120 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @throws MissingPageException |
127 | 127 | * @return Page |
128 | 128 | */ |
129 | - public function getExistingBasePage() : Page { |
|
129 | + public function getExistingBasePage () : Page { |
|
130 | 130 | $basePage = $this->getBasePage(); |
131 | 131 | if ( !$basePage->exists() ) { |
132 | 132 | $basePage = null; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | /** |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function __toString() { |
|
153 | + public function __toString () { |
|
154 | 154 | return $this->name; |
155 | 155 | } |
156 | 156 | } |
@@ -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; |
4 | 4 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * @param Wiki $wiki |
14 | 14 | */ |
15 | - public function __construct( Wiki $wiki ) { |
|
15 | + public function __construct ( Wiki $wiki ) { |
|
16 | 16 | $this->wiki = $wiki; |
17 | 17 | } |
18 | 18 | |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @param string $delimiter |
23 | 23 | * @return string |
24 | 24 | */ |
25 | - abstract public function getRegex( string $delimiter = '/' ) : string; |
|
25 | + abstract public function getRegex ( string $delimiter = '/' ) : string; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Get a regex matching any element in the given array |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * @return string |
33 | 33 | * @todo Is this the right place? |
34 | 34 | */ |
35 | - public static function regexFromArray( array $elements, string $delimiter = '/' ) : string { |
|
36 | - $bits = []; |
|
35 | + public static function regexFromArray ( array $elements, string $delimiter = '/' ) : string { |
|
36 | + $bits = [ ]; |
|
37 | 37 | foreach ( $elements as $el ) { |
38 | - $bits[] = $el->getRegex( $delimiter ); |
|
38 | + $bits[ ] = $el->getRegex( $delimiter ); |
|
39 | 39 | } |
40 | 40 | return '(?:' . implode( '|', $bits ) . ')'; |
41 | 41 | } |
@@ -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 | * @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; |
4 | 4 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @param string $key |
28 | 28 | */ |
29 | - public function __construct( string $key ) { |
|
29 | + public function __construct ( string $key ) { |
|
30 | 30 | $this->value = Config::getInstance()->getWikiMessage( $key ); |
31 | 31 | } |
32 | 32 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param array $args |
35 | 35 | * @return self |
36 | 36 | */ |
37 | - public function params( array $args ) : self { |
|
37 | + public function params ( array $args ) : self { |
|
38 | 38 | $this->value = strtr( $this->value, $args ); |
39 | 39 | return $this; |
40 | 40 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function text() : string { |
|
45 | + public function text () : string { |
|
46 | 46 | $this->parsePlurals(); |
47 | 47 | return $this->value; |
48 | 48 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * Replace {{$plur|<amount>|sing|plur}} |
52 | 52 | */ |
53 | - protected function parsePlurals() : void { |
|
53 | + protected function parsePlurals () : void { |
|
54 | 54 | $reg = '!\{\{\$plur\|(?P<amount>\d+)\|(?P<sing>[^}|]+)\|(?P<plur>[^|}]+)}}!'; |
55 | 55 | |
56 | 56 | if ( preg_match( $reg, $this->value ) === 0 ) { |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $this->value = preg_replace_callback( |
60 | 60 | $reg, |
61 | 61 | static function ( $matches ) { |
62 | - return (int)$matches['amount'] > 1 ? trim( $matches['plur'] ) : trim( $matches['sing'] ); |
|
62 | + return (int)$matches[ 'amount' ] > 1 ? trim( $matches[ 'plur' ] ) : trim( $matches[ 'sing' ] ); |
|
63 | 63 | }, |
64 | 64 | $this->value |
65 | 65 | ); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param string $timeString Full format, e.g. "15 aprile 2019 18:27" |
72 | 72 | * @return int |
73 | 73 | */ |
74 | - public static function getTimestampFromLocalTime( string $timeString ) : int { |
|
74 | + public static function getTimestampFromLocalTime ( string $timeString ) : int { |
|
75 | 75 | $englishTime = str_ireplace( |
76 | 76 | array_values( self::MONTHS ), |
77 | 77 | array_keys( self::MONTHS ), |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | * @param string $emptyText |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - public static function commaList( array $data, string $emptyText = 'nessuno' ) : string { |
|
92 | + public static function commaList ( array $data, string $emptyText = 'nessuno' ) : string { |
|
93 | 93 | if ( count( $data ) > 1 ) { |
94 | 94 | $last = array_pop( $data ); |
95 | 95 | $ret = implode( ', ', $data ) . " e $last"; |
96 | 96 | } elseif ( $data ) { |
97 | - $ret = (string)$data[0]; |
|
97 | + $ret = (string)$data[ 0 ]; |
|
98 | 98 | } else { |
99 | 99 | $ret = $emptyText; |
100 | 100 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | return $ret; |
103 | 103 | } |
104 | 104 | |
105 | - public function __toString() { |
|
105 | + public function __toString () { |
|
106 | 106 | return $this->text(); |
107 | 107 | } |
108 | 108 | } |
@@ -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 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** @var User[]|null */ |
15 | 15 | private $processUsers; |
16 | 16 | /** @var PageRiconferma[] */ |
17 | - private $createdPages = []; |
|
17 | + private $createdPages = [ ]; |
|
18 | 18 | /** @var PageRiconferma[]|null */ |
19 | 19 | private $openPages; |
20 | 20 | /** @var PageRiconferma[]|null */ |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @return User[] |
27 | 27 | */ |
28 | - public function getUsersToProcess() : array { |
|
28 | + public function getUsersToProcess () : array { |
|
29 | 29 | if ( $this->processUsers === null ) { |
30 | - $this->processUsers = []; |
|
30 | + $this->processUsers = [ ]; |
|
31 | 31 | foreach ( PageBotList::get( $this->getWiki() )->getAdminsList() as $name => $user ) { |
32 | 32 | if ( $this->shouldAddUser( $user ) ) { |
33 | 33 | $this->processUsers[ $name ] = $user; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param User $user |
45 | 45 | * @return bool |
46 | 46 | */ |
47 | - private function shouldAddUser( User $user ) : bool { |
|
47 | + private function shouldAddUser ( User $user ) : bool { |
|
48 | 48 | $timestamp = PageBotList::getOverrideTimestamp( $user->getUserInfo() ); |
49 | 49 | $override = $timestamp !== null; |
50 | 50 | |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return PageRiconferma[] |
64 | 64 | */ |
65 | - public function getOpenPages() : array { |
|
65 | + public function getOpenPages () : array { |
|
66 | 66 | if ( $this->openPages === null ) { |
67 | - $this->openPages = []; |
|
67 | + $this->openPages = [ ]; |
|
68 | 68 | $mainTitle = $this->getOpt( 'main-page-title' ); |
69 | 69 | $params = [ |
70 | 70 | 'action' => 'query', |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $pages = RequestBase::newFromParams( $params )->execute()->query->pages; |
79 | 79 | foreach ( reset( $pages )->templates as $page ) { |
80 | 80 | if ( preg_match( "!$titleReg/[^/]+/\d!", $page->title ) ) { |
81 | - $this->openPages[] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
81 | + $this->openPages[ ] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return PageRiconferma[] |
93 | 93 | */ |
94 | - public function getPagesToClose() : array { |
|
94 | + public function getPagesToClose () : array { |
|
95 | 95 | if ( $this->pagesToClose === null ) { |
96 | - $this->pagesToClose = []; |
|
96 | + $this->pagesToClose = [ ]; |
|
97 | 97 | foreach ( $this->getOpenPages() as $page ) { |
98 | 98 | if ( time() > $page->getEndTimestamp() ) { |
99 | - $this->pagesToClose[] = $page; |
|
99 | + $this->pagesToClose[ ] = $page; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
@@ -108,21 +108,21 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @param string $name |
110 | 110 | */ |
111 | - public function removeUser( string $name ) : void { |
|
111 | + public function removeUser ( string $name ) : void { |
|
112 | 112 | unset( $this->processUsers[ $name ] ); |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * @return PageRiconferma[] |
117 | 117 | */ |
118 | - public function getCreatedPages() : array { |
|
118 | + public function getCreatedPages () : array { |
|
119 | 119 | return $this->createdPages; |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param PageRiconferma $page |
124 | 124 | */ |
125 | - public function addCreatedPage( PageRiconferma $page ) : void { |
|
126 | - $this->createdPages[] = $page; |
|
125 | + public function addCreatedPage ( PageRiconferma $page ) : void { |
|
126 | + $this->createdPages[ ] = $page; |
|
127 | 127 | } |
128 | 128 | } |
@@ -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 = [] ) : 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\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 |
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 | } |