@@ -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 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @param string $domain The URL of the wiki, if different from default |
29 | 29 | */ |
30 | - public function __construct( string $domain = DEFAULT_URL ) { |
|
30 | + public function __construct ( string $domain = DEFAULT_URL ) { |
|
31 | 31 | $this->logger = new Logger; |
32 | 32 | $this->domain = $domain; |
33 | 33 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @throws MissingPageException |
42 | 42 | * @throws MissingSectionException |
43 | 43 | */ |
44 | - public function getPageContent( string $title, int $section = null ) : string { |
|
44 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
45 | 45 | $msg = "Retrieving content of page $title" . ( $section !== null ? ", section $section" : '' ); |
46 | 46 | $this->logger->debug( $msg ); |
47 | 47 | $params = [ |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | ]; |
54 | 54 | |
55 | 55 | if ( $section !== null ) { |
56 | - $params['rvsection'] = $section; |
|
56 | + $params[ 'rvsection' ] = $section; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $req = RequestBase::newFromParams( $params )->setUrl( $this->domain ); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | throw new MissingPageException( $title ); |
64 | 64 | } |
65 | 65 | |
66 | - $mainSlot = $page->revisions[0]->slots->main; |
|
66 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
67 | 67 | |
68 | 68 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
69 | 69 | throw new MissingSectionException( $title, $section ); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param array $params |
78 | 78 | * @throws EditException |
79 | 79 | */ |
80 | - public function editPage( array $params ) { |
|
80 | + public function editPage ( array $params ) { |
|
81 | 81 | $this->login(); |
82 | 82 | |
83 | 83 | $params = [ |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
105 | 105 | * @throws LoginException |
106 | 106 | */ |
107 | - public function login() { |
|
107 | + public function login () { |
|
108 | 108 | if ( self::$loggedIn ) { |
109 | 109 | return; |
110 | 110 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | self::$loggedIn = true; |
132 | 132 | // Clear tokens cache |
133 | - $this->tokens = []; |
|
133 | + $this->tokens = [ ]; |
|
134 | 134 | $this->logger->info( 'Login succeeded' ); |
135 | 135 | } |
136 | 136 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $type |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - public function getToken( string $type ) : string { |
|
143 | + public function getToken ( string $type ) : string { |
|
144 | 144 | if ( !isset( $this->tokens[ $type ] ) ) { |
145 | 145 | $params = [ |
146 | 146 | 'action' => 'query', |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param string $title |
164 | 164 | * @return int |
165 | 165 | */ |
166 | - public function getPageCreationTS( string $title ) : int { |
|
166 | + public function getPageCreationTS ( string $title ) : int { |
|
167 | 167 | $params = [ |
168 | 168 | 'action' => 'query', |
169 | 169 | 'prop' => 'revisions', |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | $res = RequestBase::newFromParams( $params )->setUrl( $this->domain )->execute(); |
178 | 178 | $data = $res->query->pages; |
179 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
179 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @param string $title |
186 | 186 | * @param string $reason |
187 | 187 | */ |
188 | - public function protectPage( string $title, string $reason ) { |
|
188 | + public function protectPage ( string $title, string $reason ) { |
|
189 | 189 | $this->logger->info( "Protecting page $title" ); |
190 | 190 | $this->login(); |
191 | 191 |
@@ -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 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @inheritDoc |
13 | 13 | * @throws APIRequestException |
14 | 14 | */ |
15 | - protected function reallyMakeRequest( string $params ) : string { |
|
15 | + protected function reallyMakeRequest ( string $params ) : string { |
|
16 | 16 | $curl = curl_init(); |
17 | 17 | if ( $curl === false ) { |
18 | 18 | throw new APIRequestException( 'Cannot open cURL handler.' ); |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | * @return int |
55 | 55 | * @internal Only used as CB for cURL |
56 | 56 | */ |
57 | - public function headersHandler( $ch, string $header ) : int { |
|
57 | + public function headersHandler ( $ch, string $header ) : int { |
|
58 | 58 | $bits = explode( ':', $header, 2 ); |
59 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
60 | - $this->newCookies[] = $bits[1]; |
|
59 | + if ( trim( $bits[ 0 ] ) === 'Set-Cookie' ) { |
|
60 | + $this->newCookies[ ] = $bits[ 1 ]; |
|
61 | 61 | } |
62 | 62 | // @phan-suppress-next-line PhanTypeMismatchReturn WTF? Why does phan thinks this is a string? |
63 | 63 | return strlen( $header ); |
@@ -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,12 +13,12 @@ discard block |
||
13 | 13 | /** @var self */ |
14 | 14 | private static $instance; |
15 | 15 | /** @var array */ |
16 | - private $opts = []; |
|
16 | + private $opts = [ ]; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Use self::init() and self::getInstance() |
20 | 20 | */ |
21 | - private function __construct() { |
|
21 | + private function __construct () { |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | * @param array $defaults |
28 | 28 | * @throws ConfigException |
29 | 29 | */ |
30 | - public static function init( array $defaults ) { |
|
30 | + public static function init ( array $defaults ) { |
|
31 | 31 | if ( self::$instance ) { |
32 | 32 | throw new ConfigException( 'Config was already initialized' ); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $inst = new self; |
36 | - $inst->set( 'list-title', $defaults['list-title'] ); |
|
37 | - $inst->set( 'msg-title', $defaults['msg-title'] ); |
|
38 | - $inst->set( 'username', $defaults['username'] ); |
|
39 | - $inst->set( 'password', $defaults['password'] ); |
|
36 | + $inst->set( 'list-title', $defaults[ 'list-title' ] ); |
|
37 | + $inst->set( 'msg-title', $defaults[ 'msg-title' ] ); |
|
38 | + $inst->set( 'username', $defaults[ 'username' ] ); |
|
39 | + $inst->set( 'password', $defaults[ 'password' ] ); |
|
40 | 40 | self::$instance = $inst; |
41 | 41 | |
42 | 42 | // On-wiki values |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @return string |
57 | 57 | * @throws ConfigException |
58 | 58 | */ |
59 | - public function getWikiMessage( string $key ) : string { |
|
59 | + public function getWikiMessage ( string $key ) : string { |
|
60 | 60 | static $messages = null; |
61 | 61 | if ( $messages === null ) { |
62 | 62 | try { |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | if ( !isset( $messages[ $key ] ) ) { |
70 | 70 | throw new ConfigException( "Message '$key' does not exist." ); |
71 | 71 | } |
72 | - return $messages[$key]; |
|
72 | + return $messages[ $key ]; |
|
73 | 73 | } |
74 | 74 | /** |
75 | 75 | * Set a config value. |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param string $key |
78 | 78 | * @param mixed $value |
79 | 79 | */ |
80 | - protected function set( string $key, $value ) { |
|
80 | + protected function set ( string $key, $value ) { |
|
81 | 81 | $this->opts[ $key ] = $value; |
82 | 82 | } |
83 | 83 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @return self |
88 | 88 | * @throws ConfigException |
89 | 89 | */ |
90 | - public static function getInstance() : self { |
|
90 | + public static function getInstance () : self { |
|
91 | 91 | if ( !self::$instance ) { |
92 | 92 | throw new ConfigException( 'Config not yet initialized' ); |
93 | 93 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @return mixed |
102 | 102 | * @throws ConfigException |
103 | 103 | */ |
104 | - public function get( string $opt ) { |
|
104 | + public function get ( string $opt ) { |
|
105 | 105 | if ( !isset( $this->opts[ $opt ] ) ) { |
106 | 106 | throw new ConfigException( "Config option '$opt' not set." ); |
107 | 107 | } |
@@ -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,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | const VERSION = '1.0'; |
13 | 13 | |
14 | - public function __construct() { |
|
14 | + public function __construct () { |
|
15 | 15 | $this->logger = new Logger; |
16 | 16 | } |
17 | 17 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param string $mode |
22 | 22 | * @param string|null $name |
23 | 23 | */ |
24 | - private function run( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) { |
|
24 | + private function run ( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) { |
|
25 | 25 | $activity = $mode === TaskManager::MODE_COMPLETE ? TaskManager::MODE_COMPLETE : "$mode $name"; |
26 | 26 | $this->logger->info( "Running $activity" ); |
27 | 27 | $manager = new TaskManager; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * Entry point for the whole process |
39 | 39 | */ |
40 | - public function runAll() { |
|
40 | + public function runAll () { |
|
41 | 41 | $this->run(); |
42 | 42 | } |
43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @param string $task |
48 | 48 | */ |
49 | - public function runTask( string $task ) { |
|
49 | + public function runTask ( string $task ) { |
|
50 | 50 | $this->run( TaskManager::MODE_TASK, $task ); |
51 | 51 | } |
52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @param string $subtask |
57 | 57 | */ |
58 | - public function runSubtask( string $subtask ) { |
|
58 | + public function runSubtask ( string $subtask ) { |
|
59 | 59 | $this->run( TaskManager::MODE_SUBTASK, $subtask ); |
60 | 60 | } |
61 | 61 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Task\Subtask; |
4 | 4 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @inheritDoc |
16 | 16 | */ |
17 | - public function runInternal() : int { |
|
17 | + public function runInternal () : int { |
|
18 | 18 | $pages = $this->getDataProvider()->getCreatedPages(); |
19 | 19 | |
20 | 20 | if ( !$pages ) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param PageRiconferma[] $pages |
38 | 38 | */ |
39 | - protected function addToMainPage( array $pages ) { |
|
39 | + protected function addToMainPage ( array $pages ) { |
|
40 | 40 | $this->getLogger()->info( |
41 | 41 | 'Adding the following to main: ' . implode( ', ', $pages ) |
42 | 42 | ); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @param PageRiconferma[] $pages |
65 | 65 | */ |
66 | - protected function addToVotazioni( array $pages ) { |
|
66 | + protected function addToVotazioni ( array $pages ) { |
|
67 | 67 | $this->getLogger()->info( |
68 | 68 | 'Adding the following to votes: ' . implode( ', ', $pages ) |
69 | 69 | ); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @param int $amount |
97 | 97 | * @throws TaskException |
98 | 98 | */ |
99 | - protected function addToNews( int $amount ) { |
|
99 | + protected function addToNews ( int $amount ) { |
|
100 | 100 | $this->getLogger()->info( "Increasing the news counter by $amount" ); |
101 | 101 | $newsPage = new Page( $this->getConfig()->get( 'news-page-title' ) ); |
102 | 102 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | throw new TaskException( 'Param not found in news page' ); |
110 | 110 | } |
111 | 111 | |
112 | - $newNum = (int)$matches[2] + $amount; |
|
112 | + $newNum = (int)$matches[ 2 ] + $amount; |
|
113 | 113 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
114 | 114 | |
115 | 115 | $summary = $this->msg( 'news-page-summary' ) |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Task\Subtask; |
4 | 4 | |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @inheritDoc |
18 | 18 | */ |
19 | - public function runInternal() : int { |
|
19 | + public function runInternal () : int { |
|
20 | 20 | $pages = $this->getDataProvider()->getPagesToClose(); |
21 | 21 | |
22 | 22 | if ( !$pages ) { |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @param PageRiconferma[] $pages |
39 | 39 | * @see UpdatesAround::addToVotazioni() |
40 | 40 | */ |
41 | - protected function updateVotazioni( array $pages ) { |
|
41 | + protected function updateVotazioni ( array $pages ) { |
|
42 | 42 | $this->getLogger()->info( |
43 | 43 | 'Updating votazioni: ' . implode( ', ', $pages ) |
44 | 44 | ); |
45 | 45 | $votePage = new Page( $this->getConfig()->get( 'vote-page-title' ) ); |
46 | 46 | |
47 | - $users = []; |
|
47 | + $users = [ ]; |
|
48 | 48 | foreach ( $pages as $page ) { |
49 | - $users[] = $page->getUser(); |
|
49 | + $users[ ] = $page->getUser(); |
|
50 | 50 | } |
51 | 51 | $usersReg = Element::regexFromArray( $users ); |
52 | 52 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param array $pages |
68 | 68 | * @see UpdatesAround::addToNews() |
69 | 69 | */ |
70 | - protected function updateNews( array $pages ) { |
|
70 | + protected function updateNews ( array $pages ) { |
|
71 | 71 | $simpleAmount = $voteAmount = 0; |
72 | 72 | foreach ( $pages as $page ) { |
73 | 73 | if ( $page->isVote() ) { |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | $simpleMatches = $newsPage->getMatch( $simpleReg ); |
91 | 91 | $voteMatches = $newsPage->getMatch( $voteReg ); |
92 | 92 | |
93 | - $newSimp = (int)$simpleMatches[2] - $simpleAmount ?: ''; |
|
94 | - $newVote = (int)$voteMatches[2] - $voteAmount ?: ''; |
|
93 | + $newSimp = (int)$simpleMatches[ 2 ] - $simpleAmount ?: ''; |
|
94 | + $newVote = (int)$voteMatches[ 2 ] - $voteAmount ?: ''; |
|
95 | 95 | $newContent = preg_replace( $simpleReg, '${1}' . $newSimp, $content ); |
96 | 96 | $newContent = preg_replace( $voteReg, '${1}' . $newVote, $newContent ); |
97 | 97 | |
@@ -109,21 +109,21 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @param bool[] $outcomes |
111 | 111 | */ |
112 | - protected function updateAdminList( array $outcomes ) { |
|
112 | + protected function updateAdminList ( array $outcomes ) { |
|
113 | 113 | $this->getLogger()->info( 'Updating admin list' ); |
114 | 114 | $adminsPage = new Page( $this->getConfig()->get( 'admins-list-title' ) ); |
115 | 115 | $newContent = $adminsPage->getContent(); |
116 | 116 | |
117 | - $riconfNames = $removeNames = []; |
|
117 | + $riconfNames = $removeNames = [ ]; |
|
118 | 118 | foreach ( $outcomes as $user => $confirmed ) { |
119 | 119 | $userReg = ( new User( $user ) )->getRegex(); |
120 | 120 | $reg = "!(\{\{Amministratore\/riga\|$userReg.+\| *)\d+( *\|[ \w]*\}\}.*\n)!"; |
121 | 121 | if ( $confirmed ) { |
122 | 122 | $newContent = preg_replace( $reg, '${1}{{subst:#time:Ymd|+1 year}}$2', $newContent ); |
123 | - $riconfNames[] = $user; |
|
123 | + $riconfNames[ ] = $user; |
|
124 | 124 | } else { |
125 | 125 | $newContent = preg_replace( $reg, '', $newContent ); |
126 | - $removeNames[] = $user; |
|
126 | + $removeNames[ ] = $user; |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
@@ -143,21 +143,21 @@ discard block |
||
143 | 143 | /** |
144 | 144 | * @param bool[] $outcomes |
145 | 145 | */ |
146 | - protected function updateCUList( array $outcomes ) { |
|
146 | + protected function updateCUList ( array $outcomes ) { |
|
147 | 147 | $this->getLogger()->info( 'Updating CU list.' ); |
148 | 148 | $cuList = new Page( $this->getConfig()->get( 'cu-list-title' ) ); |
149 | 149 | $newContent = $cuList->getContent(); |
150 | 150 | |
151 | - $riconfNames = $removeNames = []; |
|
151 | + $riconfNames = $removeNames = [ ]; |
|
152 | 152 | foreach ( $outcomes as $user => $confirmed ) { |
153 | 153 | $userReg = ( new User( $user ) )->getRegex(); |
154 | 154 | $reg = "!(\{\{ *Checkuser *\| *$userReg *\|[^}]+\| *)[\w \d]+(}}.*\n)!"; |
155 | 155 | if ( $confirmed ) { |
156 | 156 | $newContent = preg_replace( $reg, '${1}{{subst:#time:j F Y}}$2', $newContent ); |
157 | - $riconfNames[] = $user; |
|
157 | + $riconfNames[ ] = $user; |
|
158 | 158 | } else { |
159 | 159 | $newContent = preg_replace( $reg, '', $newContent ); |
160 | - $removeNames[] = $user; |
|
160 | + $removeNames[ ] = $user; |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param PageRiconferma[] $pages |
182 | 182 | * @return bool[] |
183 | 183 | */ |
184 | - private function getGroupOutcomes( string $group, array $pages ) : array { |
|
185 | - $ret = []; |
|
184 | + private function getGroupOutcomes ( string $group, array $pages ) : array { |
|
185 | + $ret = [ ]; |
|
186 | 186 | foreach ( $pages as $page ) { |
187 | 187 | $user = $page->getUser(); |
188 | 188 | if ( $user->inGroup( $group ) ) { |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Task; |
4 | 4 | |
@@ -15,15 +15,15 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @inheritDoc |
17 | 17 | */ |
18 | - protected function getSubtasksMap(): array { |
|
18 | + protected function getSubtasksMap (): array { |
|
19 | 19 | // Everything is done here. |
20 | - return []; |
|
20 | + return [ ]; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @inheritDoc |
25 | 25 | */ |
26 | - public function runInternal() : int { |
|
26 | + public function runInternal () : int { |
|
27 | 27 | $pages = $this->getDataProvider()->getOpenPages(); |
28 | 28 | |
29 | 29 | if ( !$pages ) { |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @param PageRiconferma[] $pages |
38 | 38 | * @return int a STATUS_* constant |
39 | 39 | */ |
40 | - protected function processPages( array $pages ) : int { |
|
41 | - $actualPages = []; |
|
40 | + protected function processPages ( array $pages ) : int { |
|
41 | + $actualPages = [ ]; |
|
42 | 42 | foreach ( $pages as $page ) { |
43 | 43 | if ( $page->hasOpposition() && !$page->isVote() ) { |
44 | 44 | $this->openVote( $page ); |
45 | - $actualPages[] = $page; |
|
45 | + $actualPages[ ] = $page; |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @param PageRiconferma $page |
62 | 62 | */ |
63 | - protected function openVote( PageRiconferma $page ) { |
|
63 | + protected function openVote ( PageRiconferma $page ) { |
|
64 | 64 | $this->getLogger()->info( "Starting vote on $page" ); |
65 | 65 | |
66 | 66 | $content = $page->getContent(); |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | * @see SimpleUpdates::updateVotazioni() |
100 | 100 | * @see UpdatesAround::addToVotazioni() |
101 | 101 | */ |
102 | - protected function updateVotazioni( array $pages ) { |
|
102 | + protected function updateVotazioni ( array $pages ) { |
|
103 | 103 | $votePage = new Page( $this->getConfig()->get( 'vote-page-title' ) ); |
104 | 104 | |
105 | - $users = []; |
|
105 | + $users = [ ]; |
|
106 | 106 | foreach ( $pages as $page ) { |
107 | - $users[] = $page->getUser(); |
|
107 | + $users[ ] = $page->getUser(); |
|
108 | 108 | } |
109 | 109 | $usersReg = Element::regexFromArray( $users ); |
110 | 110 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @see SimpleUpdates::updateNews() |
143 | 143 | * @throws TaskException |
144 | 144 | */ |
145 | - protected function updateNews( int $amount ) { |
|
145 | + protected function updateNews ( int $amount ) { |
|
146 | 146 | $this->getLogger()->info( "Turning $amount pages into votes" ); |
147 | 147 | $newsPage = new Page( $this->getConfig()->get( 'news-page-title' ) ); |
148 | 148 | |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | throw new TaskException( 'Param "voto" not found in news page' ); |
158 | 158 | } |
159 | 159 | |
160 | - $newTac = intval( $newsPage->getMatch( $regTac )[2] ) - $amount ?: ''; |
|
161 | - $newVot = intval( $newsPage->getMatch( $regVot )[2] ) + $amount ?: ''; |
|
160 | + $newTac = intval( $newsPage->getMatch( $regTac )[ 2 ] ) - $amount ?: ''; |
|
161 | + $newVot = intval( $newsPage->getMatch( $regVot )[ 2 ] ) + $amount ?: ''; |
|
162 | 162 | |
163 | 163 | $newContent = preg_replace( $regTac, '${1}' . $newTac, $content ); |
164 | 164 | $newContent = preg_replace( $regVot, '${1}' . $newVot, $newContent ); |
@@ -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\Wiki\Page; |
4 | 4 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | private $supportSection = 3; |
14 | 14 | private $opposeSection = 4; |
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 | const OUTCOME_OK = 0; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @param string $title |
31 | 31 | */ |
32 | - public function __construct( string $title ) { |
|
32 | + public function __construct ( string $title ) { |
|
33 | 33 | parent::__construct( $title ); |
34 | 34 | $this->supportSection = $this->isVote() ? 3 : 0; |
35 | 35 | $this->opposeSection = $this->isVote() ? 4 : 3; |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return User |
42 | 42 | */ |
43 | - public function getUser() : User { |
|
44 | - $name = explode( '/', $this->title )[2]; |
|
43 | + public function getUser () : User { |
|
44 | + $name = explode( '/', $this->title )[ 2 ]; |
|
45 | 45 | return new User( $name ); |
46 | 46 | } |
47 | 47 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return int |
52 | 52 | */ |
53 | - public function getNum() : int { |
|
53 | + public function getNum () : int { |
|
54 | 54 | $bits = explode( '/', $this->getTitle() ); |
55 | 55 | return intval( end( $bits ) ); |
56 | 56 | } |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - public function getUserNum() : string { |
|
64 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
63 | + public function getUserNum () : string { |
|
64 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - public function getBaseTitle() : string { |
|
72 | + public function getBaseTitle () : string { |
|
73 | 73 | // @phan-suppress-next-line PhanTypeMismatchArgumentInternal Phan bug |
74 | 74 | return substr( $this->getTitle(), 0, strrpos( $this->getTitle(), '/' ) ); |
75 | 75 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return int |
81 | 81 | */ |
82 | - public function getOpposingCount() : int { |
|
82 | + public function getOpposingCount () : int { |
|
83 | 83 | return $this->getCountForSection( $this->opposeSection ); |
84 | 84 | } |
85 | 85 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return int |
90 | 90 | * @throws \BadMethodCallException |
91 | 91 | */ |
92 | - public function getSupportCount() : int { |
|
92 | + public function getSupportCount () : int { |
|
93 | 93 | if ( !$this->isVote() ) { |
94 | 94 | throw new \BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
95 | 95 | } |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | * @param int $secNum |
103 | 103 | * @return int |
104 | 104 | */ |
105 | - protected function getCountForSection( int $secNum ) : int { |
|
105 | + protected function getCountForSection ( int $secNum ) : int { |
|
106 | 106 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
107 | 107 | $content = $this->controller->getPageContent( $this->title, $secNum ); |
108 | 108 | // Let's hope that this is good enough... |
109 | - $this->sectionCounts[$secNum] = preg_match_all( "/^\# *(?![# *]|\.\.\.$)/m", $content ); |
|
109 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^\# *(?![# *]|\.\.\.$)/m", $content ); |
|
110 | 110 | } |
111 | - return $this->sectionCounts[$secNum]; |
|
111 | + return $this->sectionCounts[ $secNum ]; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return int |
118 | 118 | */ |
119 | - protected function getQuorum() : int { |
|
119 | + protected function getQuorum () : int { |
|
120 | 120 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
121 | - return intval( $this->getMatch( $reg )[1] ); |
|
121 | + return intval( $this->getMatch( $reg )[ 1 ] ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return bool |
128 | 128 | */ |
129 | - public function hasOpposition() : bool { |
|
129 | + public function hasOpposition () : bool { |
|
130 | 130 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
131 | 131 | } |
132 | 132 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return int One of the OUTCOME_* constants |
137 | 137 | */ |
138 | - public function getOutcome() : int { |
|
138 | + public function getOutcome () : int { |
|
139 | 139 | if ( !$this->isVote() ) { |
140 | 140 | return self::OUTCOME_OK; |
141 | 141 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @throws \BadMethodCallException |
156 | 156 | * @throws \LogicException |
157 | 157 | */ |
158 | - public function getOutcomeText() : string { |
|
158 | + public function getOutcomeText () : string { |
|
159 | 159 | if ( !$this->isVote() ) { |
160 | 160 | throw new \BadMethodCallException( 'No need for an outcome text.' ); |
161 | 161 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return bool |
191 | 191 | */ |
192 | - public function isVote() : bool { |
|
192 | + public function isVote () : bool { |
|
193 | 193 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
194 | 194 | return !$this->matches( $sectionReg ); |
195 | 195 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @return int |
201 | 201 | */ |
202 | - public function getCreationTimestamp() : int { |
|
202 | + public function getCreationTimestamp () : int { |
|
203 | 203 | return $this->controller->getPageCreationTS( $this->title ); |
204 | 204 | } |
205 | 205 | /** |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function getEndTimestamp() : int { |
|
210 | + public function getEndTimestamp () : int { |
|
211 | 211 | if ( $this->isVote() ) { |
212 | 212 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
213 | 213 | list( , $hours, $day ) = $this->getMatch( $reg ); |