@@ -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 Use self::get() |
14 | 14 | * @param Controller $controller |
15 | 15 | */ |
16 | - public function __construct( Controller $controller ) { |
|
16 | + public function __construct ( Controller $controller ) { |
|
17 | 17 | parent::__construct( Config::getInstance()->get( 'list-title' ), $controller ); |
18 | 18 | } |
19 | 19 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param Controller $controller |
24 | 24 | * @return self |
25 | 25 | */ |
26 | - public static function get( Controller $controller ) : self { |
|
26 | + public static function get ( Controller $controller ) : self { |
|
27 | 27 | static $instance = null; |
28 | 28 | if ( $instance === null ) { |
29 | 29 | $instance = new self( $controller ); |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | * @param string[] $groups |
36 | 36 | * @return int|null |
37 | 37 | */ |
38 | - public static function getOverrideTimestamp( array $groups ) : ?int { |
|
38 | + public static function getOverrideTimestamp ( array $groups ) : ?int { |
|
39 | 39 | if ( !array_intersect_key( $groups, [ 'override-perm' => true, 'override' => true ] ) ) { |
40 | 40 | return null; |
41 | 41 | } |
42 | 42 | |
43 | 43 | // A one-time override takes precedence |
44 | 44 | if ( array_key_exists( 'override', $groups ) ) { |
45 | - $date = $groups['override']; |
|
45 | + $date = $groups[ 'override' ]; |
|
46 | 46 | } else { |
47 | - $date = $groups['override-prem'] . '/' . date( 'Y' ); |
|
47 | + $date = $groups[ 'override-prem' ] . '/' . date( 'Y' ); |
|
48 | 48 | } |
49 | 49 | return \DateTime::createFromFormat( 'd/m/Y', $date )->getTimestamp(); |
50 | 50 | } |
@@ -55,17 +55,15 @@ discard block |
||
55 | 55 | * @param array $groups |
56 | 56 | * @return int |
57 | 57 | */ |
58 | - public static function getValidFlagTimestamp( array $groups ): int { |
|
59 | - $checkuser = isset( $groups['checkuser'] ) ? |
|
60 | - \DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() : |
|
61 | - 0; |
|
62 | - $bureaucrat = isset( $groups['bureaucrat'] ) ? |
|
63 | - \DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() : |
|
64 | - 0; |
|
58 | + public static function getValidFlagTimestamp ( array $groups ): int { |
|
59 | + $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
60 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
61 | + $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
62 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
65 | 63 | |
66 | 64 | $timestamp = max( $bureaucrat, $checkuser ); |
67 | 65 | if ( $timestamp === 0 ) { |
68 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp(); |
|
66 | + $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
69 | 67 | } |
70 | 68 | return $timestamp; |
71 | 69 | } |
@@ -75,7 +73,7 @@ discard block |
||
75 | 73 | * |
76 | 74 | * @return array[] |
77 | 75 | */ |
78 | - public function getAdminsList() : array { |
|
76 | + public function getAdminsList () : array { |
|
79 | 77 | return json_decode( $this->getContent(), true ); |
80 | 78 | } |
81 | 79 | } |
@@ -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() { |
|
35 | + private function defineSections () { |
|
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->controller ); |
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 intval( 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 string |
73 | 73 | */ |
74 | - public function getBaseTitle() : string { |
|
74 | + public function getBaseTitle () : string { |
|
75 | 75 | return substr( $this->getTitle(), 0, strrpos( $this->getTitle(), '/' ) ); |
76 | 76 | } |
77 | 77 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return int |
82 | 82 | */ |
83 | - public function getOpposingCount() : int { |
|
83 | + public function getOpposingCount () : int { |
|
84 | 84 | $this->defineSections(); |
85 | 85 | return $this->getCountForSection( $this->opposeSection ); |
86 | 86 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return int |
92 | 92 | * @throws \BadMethodCallException |
93 | 93 | */ |
94 | - public function getSupportCount() : int { |
|
94 | + public function getSupportCount () : int { |
|
95 | 95 | if ( !$this->isVote() ) { |
96 | 96 | throw new \BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
97 | 97 | } |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | * @param int $secNum |
106 | 106 | * @return int |
107 | 107 | */ |
108 | - protected function getCountForSection( int $secNum ) : int { |
|
108 | + protected function getCountForSection ( int $secNum ) : int { |
|
109 | 109 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
110 | 110 | $content = $this->controller->getPageContent( $this->title, $secNum ); |
111 | 111 | // Let's hope that this is good enough... |
112 | - $this->sectionCounts[$secNum] = preg_match_all( "/^\# *(?![# *:]|\.\.\.$)/m", $content ); |
|
112 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^\# *(?![# *:]|\.\.\.$)/m", $content ); |
|
113 | 113 | } |
114 | - return $this->sectionCounts[$secNum]; |
|
114 | + return $this->sectionCounts[ $secNum ]; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return int |
121 | 121 | */ |
122 | - protected function getQuorum() : int { |
|
122 | + protected function getQuorum () : int { |
|
123 | 123 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
124 | - return intval( $this->getMatch( $reg )[1] ); |
|
124 | + return intval( $this->getMatch( $reg )[ 1 ] ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return bool |
131 | 131 | */ |
132 | - public function hasOpposition() : bool { |
|
132 | + public function hasOpposition () : bool { |
|
133 | 133 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
134 | 134 | } |
135 | 135 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return int One of the OUTCOME_* constants |
140 | 140 | */ |
141 | - public function getOutcome() : int { |
|
141 | + public function getOutcome () : int { |
|
142 | 142 | if ( !$this->isVote() ) { |
143 | 143 | return self::OUTCOME_OK; |
144 | 144 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @throws \BadMethodCallException |
162 | 162 | * @throws \LogicException |
163 | 163 | */ |
164 | - public function getOutcomeText() : string { |
|
164 | + public function getOutcomeText () : string { |
|
165 | 165 | if ( !$this->isVote() ) { |
166 | 166 | throw new \BadMethodCallException( 'No need for an outcome text.' ); |
167 | 167 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @return bool |
197 | 197 | */ |
198 | - public function isVote() : bool { |
|
198 | + public function isVote () : bool { |
|
199 | 199 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
200 | 200 | return !$this->matches( $sectionReg ); |
201 | 201 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @return int |
207 | 207 | */ |
208 | - public function getCreationTimestamp() : int { |
|
208 | + public function getCreationTimestamp () : int { |
|
209 | 209 | return $this->controller->getPageCreationTS( $this->title ); |
210 | 210 | } |
211 | 211 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @return int |
216 | 216 | */ |
217 | - public function getEndTimestamp() : int { |
|
217 | + public function getEndTimestamp () : int { |
|
218 | 218 | if ( $this->isVote() ) { |
219 | 219 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
220 | 220 | list( , $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 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @param string $name |
18 | 18 | * @param Controller $controller |
19 | 19 | */ |
20 | - public function __construct( string $name, Controller $controller ) { |
|
20 | + public function __construct ( string $name, Controller $controller ) { |
|
21 | 21 | parent::__construct( $controller ); |
22 | 22 | $this->name = $name; |
23 | 23 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @return string |
27 | 27 | */ |
28 | - public function getName() : string { |
|
28 | + public function getName () : string { |
|
29 | 29 | return $this->name; |
30 | 30 | } |
31 | 31 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return string[] |
36 | 36 | */ |
37 | - public function getGroups() : array { |
|
37 | + public function getGroups () : array { |
|
38 | 38 | return array_keys( $this->getGroupsWithDates() ); |
39 | 39 | } |
40 | 40 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return string[] |
46 | 46 | */ |
47 | - public function getGroupsWithDates() : array { |
|
47 | + public function getGroupsWithDates () : array { |
|
48 | 48 | if ( $this->groups === null ) { |
49 | 49 | $usersList = PageBotList::get( $this->controller )->getAdminsList(); |
50 | 50 | $this->groups = $usersList[ $this->name ]; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param string $groupName |
59 | 59 | * @return bool |
60 | 60 | */ |
61 | - public function inGroup( string $groupName ) : bool { |
|
61 | + public function inGroup ( string $groupName ) : bool { |
|
62 | 62 | return in_array( $groupName, $this->getGroups() ); |
63 | 63 | } |
64 | 64 | |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @inheritDoc |
69 | 69 | */ |
70 | - public function getRegex() : string { |
|
70 | + public function getRegex () : string { |
|
71 | 71 | return str_replace( ' ', '[ _]', preg_quote( $this->name ) ); |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @return string |
76 | 76 | */ |
77 | - public function __toString() { |
|
77 | + public function __toString () { |
|
78 | 78 | return $this->name; |
79 | 79 | } |
80 | 80 | } |
@@ -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 Logger $logger |
29 | 29 | * @param string $domain The URL of the wiki, if different from default |
30 | 30 | */ |
31 | - public function __construct( Logger $logger, string $domain = DEFAULT_URL ) { |
|
31 | + public function __construct ( Logger $logger, string $domain = DEFAULT_URL ) { |
|
32 | 32 | $this->logger = $logger; |
33 | 33 | $this->setDomain( $domain ); |
34 | 34 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param string $domain |
38 | 38 | * @return Controller |
39 | 39 | */ |
40 | - public function cloneWithDomain( string $domain ) { |
|
40 | + public function cloneWithDomain ( string $domain ) { |
|
41 | 41 | $ret = clone $this; |
42 | 42 | $ret->setDomain( $domain ); |
43 | 43 | return $ret; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * @param string $domain |
48 | 48 | */ |
49 | - public function setDomain( string $domain ) { |
|
49 | + public function setDomain ( string $domain ) { |
|
50 | 50 | $this->domain = $domain; |
51 | 51 | } |
52 | 52 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @throws MissingPageException |
60 | 60 | * @throws MissingSectionException |
61 | 61 | */ |
62 | - public function getPageContent( string $title, int $section = null ) : string { |
|
62 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
63 | 63 | $msg = "Retrieving content of $title" . ( $section !== null ? ", section $section" : '' ); |
64 | 64 | $this->logger->debug( $msg ); |
65 | 65 | $params = [ |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | ]; |
72 | 72 | |
73 | 73 | if ( $section !== null ) { |
74 | - $params['rvsection'] = $section; |
|
74 | + $params[ 'rvsection' ] = $section; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | $req = RequestBase::newFromParams( $params )->setUrl( $this->domain ); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | throw new MissingPageException( $title ); |
82 | 82 | } |
83 | 83 | |
84 | - $mainSlot = $page->revisions[0]->slots->main; |
|
84 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
85 | 85 | |
86 | 86 | // @phan-suppress-next-line PhanImpossibleTypeComparison $section can be null |
87 | 87 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @param array $params |
97 | 97 | * @throws EditException |
98 | 98 | */ |
99 | - public function editPage( array $params ) { |
|
99 | + public function editPage ( array $params ) { |
|
100 | 100 | $this->login(); |
101 | 101 | |
102 | 102 | $params = [ |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | ] + $params; |
106 | 106 | |
107 | 107 | if ( Config::getInstance()->get( 'bot-edits' ) ) { |
108 | - $params['bot'] = 1; |
|
108 | + $params[ 'bot' ] = 1; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $res = RequestBase::newFromParams( $params ) |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
127 | 127 | * @throws LoginException |
128 | 128 | */ |
129 | - public function login() { |
|
129 | + public function login () { |
|
130 | 130 | if ( self::$loggedIn ) { |
131 | 131 | return; |
132 | 132 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | self::$loggedIn = true; |
155 | 155 | // Clear tokens cache |
156 | - $this->tokens = []; |
|
156 | + $this->tokens = [ ]; |
|
157 | 157 | $this->logger->info( 'Login succeeded' ); |
158 | 158 | } |
159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param string $type |
164 | 164 | * @return string |
165 | 165 | */ |
166 | - public function getToken( string $type ) : string { |
|
166 | + public function getToken ( string $type ) : string { |
|
167 | 167 | if ( !isset( $this->tokens[ $type ] ) ) { |
168 | 168 | $params = [ |
169 | 169 | 'action' => 'query', |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @param string $title |
187 | 187 | * @return int |
188 | 188 | */ |
189 | - public function getPageCreationTS( string $title ) : int { |
|
189 | + public function getPageCreationTS ( string $title ) : int { |
|
190 | 190 | $params = [ |
191 | 191 | 'action' => 'query', |
192 | 192 | 'prop' => 'revisions', |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | $res = RequestBase::newFromParams( $params )->setUrl( $this->domain )->execute(); |
201 | 201 | $data = $res->query->pages; |
202 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
202 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @param string $title |
209 | 209 | * @param string $reason |
210 | 210 | */ |
211 | - public function protectPage( string $title, string $reason ) { |
|
211 | + public function protectPage ( string $title, string $reason ) { |
|
212 | 212 | $this->logger->info( "Protecting page $title" ); |
213 | 213 | $this->login(); |
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 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * @param Controller $controller |
14 | 14 | */ |
15 | - public function __construct( Controller $controller ) { |
|
15 | + public function __construct ( Controller $controller ) { |
|
16 | 16 | $this->controller = $controller; |
17 | 17 | } |
18 | 18 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return string |
23 | 23 | */ |
24 | - abstract public function getRegex() : string; |
|
24 | + abstract public function getRegex () : string; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Get a regex matching any element in the given array |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | * @return string |
31 | 31 | * @todo Is this the right place? |
32 | 32 | */ |
33 | - public static function regexFromArray( array $elements ) : string { |
|
34 | - $bits = []; |
|
33 | + public static function regexFromArray ( array $elements ) : string { |
|
34 | + $bits = [ ]; |
|
35 | 35 | foreach ( $elements as $el ) { |
36 | - $bits[] = $el->getRegex(); |
|
36 | + $bits[ ] = $el->getRegex(); |
|
37 | 37 | } |
38 | 38 | return '(?:' . implode( '|', $bits ) . ')'; |
39 | 39 | } |
@@ -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 | |
@@ -13,16 +13,16 @@ discard block |
||
13 | 13 | /** @var array[] */ |
14 | 14 | private $processUsers; |
15 | 15 | /** @var PageRiconferma[] */ |
16 | - private $createdPages = []; |
|
16 | + private $createdPages = [ ]; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Get a list of users to execute tasks on. |
20 | 20 | * |
21 | 21 | * @return array[] |
22 | 22 | */ |
23 | - public function getUsersToProcess() : array { |
|
23 | + public function getUsersToProcess () : array { |
|
24 | 24 | if ( $this->processUsers === null ) { |
25 | - $this->processUsers = []; |
|
25 | + $this->processUsers = [ ]; |
|
26 | 26 | foreach ( PageBotList::get( $this->getController() )->getAdminsList() as $user => $groups ) { |
27 | 27 | if ( $this->shouldAddUser( $groups ) ) { |
28 | 28 | $this->processUsers[ $user ] = $groups; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param string[] $groups |
40 | 40 | * @return bool |
41 | 41 | */ |
42 | - private function shouldAddUser( array $groups ) : bool { |
|
42 | + private function shouldAddUser ( array $groups ) : bool { |
|
43 | 43 | $override = true; |
44 | 44 | $timestamp = PageBotList::getOverrideTimestamp( $groups ); |
45 | 45 | |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return PageRiconferma[] |
60 | 60 | */ |
61 | - public function getOpenPages() : array { |
|
61 | + public function getOpenPages () : array { |
|
62 | 62 | static $list = null; |
63 | 63 | if ( $list === null ) { |
64 | - $list = []; |
|
64 | + $list = [ ]; |
|
65 | 65 | $mainTitle = $this->getOpt( 'main-page-title' ); |
66 | 66 | $params = [ |
67 | 67 | 'action' => 'query', |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $pages = RequestBase::newFromParams( $params )->execute()->query->pages; |
76 | 76 | foreach ( reset( $pages )->templates as $page ) { |
77 | 77 | if ( preg_match( "!$titleReg\/[^\/]+\/\d!", $page->title ) ) { |
78 | - $list[] = new PageRiconferma( $page->title, $this->getController() ); |
|
78 | + $list[ ] = new PageRiconferma( $page->title, $this->getController() ); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | } |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return PageRiconferma[] |
90 | 90 | */ |
91 | - public function getPagesToClose() : array { |
|
91 | + public function getPagesToClose () : array { |
|
92 | 92 | static $list = null; |
93 | 93 | if ( $list === null ) { |
94 | - $list = []; |
|
94 | + $list = [ ]; |
|
95 | 95 | foreach ( $this->getOpenPages() as $page ) { |
96 | 96 | if ( time() > $page->getEndTimestamp() ) { |
97 | - $list[] = $page; |
|
97 | + $list[ ] = $page; |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
@@ -106,21 +106,21 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param string $name |
108 | 108 | */ |
109 | - public function removeUser( string $name ) { |
|
109 | + public function removeUser ( string $name ) { |
|
110 | 110 | unset( $this->processUsers[ $name ] ); |
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | 114 | * @return PageRiconferma[] |
115 | 115 | */ |
116 | - public function getCreatedPages() : array { |
|
116 | + public function getCreatedPages () : array { |
|
117 | 117 | return $this->createdPages; |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @param PageRiconferma $page |
122 | 122 | */ |
123 | - public function addCreatedPages( PageRiconferma $page ) { |
|
124 | - $this->createdPages[] = $page; |
|
123 | + public function addCreatedPages ( PageRiconferma $page ) { |
|
124 | + $this->createdPages[ ] = $page; |
|
125 | 125 | } |
126 | 126 | } |
@@ -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 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param Logger $logger |
55 | 55 | * @param Controller $controller |
56 | 56 | */ |
57 | - public function __construct( Logger $logger, Controller $controller ) { |
|
57 | + public function __construct ( Logger $logger, Controller $controller ) { |
|
58 | 58 | $this->logger = $logger; |
59 | 59 | $this->controller = $controller; |
60 | 60 | $this->provider = new TaskDataProvider( $this->logger, $this->controller ); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param string|null $name Only used in MODE_TASK and MODE_SUBTASK |
68 | 68 | * @return TaskResult |
69 | 69 | */ |
70 | - public function run( string $mode, string $name = null ) : TaskResult { |
|
70 | + public function run ( string $mode, string $name = null ) : TaskResult { |
|
71 | 71 | if ( $mode === self::MODE_COMPLETE ) { |
72 | 72 | return $this->runAllTasks(); |
73 | 73 | } elseif ( $name === null ) { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return TaskResult |
84 | 84 | */ |
85 | - protected function runAllTasks() : TaskResult { |
|
85 | + protected function runAllTasks () : TaskResult { |
|
86 | 86 | $orderedList = [ |
87 | 87 | 'update-list', |
88 | 88 | 'start-new', |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param string $name |
105 | 105 | * @return TaskResult |
106 | 106 | */ |
107 | - protected function runTask( string $name ) : TaskResult { |
|
107 | + protected function runTask ( string $name ) : TaskResult { |
|
108 | 108 | if ( !isset( self::TASKS_MAP[ $name ] ) ) { |
109 | 109 | throw new \InvalidArgumentException( "'$name' is not a valid task." ); |
110 | 110 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param string $name |
120 | 120 | * @return TaskResult |
121 | 121 | */ |
122 | - protected function runSubtask( string $name ) : TaskResult { |
|
122 | + protected function runSubtask ( string $name ) : TaskResult { |
|
123 | 123 | if ( !isset( self::SUBTASKS_MAP[ $name ] ) ) { |
124 | 124 | throw new \InvalidArgumentException( "'$name' is not a valid subtask." ); |
125 | 125 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param string $class |
135 | 135 | * @return Task |
136 | 136 | */ |
137 | - private function getTaskInstance( string $class ) : Task { |
|
137 | + private function getTaskInstance ( string $class ) : Task { |
|
138 | 138 | return new $class( $this->logger, $this->controller, $this->provider ); |
139 | 139 | } |
140 | 140 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param string $class |
145 | 145 | * @return Subtask |
146 | 146 | */ |
147 | - private function getSubtaskInstance( string $class ) : Subtask { |
|
147 | + private function getSubtaskInstance ( string $class ) : Subtask { |
|
148 | 148 | return new $class( $this->logger, $this->controller, $this->provider ); |
149 | 149 | } |
150 | 150 | } |
@@ -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 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param Logger $logger |
20 | 20 | * @param Controller $controller |
21 | 21 | */ |
22 | - public function __construct( Logger $logger, Controller $controller ) { |
|
22 | + public function __construct ( Logger $logger, Controller $controller ) { |
|
23 | 23 | $this->logger = $logger; |
24 | 24 | $this->controller = $controller; |
25 | 25 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param string $mode |
31 | 31 | * @param string|null $name |
32 | 32 | */ |
33 | - private function run( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) { |
|
33 | + private function run ( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) { |
|
34 | 34 | $activity = $mode === TaskManager::MODE_COMPLETE ? TaskManager::MODE_COMPLETE : "$mode $name"; |
35 | 35 | $this->logger->info( "Running $activity" ); |
36 | 36 | $manager = new TaskManager( $this->logger, $this->controller ); |
@@ -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 . ".\n$line\n\n" ); |
45 | 44 | } else { |
46 | 45 | $this->logger->error( "$base failed.\n$res\n$line\n\n" ); |
@@ -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; |
4 | 4 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | /** @var self */ |
14 | 14 | private static $instance; |
15 | 15 | /** @var array */ |
16 | - private $opts = []; |
|
16 | + private $opts = [ ]; |
|
17 | 17 | /** @var Controller */ |
18 | 18 | private $controller; |
19 | 19 | |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param Controller $controller |
24 | 24 | */ |
25 | - private function __construct( Controller $controller ) { |
|
25 | + private function __construct ( Controller $controller ) { |
|
26 | 26 | $this->controller = $controller; |
27 | 27 | } |
28 | 28 | |
@@ -33,16 +33,16 @@ discard block |
||
33 | 33 | * @param Controller $controller |
34 | 34 | * @throws ConfigException |
35 | 35 | */ |
36 | - public static function init( array $defaults, Controller $controller ) { |
|
36 | + public static function init ( array $defaults, Controller $controller ) { |
|
37 | 37 | if ( self::$instance ) { |
38 | 38 | throw new ConfigException( 'Config was already initialized' ); |
39 | 39 | } |
40 | 40 | |
41 | 41 | $inst = new self( $controller ); |
42 | - $inst->set( 'list-title', $defaults['list-title'] ); |
|
43 | - $inst->set( 'msg-title', $defaults['msg-title'] ); |
|
44 | - $inst->set( 'username', $defaults['username'] ); |
|
45 | - $inst->set( 'password', $defaults['password'] ); |
|
42 | + $inst->set( 'list-title', $defaults[ 'list-title' ] ); |
|
43 | + $inst->set( 'msg-title', $defaults[ 'msg-title' ] ); |
|
44 | + $inst->set( 'username', $defaults[ 'username' ] ); |
|
45 | + $inst->set( 'password', $defaults[ 'password' ] ); |
|
46 | 46 | self::$instance = $inst; |
47 | 47 | |
48 | 48 | // On-wiki values |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @return string |
63 | 63 | * @throws ConfigException |
64 | 64 | */ |
65 | - public function getWikiMessage( string $key ) : string { |
|
65 | + public function getWikiMessage ( string $key ) : string { |
|
66 | 66 | static $messages = null; |
67 | 67 | if ( $messages === null ) { |
68 | 68 | try { |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | if ( !isset( $messages[ $key ] ) ) { |
76 | 76 | throw new ConfigException( "Message '$key' does not exist." ); |
77 | 77 | } |
78 | - return $messages[$key]; |
|
78 | + return $messages[ $key ]; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param string $key |
85 | 85 | * @param mixed $value |
86 | 86 | */ |
87 | - protected function set( string $key, $value ) { |
|
87 | + protected function set ( string $key, $value ) { |
|
88 | 88 | $this->opts[ $key ] = $value; |
89 | 89 | } |
90 | 90 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return self |
95 | 95 | * @throws ConfigException |
96 | 96 | */ |
97 | - public static function getInstance() : self { |
|
97 | + public static function getInstance () : self { |
|
98 | 98 | if ( !self::$instance ) { |
99 | 99 | throw new ConfigException( 'Config not yet initialized' ); |
100 | 100 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return mixed |
109 | 109 | * @throws ConfigException |
110 | 110 | */ |
111 | - public function get( string $opt ) { |
|
111 | + public function get ( string $opt ) { |
|
112 | 112 | if ( !isset( $this->opts[ $opt ] ) ) { |
113 | 113 | throw new ConfigException( "Config option '$opt' not set." ); |
114 | 114 | } |