@@ -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()->getPagesToClose(); |
18 | 18 | $protectReason = $this->getConfig()->get( 'close-protect-summary' ); |
19 | 19 | foreach ( $pages as $page ) { |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | $this->updateBasePage( $page ); |
25 | 25 | } |
26 | 26 | |
27 | - return self::STATUS_GOOD ; |
|
27 | + return self::STATUS_GOOD; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param PageRiconferma $page |
32 | 32 | */ |
33 | - protected function addVoteCloseText( PageRiconferma $page ) { |
|
33 | + protected function addVoteCloseText ( PageRiconferma $page ) { |
|
34 | 34 | $content = $page->getContent(); |
35 | 35 | $beforeReg = '!è necessario ottenere una maggioranza .+ votanti\.!'; |
36 | 36 | $newContent = preg_replace( $beforeReg, '$0' . "\n" . $page->getOutcomeText(), $content ); |
@@ -45,15 +45,14 @@ discard block |
||
45 | 45 | * @param PageRiconferma $page |
46 | 46 | * @see CreatePages::updateBasePage() |
47 | 47 | */ |
48 | - protected function updateBasePage( PageRiconferma $page ) { |
|
48 | + protected function updateBasePage ( PageRiconferma $page ) { |
|
49 | 49 | $this->getLogger()->info( "Updating base page for $page" ); |
50 | 50 | |
51 | 51 | $basePage = new Page( $page->getBaseTitle() ); |
52 | 52 | $current = $basePage->getContent(); |
53 | 53 | |
54 | 54 | $outcomeText = $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ? |
55 | - 'non riconfermato' : |
|
56 | - 'riconfermato'; |
|
55 | + 'non riconfermato' : 'riconfermato'; |
|
57 | 56 | $text = $page->isVote() ? "votazione: $outcomeText" : 'riconferma tacita'; |
58 | 57 | |
59 | 58 | $newContent = str_replace( 'riconferma in corso', $text, $current ); |
@@ -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()->getPagesToClose(); |
18 | 18 | $this->removeFromMainPage( $pages ); |
19 | 19 | $this->addToArchive( $pages ); |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | * @param PageRiconferma[] $pages |
28 | 28 | * @see UpdatesAround::addToMainPage() |
29 | 29 | */ |
30 | - protected function removeFromMainPage( array $pages ) { |
|
30 | + protected function removeFromMainPage ( array $pages ) { |
|
31 | 31 | $this->getLogger()->info( |
32 | 32 | 'Removing from main: ' . implode( ', ', array_map( 'strval', $pages ) ) |
33 | 33 | ); |
34 | 34 | |
35 | 35 | $mainPage = new Page( $this->getConfig()->get( 'ric-main-page' ) ); |
36 | - $remove = []; |
|
36 | + $remove = [ ]; |
|
37 | 37 | foreach ( $pages as $page ) { |
38 | - $remove[] = '{{' . $page->getTitle() . '}}'; |
|
38 | + $remove[ ] = '{{' . $page->getTitle() . '}}'; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | $mainPage->edit( [ |
@@ -49,17 +49,17 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @param PageRiconferma[] $pages |
51 | 51 | */ |
52 | - protected function addToArchive( array $pages ) { |
|
52 | + protected function addToArchive ( array $pages ) { |
|
53 | 53 | $this->getLogger()->info( |
54 | 54 | 'Adding to archive: ' . implode( ', ', array_map( 'strval', $pages ) ) |
55 | 55 | ); |
56 | 56 | |
57 | - $simple = $votes = []; |
|
57 | + $simple = $votes = [ ]; |
|
58 | 58 | foreach ( $pages as $page ) { |
59 | 59 | if ( $page->isVote() ) { |
60 | - $votes[] = $page; |
|
60 | + $votes[ ] = $page; |
|
61 | 61 | } else { |
62 | - $simple[] = $page; |
|
62 | + $simple[ ] = $page; |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | * @param string $archiveTitle |
77 | 77 | * @param array $pages |
78 | 78 | */ |
79 | - private function reallyAddToArchive( string $archiveTitle, array $pages ) { |
|
79 | + private function reallyAddToArchive ( string $archiveTitle, array $pages ) { |
|
80 | 80 | $archivePage = new Page( "$archiveTitle/" . date( 'Y' ) ); |
81 | 81 | |
82 | 82 | $append = ''; |
83 | - $archivedList = []; |
|
83 | + $archivedList = [ ]; |
|
84 | 84 | foreach ( $pages as $page ) { |
85 | 85 | $append .= '{{' . $page->getTitle() . "}}\n"; |
86 | - $archivedList[] = $page->getUserNum(); |
|
86 | + $archivedList[ ] = $page->getUserNum(); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | $summary = $this->msg( 'close-archive-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; |
4 | 4 | |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @inheritDoc |
17 | 17 | */ |
18 | - public function runInternal() : int { |
|
18 | + public function runInternal () : int { |
|
19 | 19 | $orderedList = [ |
20 | 20 | 'close-pages', |
21 | 21 | 'archive-pages', |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @inheritDoc |
36 | 36 | */ |
37 | - protected function getSubtasksMap(): array { |
|
37 | + protected function getSubtasksMap (): array { |
|
38 | 38 | return [ |
39 | 39 | 'archive-pages' => ArchivePages::class, |
40 | 40 | 'close-pages' => ClosePages::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\Task; |
4 | 4 | |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | const STATUS_NOTHING = 1; |
16 | 16 | const STATUS_ERROR = 2; |
17 | 17 | /** @var string[] */ |
18 | - protected $errors = []; |
|
18 | + protected $errors = [ ]; |
|
19 | 19 | /** @var TaskDataProvider */ |
20 | 20 | protected $dataProvider; |
21 | 21 | |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param TaskDataProvider $dataProvider |
26 | 26 | */ |
27 | - final public function __construct( TaskDataProvider $dataProvider ) { |
|
27 | + final public function __construct ( TaskDataProvider $dataProvider ) { |
|
28 | 28 | set_exception_handler( [ $this, 'handleException' ] ); |
29 | 29 | set_error_handler( [ $this, 'handleError' ] ); |
30 | 30 | parent::__construct(); |
31 | 31 | $this->dataProvider = $dataProvider; |
32 | 32 | } |
33 | 33 | |
34 | - public function __destruct() { |
|
34 | + public function __destruct () { |
|
35 | 35 | restore_error_handler(); |
36 | 36 | restore_exception_handler(); |
37 | 37 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return TaskResult |
43 | 43 | */ |
44 | - final public function run() : TaskResult { |
|
44 | + final public function run () : TaskResult { |
|
45 | 45 | $task = static::class; |
46 | 46 | $this->getLogger()->info( "Starting task $task" ); |
47 | 47 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return int One of the STATUS_* constants |
73 | 73 | */ |
74 | - abstract protected function runInternal() : int; |
|
74 | + abstract protected function runInternal () : int; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Exception handler. |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param \Throwable $ex |
80 | 80 | * @protected |
81 | 81 | */ |
82 | - public function handleException( \Throwable $ex ) { |
|
82 | + public function handleException ( \Throwable $ex ) { |
|
83 | 83 | $this->getLogger()->error( |
84 | 84 | get_class( $ex ) . ': ' . |
85 | 85 | $ex->getMessage() . "\nTrace:\n" . |
@@ -96,14 +96,14 @@ discard block |
||
96 | 96 | * @param int $errline |
97 | 97 | * @protected |
98 | 98 | */ |
99 | - public function handleError( $errno, $errstr, $errfile, $errline ) { |
|
99 | + public function handleError ( $errno, $errstr, $errfile, $errline ) { |
|
100 | 100 | throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline ); |
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * @return TaskDataProvider |
105 | 105 | */ |
106 | - protected function getDataProvider() : TaskDataProvider { |
|
106 | + protected function getDataProvider () : TaskDataProvider { |
|
107 | 107 | return $this->dataProvider; |
108 | 108 | } |
109 | 109 | } |
@@ -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 | |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @inheritDoc |
20 | 20 | */ |
21 | - protected function getSubtasksMap(): array { |
|
21 | + protected function getSubtasksMap (): array { |
|
22 | 22 | // Everything is done here. |
23 | - return []; |
|
23 | + return [ ]; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @inheritDoc |
28 | 28 | */ |
29 | - public function runInternal() : int { |
|
29 | + public function runInternal () : int { |
|
30 | 30 | $this->actualList = $this->getActualAdmins(); |
31 | 31 | $this->botList = $this->getDataProvider()->getUsersList(); |
32 | 32 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * @return array |
57 | 57 | */ |
58 | - protected function getActualAdmins() : array { |
|
58 | + protected function getActualAdmins () : array { |
|
59 | 59 | $this->getLogger()->debug( 'Retrieving admins - API' ); |
60 | 60 | $params = [ |
61 | 61 | 'action' => 'query', |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * @param \stdClass $data |
74 | 74 | * @return array |
75 | 75 | */ |
76 | - protected function extractAdmins( \stdClass $data ) : array { |
|
77 | - $ret = []; |
|
76 | + protected function extractAdmins ( \stdClass $data ) : array { |
|
77 | + $ret = [ ]; |
|
78 | 78 | $blacklist = $this->getConfig()->get( 'exclude-admins' ); |
79 | 79 | foreach ( $data->query->allusers as $u ) { |
80 | 80 | if ( in_array( $u->name, $blacklist ) ) { |
@@ -91,22 +91,22 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return array[] |
93 | 93 | */ |
94 | - protected function getMissingGroups() : array { |
|
95 | - $missing = []; |
|
94 | + protected function getMissingGroups () : array { |
|
95 | + $missing = [ ]; |
|
96 | 96 | foreach ( $this->actualList as $adm => $groups ) { |
97 | - $groupsList = []; |
|
97 | + $groupsList = [ ]; |
|
98 | 98 | if ( !isset( $this->botList[ $adm ] ) ) { |
99 | 99 | $groupsList = $groups; |
100 | - } elseif ( count( $groups ) > count( $this->botList[$adm] ) ) { |
|
100 | + } elseif ( count( $groups ) > count( $this->botList[ $adm ] ) ) { |
|
101 | 101 | // Only some groups are missing |
102 | - $groupsList = array_diff_key( $groups, $this->botList[$adm] ); |
|
102 | + $groupsList = array_diff_key( $groups, $this->botList[ $adm ] ); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | foreach ( $groupsList as $group ) { |
106 | 106 | try { |
107 | 107 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
108 | 108 | } catch ( TaskException $e ) { |
109 | - $this->errors[] = $e->getMessage(); |
|
109 | + $this->errors[ ] = $e->getMessage(); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @return string |
122 | 122 | * @throws TaskException |
123 | 123 | */ |
124 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
124 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
125 | 125 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
126 | 126 | |
127 | 127 | $url = DEFAULT_URL; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @param string $group |
157 | 157 | * @return string|null |
158 | 158 | */ |
159 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
159 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
160 | 160 | $ts = null; |
161 | 161 | foreach ( $data->query->logevents as $entry ) { |
162 | 162 | if ( !isset( $entry->params ) ) { |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return array[] |
180 | 180 | */ |
181 | - protected function getExtraGroups() : array { |
|
182 | - $extra = []; |
|
181 | + protected function getExtraGroups () : array { |
|
182 | + $extra = [ ]; |
|
183 | 183 | foreach ( $this->botList as $name => $groups ) { |
184 | 184 | if ( !isset( $this->actualList[ $name ] ) ) { |
185 | 185 | $extra[ $name ] = $groups; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @param array[] $extra |
198 | 198 | * @return array[] |
199 | 199 | */ |
200 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
200 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
201 | 201 | $newContent = $this->botList; |
202 | 202 | foreach ( $newContent as $user => $groups ) { |
203 | 203 | if ( isset( $missing[ $user ] ) ) { |
@@ -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 | 'update-list', |
20 | 20 | 'create-pages', |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * @inheritDoc |
35 | 35 | */ |
36 | - protected function getSubtasksMap() : array { |
|
36 | + protected function getSubtasksMap () : array { |
|
37 | 37 | return [ |
38 | 38 | 'create-pages' => CreatePages::class, |
39 | 39 | 'update-list' => UpdateList::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\Task; |
4 | 4 | |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @inheritDoc |
16 | 16 | */ |
17 | - protected function getSubtasksMap(): array { |
|
17 | + protected function getSubtasksMap (): array { |
|
18 | 18 | // Everything is done here. |
19 | - return []; |
|
19 | + return [ ]; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @inheritDoc |
24 | 24 | */ |
25 | - public function runInternal() : int { |
|
25 | + public function runInternal () : int { |
|
26 | 26 | $pages = $this->getDataProvider()->getOpenPages(); |
27 | 27 | |
28 | 28 | if ( !$pages ) { |
@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | |
32 | 32 | $this->processPages( $pages ); |
33 | 33 | |
34 | - return self::STATUS_GOOD ; |
|
34 | + return self::STATUS_GOOD; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @param PageRiconferma[] $pages |
39 | 39 | */ |
40 | - protected function processPages( array $pages ) { |
|
41 | - $actualPages = []; |
|
40 | + protected function processPages ( array $pages ) { |
|
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 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @param PageRiconferma $page |
61 | 61 | */ |
62 | - protected function openVote( PageRiconferma $page ) { |
|
62 | + protected function openVote ( PageRiconferma $page ) { |
|
63 | 63 | $this->getLogger()->info( "Starting vote on $page" ); |
64 | 64 | |
65 | 65 | $content = $page->getContent(); |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | * @see SimpleUpdates::updateVote() |
99 | 99 | * @see UpdatesAround::addVote() |
100 | 100 | */ |
101 | - protected function updateVotePage( array $pages ) { |
|
101 | + protected function updateVotePage ( array $pages ) { |
|
102 | 102 | $votePage = new Page( $this->getConfig()->get( 'ric-vote-page' ) ); |
103 | 103 | $content = $votePage->getContent(); |
104 | 104 | |
105 | - $titles = []; |
|
105 | + $titles = [ ]; |
|
106 | 106 | foreach ( $pages as $page ) { |
107 | - $titles[] = preg_quote( $page->getTitle() ); |
|
107 | + $titles[ ] = preg_quote( $page->getTitle() ); |
|
108 | 108 | } |
109 | 109 | $titleReg = implode( '|', $titles ); |
110 | 110 | $search = "!^\*.+ La \[\[($titleReg)\|procedura]] termina.+\n!gm"; |
@@ -127,14 +127,14 @@ discard block |
||
127 | 127 | $newContent = preg_replace( $introReg, '$0' . "\n$newLines", $newContent, 1 ); |
128 | 128 | } else { |
129 | 129 | // Start section |
130 | - $matches = []; |
|
130 | + $matches = [ ]; |
|
131 | 131 | if ( preg_match( $introReg, $newContent, $matches ) === false ) { |
132 | 132 | throw new TaskException( 'Intro not found in vote page' ); |
133 | 133 | } |
134 | 134 | $beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m'; |
135 | 135 | // Replace semicolon with full stop |
136 | 136 | $newLines = substr( $newLines, 0, -2 ) . ".\n"; |
137 | - $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[0]}\n$newLines", $newContent, 1 ); |
|
137 | + $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[ 0 ]}\n$newLines", $newContent, 1 ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $summary = $this->msg( 'vote-start-vote-page-summary' ) |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @see UpdatesAround::addNews() |
157 | 157 | * @see SimpleUpdates::updateNews() |
158 | 158 | */ |
159 | - protected function updateNews( int $amount ) { |
|
159 | + protected function updateNews ( int $amount ) { |
|
160 | 160 | $this->getLogger()->info( "Turning $amount pages into votes" ); |
161 | 161 | $newsPage = new Page( $this->getConfig()->get( 'ric-news-page' ) ); |
162 | 162 | |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | throw new TaskException( 'Param "voto" not found in news page' ); |
172 | 172 | } |
173 | 173 | |
174 | - $newTac = intval( $newsPage->getMatch( $regTac )[2] ) - $amount ?: ''; |
|
175 | - $newVot = intval( $newsPage->getMatch( $regVot )[2] ) + $amount ?: ''; |
|
174 | + $newTac = intval( $newsPage->getMatch( $regTac )[ 2 ] ) - $amount ?: ''; |
|
175 | + $newVot = intval( $newsPage->getMatch( $regVot )[ 2 ] ) + $amount ?: ''; |
|
176 | 176 | |
177 | 177 | $newContent = preg_replace( $regTac, '${1}' . $newTac, $content ); |
178 | 178 | $newContent = preg_replace( $regVot, '${1}' . $newVot, $newContent ); |