@@ -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\Task; |
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 | $orderedList = [ |
19 | 19 | 'create-pages', |
20 | 20 | 'open-updates', |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @inheritDoc |
34 | 34 | */ |
35 | - protected function getSubtasksMap() : array { |
|
35 | + protected function getSubtasksMap () : array { |
|
36 | 36 | return [ |
37 | 37 | 'create-pages' => CreatePages::class, |
38 | 38 | 'open-updates' => OpenUpdates::class, |
@@ -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.' ); |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | * @internal Only used as CB for cURL (CURLOPT_HEADERFUNCTION) |
56 | 56 | * @suppress PhanUnreferencedPublicMethod,PhanUnusedPublicNoOverrideMethodParameter |
57 | 57 | */ |
58 | - public function headersHandler( $ch, string $header ) : int { |
|
58 | + public function headersHandler ( $ch, string $header ) : int { |
|
59 | 59 | $bits = explode( ':', $header, 2 ); |
60 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
61 | - $this->newCookies[] = $bits[1]; |
|
60 | + if ( trim( $bits[ 0 ] ) === 'Set-Cookie' ) { |
|
61 | + $this->newCookies[ ] = $bits[ 1 ]; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | 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\Logger; |
4 | 4 | |
@@ -8,5 +8,5 @@ discard block |
||
8 | 8 | * Logger aware of flushing. Can be declared empty if the buffer is flushed immediately. |
9 | 9 | */ |
10 | 10 | interface IFlushingAwareLogger extends LoggerInterface { |
11 | - public function flush() : void; |
|
11 | + public function flush () : void; |
|
12 | 12 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | /** |
3 | 3 | * Entry point for the bot, called by CLI |
4 | 4 | */ |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | $type = current( array_keys( $taskOpt ) ); |
55 | 55 | try { |
56 | 56 | if ( $type === 'task' ) { |
57 | - $bot->runTask( $taskOpt['task'] ); |
|
57 | + $bot->runTask( $taskOpt[ 'task' ] ); |
|
58 | 58 | } elseif ( $type === 'subtask' ) { |
59 | - $bot->runSubtask( $taskOpt['subtask'] ); |
|
59 | + $bot->runSubtask( $taskOpt[ 'subtask' ] ); |
|
60 | 60 | } else { |
61 | 61 | $bot->runAll(); |
62 | 62 | } |
@@ -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 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @private Use self::get() |
20 | 20 | * @param Wiki $wiki |
21 | 21 | */ |
22 | - public function __construct( Wiki $wiki ) { |
|
22 | + public function __construct ( Wiki $wiki ) { |
|
23 | 23 | parent::__construct( Config::getInstance()->get( 'list-title' ), $wiki ); |
24 | 24 | } |
25 | 25 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param Wiki $wiki |
30 | 30 | * @return self |
31 | 31 | */ |
32 | - public static function get( Wiki $wiki ) : self { |
|
32 | + public static function get ( Wiki $wiki ) : self { |
|
33 | 33 | static $instance = null; |
34 | 34 | if ( $instance === null ) { |
35 | 35 | $instance = new self( $wiki ); |
@@ -41,16 +41,16 @@ discard block |
||
41 | 41 | * @param string[] $groups |
42 | 42 | * @return int|null |
43 | 43 | */ |
44 | - public static function getOverrideTimestamp( array $groups ) : ?int { |
|
44 | + public static function getOverrideTimestamp ( array $groups ) : ?int { |
|
45 | 45 | if ( !array_intersect_key( $groups, [ 'override-perm' => true, 'override' => true ] ) ) { |
46 | 46 | return null; |
47 | 47 | } |
48 | 48 | |
49 | 49 | // A one-time override takes precedence |
50 | 50 | if ( array_key_exists( 'override', $groups ) ) { |
51 | - $date = $groups['override']; |
|
51 | + $date = $groups[ 'override' ]; |
|
52 | 52 | } else { |
53 | - $date = $groups['override-prem'] . '/' . date( 'Y' ); |
|
53 | + $date = $groups[ 'override-prem' ] . '/' . date( 'Y' ); |
|
54 | 54 | } |
55 | 55 | return \DateTime::createFromFormat( 'd/m/Y', $date )->getTimestamp(); |
56 | 56 | } |
@@ -61,17 +61,15 @@ discard block |
||
61 | 61 | * @param array $groups |
62 | 62 | * @return int |
63 | 63 | */ |
64 | - public static function getValidFlagTimestamp( array $groups ): int { |
|
65 | - $checkuser = isset( $groups['checkuser'] ) ? |
|
66 | - \DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() : |
|
67 | - 0; |
|
68 | - $bureaucrat = isset( $groups['bureaucrat'] ) ? |
|
69 | - \DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() : |
|
70 | - 0; |
|
64 | + public static function getValidFlagTimestamp ( array $groups ): int { |
|
65 | + $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
66 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
67 | + $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
68 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
71 | 69 | |
72 | 70 | $timestamp = max( $bureaucrat, $checkuser ); |
73 | 71 | if ( $timestamp === 0 ) { |
74 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp(); |
|
72 | + $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
75 | 73 | } |
76 | 74 | return $timestamp; |
77 | 75 | } |
@@ -80,14 +78,14 @@ discard block |
||
80 | 78 | * @param array $groups |
81 | 79 | * @return bool |
82 | 80 | */ |
83 | - public static function isOverrideExpired( array $groups ) : bool { |
|
84 | - if ( !isset( $groups['override'] ) ) { |
|
81 | + public static function isOverrideExpired ( array $groups ) : bool { |
|
82 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
85 | 83 | return false; |
86 | 84 | } |
87 | 85 | |
88 | 86 | $flagTS = self::getValidFlagTimestamp( $groups ); |
89 | 87 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); |
90 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
88 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
91 | 89 | $delay = 60 * 60 * 24 * 3; |
92 | 90 | |
93 | 91 | return time() > $usualTS + $delay && time() > $overrideTS + $delay; |
@@ -98,9 +96,9 @@ discard block |
||
98 | 96 | * |
99 | 97 | * @return User[] |
100 | 98 | */ |
101 | - public function getAdminsList() : array { |
|
99 | + public function getAdminsList () : array { |
|
102 | 100 | if ( $this->adminsList === null ) { |
103 | - $this->adminsList = []; |
|
101 | + $this->adminsList = [ ]; |
|
104 | 102 | foreach ( $this->getDecodedContent() as $user => $info ) { |
105 | 103 | $userObj = new User( $user, $this->wiki ); |
106 | 104 | $userObj->setInfo( $info ); |
@@ -115,7 +113,7 @@ discard block |
||
115 | 113 | * |
116 | 114 | * @return array[] |
117 | 115 | */ |
118 | - public function getDecodedContent() : array { |
|
116 | + public function getDecodedContent () : array { |
|
119 | 117 | return json_decode( $this->getContent(), true ); |
120 | 118 | } |
121 | 119 | } |
@@ -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 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * @inheritDoc |
14 | 14 | */ |
15 | - public function runInternal() : int { |
|
15 | + public function runInternal () : int { |
|
16 | 16 | $pages = $this->getDataProvider()->getCreatedPages(); |
17 | 17 | $users = $this->getDataProvider()->getUsersToProcess(); |
18 | 18 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | return TaskResult::STATUS_NOTHING; |
21 | 21 | } |
22 | 22 | |
23 | - $ricNums = []; |
|
23 | + $ricNums = [ ]; |
|
24 | 24 | foreach ( $pages as $page ) { |
25 | 25 | $ricNums[ $page->getUser()->getName() ] = $page->getNum(); |
26 | 26 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param User $user |
39 | 39 | * @param int $ricNum |
40 | 40 | */ |
41 | - protected function addMsg( User $user, int $ricNum ) : void { |
|
41 | + protected function addMsg ( User $user, int $ricNum ) : void { |
|
42 | 42 | $this->getLogger()->info( "Leaving msg to $user" ); |
43 | 43 | $msg = $this->msg( 'user-notice-msg' )->params( [ '$num' => $ricNum ] )->text(); |
44 | 44 |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * @inheritDoc |
15 | 15 | */ |
16 | - public function runInternal() : int { |
|
16 | + public function runInternal () : int { |
|
17 | 17 | $pages = $this->getDataProvider()->getCreatedPages(); |
18 | 18 | |
19 | 19 | if ( !$pages ) { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param PageRiconferma[] $pages |
37 | 37 | */ |
38 | - protected function addToMainPage( array $pages ) : void { |
|
38 | + protected function addToMainPage ( array $pages ) : void { |
|
39 | 39 | $this->getLogger()->info( |
40 | 40 | 'Adding the following to main: ' . implode( ', ', $pages ) |
41 | 41 | ); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @param PageRiconferma[] $pages |
70 | 70 | */ |
71 | - protected function addToVotazioni( array $pages ) : void { |
|
71 | + protected function addToVotazioni ( array $pages ) : void { |
|
72 | 72 | $this->getLogger()->info( |
73 | 73 | 'Adding the following to votes: ' . implode( ', ', $pages ) |
74 | 74 | ); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param int $amount |
106 | 106 | * @throws TaskException |
107 | 107 | */ |
108 | - protected function addToNews( int $amount ) : void { |
|
108 | + protected function addToNews ( int $amount ) : void { |
|
109 | 109 | $this->getLogger()->info( "Increasing the news counter by $amount" ); |
110 | 110 | $newsPage = $this->getPage( $this->getOpt( 'news-page-title' ) ); |
111 | 111 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | $matches = $newsPage->getMatch( $reg ); |
120 | 120 | |
121 | - $newNum = (int)$matches[2] + $amount; |
|
121 | + $newNum = (int)$matches[ 2 ] + $amount; |
|
122 | 122 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
123 | 123 | |
124 | 124 | $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 OpenUpdates::addToVotazioni() |
40 | 40 | */ |
41 | - protected function updateVotazioni( array $pages ) : void { |
|
41 | + protected function updateVotazioni ( array $pages ) : void { |
|
42 | 42 | $this->getLogger()->info( |
43 | 43 | 'Updating votazioni: ' . implode( ', ', $pages ) |
44 | 44 | ); |
45 | 45 | $votePage = $this->getPage( $this->getOpt( '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 OpenUpdates::addToNews() |
69 | 69 | */ |
70 | - protected function updateNews( array $pages ) : void { |
|
70 | + protected function updateNews ( array $pages ) : void { |
|
71 | 71 | $simpleAmount = $voteAmount = 0; |
72 | 72 | foreach ( $pages as $page ) { |
73 | 73 | if ( $page->isVote() ) { |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | $simpleMatches = $newsPage->getMatch( $simpleReg ); |
88 | 88 | $voteMatches = $newsPage->getMatch( $voteReg ); |
89 | 89 | |
90 | - $newSimp = ( (int)$simpleMatches[2] - $simpleAmount ) ?: ''; |
|
91 | - $newVote = ( (int)$voteMatches[2] - $voteAmount ) ?: ''; |
|
90 | + $newSimp = ( (int)$simpleMatches[ 2 ] - $simpleAmount ) ?: ''; |
|
91 | + $newVote = ( (int)$voteMatches[ 2 ] - $voteAmount ) ?: ''; |
|
92 | 92 | $newContent = preg_replace( $simpleReg, '${1}' . $newSimp, $newsPage->getContent() ); |
93 | 93 | $newContent = preg_replace( $voteReg, '${1}' . $newVote, $newContent ); |
94 | 94 | |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param bool[] $outcomes |
108 | 108 | */ |
109 | - protected function updateAdminList( array $outcomes ) : void { |
|
109 | + protected function updateAdminList ( array $outcomes ) : void { |
|
110 | 110 | $this->getLogger()->info( 'Updating admin list' ); |
111 | 111 | $adminsPage = $this->getPage( $this->getOpt( 'admins-list-title' ) ); |
112 | 112 | $newContent = $adminsPage->getContent(); |
113 | 113 | |
114 | - $riconfNames = $removeNames = []; |
|
114 | + $riconfNames = $removeNames = [ ]; |
|
115 | 115 | foreach ( $outcomes as $username => $confirmed ) { |
116 | 116 | $user = $this->getUser( $username ); |
117 | 117 | $userReg = $user->getRegex( '!' ); |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | '${1}{{subst:#timel:Ymd}}|' . $nextDate . '$2', |
124 | 124 | $newContent |
125 | 125 | ); |
126 | - $riconfNames[] = $username; |
|
126 | + $riconfNames[ ] = $username; |
|
127 | 127 | } else { |
128 | 128 | $newContent = preg_replace( $reg, '', $newContent ); |
129 | - $removeNames[] = $username; |
|
129 | + $removeNames[ ] = $username; |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -149,17 +149,17 @@ discard block |
||
149 | 149 | * @param User $user |
150 | 150 | * @return int |
151 | 151 | */ |
152 | - private function getNextTs( User $user ) : int { |
|
152 | + private function getNextTs ( User $user ) : int { |
|
153 | 153 | $userInfo = $user->getUserInfo(); |
154 | - if ( isset( $userInfo['override-perm'] ) ) { |
|
154 | + if ( isset( $userInfo[ 'override-perm' ] ) ) { |
|
155 | 155 | $date = \DateTime::createFromFormat( |
156 | 156 | 'd/m/Y', |
157 | - $userInfo['override-perm'] . '/' . date( 'Y' ) |
|
157 | + $userInfo[ 'override-perm' ] . '/' . date( 'Y' ) |
|
158 | 158 | ); |
159 | 159 | } else { |
160 | 160 | $date = null; |
161 | - if ( isset( $userInfo['override'] ) ) { |
|
162 | - $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo['override'] ); |
|
161 | + if ( isset( $userInfo[ 'override' ] ) ) { |
|
162 | + $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo[ 'override' ] ); |
|
163 | 163 | } |
164 | 164 | if ( !$date || $date <= new \DateTime ) { |
165 | 165 | $ts = PageBotList::getValidFlagTimestamp( $userInfo ); |
@@ -175,21 +175,21 @@ discard block |
||
175 | 175 | /** |
176 | 176 | * @param bool[] $outcomes |
177 | 177 | */ |
178 | - protected function updateCUList( array $outcomes ) : void { |
|
178 | + protected function updateCUList ( array $outcomes ) : void { |
|
179 | 179 | $this->getLogger()->info( 'Updating CU list.' ); |
180 | 180 | $cuList = $this->getPage( $this->getOpt( 'cu-list-title' ) ); |
181 | 181 | $newContent = $cuList->getContent(); |
182 | 182 | |
183 | - $riconfNames = $removeNames = []; |
|
183 | + $riconfNames = $removeNames = [ ]; |
|
184 | 184 | foreach ( $outcomes as $user => $confirmed ) { |
185 | 185 | $userReg = $this->getUser( $user )->getRegex( '!' ); |
186 | 186 | $reg = "!(\{\{ *Checkuser *\| *$userReg *\|[^}]+\| *)[\w \d]+(}}.*\n)!"; |
187 | 187 | if ( $confirmed ) { |
188 | 188 | $newContent = preg_replace( $reg, '${1}{{subst:#time:j F Y}}$2', $newContent ); |
189 | - $riconfNames[] = $user; |
|
189 | + $riconfNames[ ] = $user; |
|
190 | 190 | } else { |
191 | 191 | $newContent = preg_replace( $reg, '', $newContent ); |
192 | - $removeNames[] = $user; |
|
192 | + $removeNames[ ] = $user; |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @param PageRiconferma[] $pages |
214 | 214 | * @return bool[] |
215 | 215 | */ |
216 | - private function getGroupOutcomes( string $group, array $pages ) : array { |
|
217 | - $ret = []; |
|
216 | + private function getGroupOutcomes ( string $group, array $pages ) : array { |
|
217 | + $ret = [ ]; |
|
218 | 218 | foreach ( $pages as $page ) { |
219 | 219 | $user = $page->getUser(); |
220 | 220 | if ( $user->inGroup( $group ) ) { |