@@ -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 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param LoggerInterface $logger |
26 | 26 | * @param Wiki $wiki |
27 | 27 | */ |
28 | - public function __construct( LoggerInterface $logger, Wiki $wiki ) { |
|
28 | + public function __construct ( LoggerInterface $logger, Wiki $wiki ) { |
|
29 | 29 | $this->setLogger( $logger ); |
30 | 30 | $this->setConfig( Config::getInstance() ); |
31 | 31 | $this->setWiki( $wiki ); |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @return LoggerInterface |
36 | 36 | */ |
37 | - protected function getLogger() : LoggerInterface { |
|
37 | + protected function getLogger () : LoggerInterface { |
|
38 | 38 | return $this->logger; |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @inheritDoc |
43 | 43 | */ |
44 | - public function setLogger( LoggerInterface $logger ) { |
|
44 | + public function setLogger ( LoggerInterface $logger ) { |
|
45 | 45 | $this->logger = $logger; |
46 | 46 | } |
47 | 47 | |
@@ -51,35 +51,35 @@ discard block |
||
51 | 51 | * @param string $optname |
52 | 52 | * @return mixed |
53 | 53 | */ |
54 | - protected function getOpt( string $optname ) { |
|
54 | + protected function getOpt ( string $optname ) { |
|
55 | 55 | return $this->getConfig()->get( $optname ); |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @return Config |
60 | 60 | */ |
61 | - protected function getConfig() : Config { |
|
61 | + protected function getConfig () : Config { |
|
62 | 62 | return $this->config; |
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @param Config $cfg |
67 | 67 | */ |
68 | - protected function setConfig( Config $cfg ) { |
|
68 | + protected function setConfig ( Config $cfg ) { |
|
69 | 69 | $this->config = $cfg; |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @return Wiki |
74 | 74 | */ |
75 | - protected function getWiki() : Wiki { |
|
75 | + protected function getWiki () : Wiki { |
|
76 | 76 | return $this->wiki; |
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @param Wiki $wiki |
81 | 81 | */ |
82 | - protected function setWiki( Wiki $wiki ) { |
|
82 | + protected function setWiki ( Wiki $wiki ) { |
|
83 | 83 | $this->wiki = $wiki; |
84 | 84 | } |
85 | 85 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @param string $key |
90 | 90 | * @return Message |
91 | 91 | */ |
92 | - protected function msg( string $key ) : Message { |
|
92 | + protected function msg ( string $key ) : Message { |
|
93 | 93 | return new Message( $key ); |
94 | 94 | } |
95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param string $title |
100 | 100 | * @return Page |
101 | 101 | */ |
102 | - protected function getPage( string $title ) : Page { |
|
102 | + protected function getPage ( string $title ) : Page { |
|
103 | 103 | return new Page( $title, $this->getWiki() ); |
104 | 104 | } |
105 | 105 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param string $name |
110 | 110 | * @return User |
111 | 111 | */ |
112 | - protected function getUser( string $name ) : User { |
|
112 | + protected function getUser ( string $name ) : User { |
|
113 | 113 | return new User( $name, $this->getWiki() ); |
114 | 114 | } |
115 | 115 | } |
@@ -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 | |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | private $supportSection; |
17 | 17 | private $opposeSection; |
18 | 18 | /** @var array Counts of votes for each section */ |
19 | - private $sectionCounts = []; |
|
19 | + private $sectionCounts = [ ]; |
|
20 | 20 | |
21 | 21 | // Possible outcomes of a vote |
22 | 22 | public const OUTCOME_OK = 0; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * because they can vary depending on whether the page is a vote, which is relatively |
36 | 36 | * expensive to know since it requires parsing the content of the page. |
37 | 37 | */ |
38 | - private function defineSections() { |
|
38 | + private function defineSections () { |
|
39 | 39 | $this->supportSection = $this->isVote() ? 3 : 0; |
40 | 40 | $this->opposeSection = $this->isVote() ? 4 : 3; |
41 | 41 | } |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return User |
47 | 47 | */ |
48 | - public function getUser() : User { |
|
49 | - $name = explode( '/', $this->title )[2]; |
|
48 | + public function getUser () : User { |
|
49 | + $name = explode( '/', $this->title )[ 2 ]; |
|
50 | 50 | return new User( $name, $this->wiki ); |
51 | 51 | } |
52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return int |
57 | 57 | */ |
58 | - public function getNum() : int { |
|
58 | + public function getNum () : int { |
|
59 | 59 | $bits = explode( '/', $this->getTitle() ); |
60 | 60 | return intval( end( $bits ) ); |
61 | 61 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return string |
67 | 67 | */ |
68 | - public function getUserNum() : string { |
|
69 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
68 | + public function getUserNum () : string { |
|
69 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return int |
76 | 76 | */ |
77 | - public function getOpposingCount() : int { |
|
77 | + public function getOpposingCount () : int { |
|
78 | 78 | $this->defineSections(); |
79 | 79 | return $this->getCountForSection( $this->opposeSection ); |
80 | 80 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @return int |
86 | 86 | * @throws \BadMethodCallException |
87 | 87 | */ |
88 | - public function getSupportCount() : int { |
|
88 | + public function getSupportCount () : int { |
|
89 | 89 | if ( !$this->isVote() ) { |
90 | 90 | throw new \BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
91 | 91 | } |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * @param int $secNum |
100 | 100 | * @return int |
101 | 101 | */ |
102 | - protected function getCountForSection( int $secNum ) : int { |
|
102 | + protected function getCountForSection ( int $secNum ) : int { |
|
103 | 103 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
104 | 104 | $content = $this->wiki->getPageContent( $this->title, $secNum ); |
105 | 105 | // Let's hope that this is good enough... |
106 | - $this->sectionCounts[$secNum] = preg_match_all( "/^\# *(?![# *:]|\.\.\.$)/m", $content ); |
|
106 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^\# *(?![# *:]|\.\.\.$)/m", $content ); |
|
107 | 107 | } |
108 | - return $this->sectionCounts[$secNum]; |
|
108 | + return $this->sectionCounts[ $secNum ]; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return int |
115 | 115 | */ |
116 | - protected function getQuorum() : int { |
|
116 | + protected function getQuorum () : int { |
|
117 | 117 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
118 | - return intval( $this->getMatch( $reg )[1] ); |
|
118 | + return intval( $this->getMatch( $reg )[ 1 ] ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | - public function hasOpposition() : bool { |
|
126 | + public function hasOpposition () : bool { |
|
127 | 127 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
128 | 128 | } |
129 | 129 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return int One of the OUTCOME_* constants |
134 | 134 | */ |
135 | - public function getOutcome() : int { |
|
135 | + public function getOutcome () : int { |
|
136 | 136 | if ( !$this->isVote() ) { |
137 | 137 | return self::OUTCOME_OK; |
138 | 138 | } |
@@ -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->wiki->getPageCreationTS( $this->title ); |
204 | 204 | } |
205 | 205 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * |
209 | 209 | * @return int |
210 | 210 | */ |
211 | - public function getEndTimestamp() : int { |
|
211 | + public function getEndTimestamp () : int { |
|
212 | 212 | if ( $this->isVote() ) { |
213 | 213 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
214 | 214 | 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 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @param string $name |
21 | 21 | * @param Wiki $wiki |
22 | 22 | */ |
23 | - public function __construct( string $name, Wiki $wiki ) { |
|
23 | + public function __construct ( string $name, Wiki $wiki ) { |
|
24 | 24 | parent::__construct( $wiki ); |
25 | 25 | $this->name = $name; |
26 | 26 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function getName() : string { |
|
31 | + public function getName () : string { |
|
32 | 32 | return $this->name; |
33 | 33 | } |
34 | 34 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return string[] |
39 | 39 | */ |
40 | - public function getGroups() : array { |
|
40 | + public function getGroups () : array { |
|
41 | 41 | return array_diff( array_keys( $this->getUserInfo() ), PageBotList::NON_GROUP_KEYS ); |
42 | 42 | } |
43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return string[] [ group => date ] |
48 | 48 | */ |
49 | - public function getGroupsWithDates() : array { |
|
49 | + public function getGroupsWithDates () : array { |
|
50 | 50 | return array_intersect_key( $this->getUserInfo(), array_fill_keys( $this->getGroups(), 1 ) ); |
51 | 51 | } |
52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return string[] |
57 | 57 | */ |
58 | - public function getUserInfo() : array { |
|
58 | + public function getUserInfo () : array { |
|
59 | 59 | if ( $this->info === null ) { |
60 | 60 | $usersList = PageBotList::get( $this->wiki )->getAdminsList(); |
61 | 61 | $this->info = $usersList[ $this->name ]->getUserInfo(); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | /** |
67 | 67 | * @param array|null $info |
68 | 68 | */ |
69 | - public function setInfo( ?array $info ) : void { |
|
69 | + public function setInfo ( ?array $info ) : void { |
|
70 | 70 | $this->info = $info; |
71 | 71 | } |
72 | 72 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param string $groupName |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - public function inGroup( string $groupName ) : bool { |
|
79 | + public function inGroup ( string $groupName ) : bool { |
|
80 | 80 | return in_array( $groupName, $this->getGroups() ); |
81 | 81 | } |
82 | 82 | |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @inheritDoc |
87 | 87 | */ |
88 | - public function getRegex() : string { |
|
88 | + public function getRegex () : string { |
|
89 | 89 | $bits = $this->getAliases(); |
90 | - $bits[] = $this->name; |
|
90 | + $bits[ ] = $this->name; |
|
91 | 91 | $regexify = function ( $el ) { |
92 | 92 | return str_replace( ' ', '[ _]', preg_quote( $el ) ); |
93 | 93 | }; |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return string[] |
101 | 101 | */ |
102 | - public function getAliases() : array { |
|
103 | - return $this->getUserInfo()['aliases'] ?? []; |
|
102 | + public function getAliases () : array { |
|
103 | + return $this->getUserInfo()[ 'aliases' ] ?? [ ]; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @return Page |
108 | 108 | */ |
109 | - public function getTalkPage() : Page { |
|
109 | + public function getTalkPage () : Page { |
|
110 | 110 | return new Page( "User talk:{$this->name}", $this->wiki ); |
111 | 111 | } |
112 | 112 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * Get the default base page, e.g. WP:A/Riconferma annuale/XXX |
115 | 115 | * @return Page |
116 | 116 | */ |
117 | - public function getBasePage() : Page { |
|
117 | + public function getBasePage () : Page { |
|
118 | 118 | $prefix = Config::getInstance()->get( 'main-page-title' ); |
119 | 119 | return new Page( "$prefix/$this", $this->wiki ); |
120 | 120 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @throws MissingPageException |
127 | 127 | * @return Page |
128 | 128 | */ |
129 | - public function getExistingBasePage() : Page { |
|
129 | + public function getExistingBasePage () : Page { |
|
130 | 130 | $basePage = $this->getBasePage(); |
131 | 131 | if ( !$basePage->exists() ) { |
132 | 132 | $basePage = null; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | /** |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function __toString() { |
|
153 | + public function __toString () { |
|
154 | 154 | return $this->name; |
155 | 155 | } |
156 | 156 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\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 | |
19 | 19 | if ( !$pages ) { |
@@ -32,18 +32,18 @@ discard block |
||
32 | 32 | * @param PageRiconferma[] $pages |
33 | 33 | * @see OpenUpdates::addToMainPage() |
34 | 34 | */ |
35 | - protected function removeFromMainPage( array $pages ) { |
|
35 | + protected function removeFromMainPage ( array $pages ) { |
|
36 | 36 | $this->getLogger()->info( |
37 | 37 | 'Removing from main: ' . implode( ', ', $pages ) |
38 | 38 | ); |
39 | 39 | |
40 | 40 | $mainPage = $this->getPage( $this->getOpt( 'main-page-title' ) ); |
41 | - $remove = []; |
|
41 | + $remove = [ ]; |
|
42 | 42 | foreach ( $pages as $page ) { |
43 | 43 | // Order matters here. It's not guaranteed that there'll be a newline, but avoid |
44 | 44 | // regexps for that single character. |
45 | - $remove[] = '{{' . $page->getTitle() . "}}\n"; |
|
46 | - $remove[] = '{{' . $page->getTitle() . '}}'; |
|
45 | + $remove[ ] = '{{' . $page->getTitle() . "}}\n"; |
|
46 | + $remove[ ] = '{{' . $page->getTitle() . '}}'; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | $newContent = str_replace( $remove, '', $mainPage->getContent() ); |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param PageRiconferma[] $pages |
74 | 74 | */ |
75 | - protected function addToArchive( array $pages ) { |
|
75 | + protected function addToArchive ( array $pages ) { |
|
76 | 76 | $this->getLogger()->info( |
77 | 77 | 'Adding to archive: ' . implode( ', ', $pages ) |
78 | 78 | ); |
79 | 79 | |
80 | - $simple = $votes = []; |
|
80 | + $simple = $votes = [ ]; |
|
81 | 81 | foreach ( $pages as $page ) { |
82 | 82 | if ( $page->isVote() ) { |
83 | - $votes[] = $page; |
|
83 | + $votes[ ] = $page; |
|
84 | 84 | } else { |
85 | - $simple[] = $page; |
|
85 | + $simple[ ] = $page; |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | * @param string $archiveTitle |
104 | 104 | * @param PageRiconferma[] $pages |
105 | 105 | */ |
106 | - private function reallyAddToArchive( string $archiveTitle, array $pages ) { |
|
106 | + private function reallyAddToArchive ( string $archiveTitle, array $pages ) { |
|
107 | 107 | $archivePage = $this->getPage( "$archiveTitle/" . date( 'Y' ) ); |
108 | 108 | $exists = $archivePage->exists(); |
109 | 109 | |
110 | 110 | $append = "\n"; |
111 | - $archivedList = []; |
|
111 | + $archivedList = [ ]; |
|
112 | 112 | foreach ( $pages as $page ) { |
113 | 113 | $append .= '{{' . $page->getTitle() . "}}\n"; |
114 | - $archivedList[] = $page->getUserNum(); |
|
114 | + $archivedList[ ] = $page->getUserNum(); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $summary = $this->msg( 'close-archive-summary' ) |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @param string $archiveTitle |
134 | 134 | */ |
135 | - private function addArchiveYear( string $archiveTitle ) { |
|
135 | + private function addArchiveYear ( string $archiveTitle ) { |
|
136 | 136 | $page = $this->getPage( $archiveTitle ); |
137 | 137 | $year = date( 'Y' ); |
138 | 138 |
@@ -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 | |
19 | 19 | if ( !$pages ) { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @param PageRiconferma $page |
37 | 37 | */ |
38 | - protected function addVoteCloseText( PageRiconferma $page ) { |
|
38 | + protected function addVoteCloseText ( PageRiconferma $page ) { |
|
39 | 39 | $content = $page->getContent(); |
40 | 40 | $beforeReg = '!è necessario ottenere una maggioranza .+ votanti\.!'; |
41 | 41 | $newContent = preg_replace( $beforeReg, '$0' . "\n" . $page->getOutcomeText(), $content ); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param PageRiconferma $page |
51 | 51 | * @see CreatePages::updateBasePage() |
52 | 52 | */ |
53 | - protected function updateBasePage( PageRiconferma $page ) { |
|
53 | + protected function updateBasePage ( PageRiconferma $page ) { |
|
54 | 54 | $this->getLogger()->info( "Updating base page for $page" ); |
55 | 55 | |
56 | 56 | if ( $page->getNum() === 1 ) { |
@@ -62,8 +62,7 @@ discard block |
||
62 | 62 | $current = $basePage->getContent(); |
63 | 63 | |
64 | 64 | $outcomeText = $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ? |
65 | - 'non riconfermato' : |
|
66 | - 'riconfermato'; |
|
65 | + 'non riconfermato' : 'riconfermato'; |
|
67 | 66 | $text = $page->isVote() ? "votazione: $outcomeText" : 'riconferma tacita'; |
68 | 67 | |
69 | 68 | $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 | |
@@ -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 | $users = $this->getDataProvider()->getUsersToProcess(); |
21 | 21 | |
22 | 22 | if ( !$users ) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param User $user |
37 | 37 | * @throws TaskException |
38 | 38 | */ |
39 | - protected function processUser( User $user ) { |
|
39 | + protected function processUser ( User $user ) { |
|
40 | 40 | try { |
41 | 41 | $num = $this->getLastPageNum( $user ) + 1; |
42 | 42 | } catch ( TaskException $e ) { |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | * @return int |
71 | 71 | * @throws TaskException |
72 | 72 | */ |
73 | - protected function getLastPageNum( User $user ) : int { |
|
73 | + protected function getLastPageNum ( User $user ) : int { |
|
74 | 74 | $this->getLogger()->debug( "Retrieving previous pages for $user" ); |
75 | 75 | |
76 | - $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[1]; |
|
76 | + $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[ 1 ]; |
|
77 | 77 | |
78 | 78 | $prefixes = [ "$unprefixedTitle/$user/" ]; |
79 | 79 | foreach ( $user->getAliases() as $alias ) { |
80 | - $prefixes[] = "$unprefixedTitle/$alias/"; |
|
80 | + $prefixes[ ] = "$unprefixedTitle/$alias/"; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $params = [ |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | * @param string $title |
114 | 114 | * @param User $user |
115 | 115 | */ |
116 | - protected function createPage( string $title, User $user ) { |
|
116 | + protected function createPage ( string $title, User $user ) { |
|
117 | 117 | $this->getLogger()->info( "Creating page $title" ); |
118 | 118 | $groups = $user->getGroups(); |
119 | 119 | $textParams = [ |
120 | 120 | '$user' => $user->getName(), |
121 | - '$date' => $groups['sysop'], |
|
122 | - '$burocrate' => $groups['bureaucrat'] ?? '', |
|
123 | - '$checkuser' => $groups['checkuser'] ?? '' |
|
121 | + '$date' => $groups[ 'sysop' ], |
|
122 | + '$burocrate' => $groups[ 'bureaucrat' ] ?? '', |
|
123 | + '$checkuser' => $groups[ 'checkuser' ] ?? '' |
|
124 | 124 | ]; |
125 | 125 | |
126 | 126 | $params = [ |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @param string $title |
139 | 139 | * @param string $newText |
140 | 140 | */ |
141 | - protected function createBasePage( string $title, string $newText ) { |
|
141 | + protected function createBasePage ( string $title, string $newText ) { |
|
142 | 142 | $this->getLogger()->info( "Creating base page $title" ); |
143 | 143 | |
144 | 144 | $params = [ |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @param Page $basePage |
156 | 156 | * @param string $newText |
157 | 157 | */ |
158 | - protected function updateBasePage( Page $basePage, string $newText ) { |
|
158 | + protected function updateBasePage ( Page $basePage, string $newText ) { |
|
159 | 159 | $this->getLogger()->info( "Updating base page $basePage" ); |
160 | 160 | |
161 | 161 | $params = [ |
@@ -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 ) { |
|
41 | + protected function updateVotazioni ( array $pages ) { |
|
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 ) { |
|
70 | + protected function updateNews ( array $pages ) { |
|
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 ) { |
|
109 | + protected function updateAdminList ( array $outcomes ) { |
|
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}' . date( '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,12 +149,12 @@ 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 | if ( $date < new \DateTime ) { |
160 | 160 | $date->modify( '+1 year' ); |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | } else { |
164 | 164 | $ts = PageBotList::getValidFlagTimestamp( $userInfo ); |
165 | 165 | $res = strtotime( date( 'Y', strtotime( '+1 year' ) ) . date( '-m-d', $ts ) ); |
166 | - if ( isset( $userInfo['override'] ) ) { |
|
167 | - $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo['override'] ); |
|
166 | + if ( isset( $userInfo[ 'override' ] ) ) { |
|
167 | + $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo[ 'override' ] ); |
|
168 | 168 | if ( $date > new \DateTime ) { |
169 | 169 | $res = $date->getTimestamp(); |
170 | 170 | } |
@@ -176,21 +176,21 @@ discard block |
||
176 | 176 | /** |
177 | 177 | * @param bool[] $outcomes |
178 | 178 | */ |
179 | - protected function updateCUList( array $outcomes ) { |
|
179 | + protected function updateCUList ( array $outcomes ) { |
|
180 | 180 | $this->getLogger()->info( 'Updating CU list.' ); |
181 | 181 | $cuList = $this->getPage( $this->getOpt( 'cu-list-title' ) ); |
182 | 182 | $newContent = $cuList->getContent(); |
183 | 183 | |
184 | - $riconfNames = $removeNames = []; |
|
184 | + $riconfNames = $removeNames = [ ]; |
|
185 | 185 | foreach ( $outcomes as $user => $confirmed ) { |
186 | 186 | $userReg = $this->getUser( $user )->getRegex(); |
187 | 187 | $reg = "!(\{\{ *Checkuser *\| *$userReg *\|[^}]+\| *)[\w \d]+(}}.*\n)!"; |
188 | 188 | if ( $confirmed ) { |
189 | 189 | $newContent = preg_replace( $reg, '${1}{{subst:#time:j F Y}}$2', $newContent ); |
190 | - $riconfNames[] = $user; |
|
190 | + $riconfNames[ ] = $user; |
|
191 | 191 | } else { |
192 | 192 | $newContent = preg_replace( $reg, '', $newContent ); |
193 | - $removeNames[] = $user; |
|
193 | + $removeNames[ ] = $user; |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param PageRiconferma[] $pages |
215 | 215 | * @return bool[] |
216 | 216 | */ |
217 | - private function getGroupOutcomes( string $group, array $pages ) : array { |
|
218 | - $ret = []; |
|
217 | + private function getGroupOutcomes ( string $group, array $pages ) : array { |
|
218 | + $ret = [ ]; |
|
219 | 219 | foreach ( $pages as $page ) { |
220 | 220 | $user = $page->getUser(); |
221 | 221 | 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; |
4 | 4 | |
@@ -14,16 +14,16 @@ discard block |
||
14 | 14 | /** @var User[]|null */ |
15 | 15 | private $processUsers; |
16 | 16 | /** @var PageRiconferma[] */ |
17 | - private $createdPages = []; |
|
17 | + private $createdPages = [ ]; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Get a list of users to execute tasks on. |
21 | 21 | * |
22 | 22 | * @return User[] |
23 | 23 | */ |
24 | - public function getUsersToProcess() : array { |
|
24 | + public function getUsersToProcess () : array { |
|
25 | 25 | if ( $this->processUsers === null ) { |
26 | - $this->processUsers = []; |
|
26 | + $this->processUsers = [ ]; |
|
27 | 27 | foreach ( PageBotList::get( $this->getWiki() )->getAdminsList() as $name => $user ) { |
28 | 28 | if ( $this->shouldAddUser( $user ) ) { |
29 | 29 | $this->processUsers[ $name ] = $user; |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param User $user |
41 | 41 | * @return bool |
42 | 42 | */ |
43 | - private function shouldAddUser( User $user ) : bool { |
|
43 | + private function shouldAddUser ( User $user ) : bool { |
|
44 | 44 | $override = true; |
45 | 45 | $timestamp = PageBotList::getOverrideTimestamp( $user->getUserInfo() ); |
46 | 46 | |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return PageRiconferma[] |
61 | 61 | */ |
62 | - public function getOpenPages() : array { |
|
62 | + public function getOpenPages () : array { |
|
63 | 63 | static $list = null; |
64 | 64 | if ( $list === null ) { |
65 | - $list = []; |
|
65 | + $list = [ ]; |
|
66 | 66 | $mainTitle = $this->getOpt( 'main-page-title' ); |
67 | 67 | $params = [ |
68 | 68 | 'action' => 'query', |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $pages = RequestBase::newFromParams( $params )->execute()->query->pages; |
77 | 77 | foreach ( reset( $pages )->templates as $page ) { |
78 | 78 | if ( preg_match( "!$titleReg\/[^\/]+\/\d!", $page->title ) ) { |
79 | - $list[] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
79 | + $list[ ] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return PageRiconferma[] |
91 | 91 | */ |
92 | - public function getPagesToClose() : array { |
|
92 | + public function getPagesToClose () : array { |
|
93 | 93 | static $list = null; |
94 | 94 | if ( $list === null ) { |
95 | - $list = []; |
|
95 | + $list = [ ]; |
|
96 | 96 | foreach ( $this->getOpenPages() as $page ) { |
97 | 97 | if ( time() > $page->getEndTimestamp() ) { |
98 | - $list[] = $page; |
|
98 | + $list[ ] = $page; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
@@ -107,21 +107,21 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @param string $name |
109 | 109 | */ |
110 | - public function removeUser( string $name ) { |
|
110 | + public function removeUser ( string $name ) { |
|
111 | 111 | unset( $this->processUsers[ $name ] ); |
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @return PageRiconferma[] |
116 | 116 | */ |
117 | - public function getCreatedPages() : array { |
|
117 | + public function getCreatedPages () : array { |
|
118 | 118 | return $this->createdPages; |
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
122 | 122 | * @param PageRiconferma $page |
123 | 123 | */ |
124 | - public function addCreatedPage( PageRiconferma $page ) { |
|
125 | - $this->createdPages[] = $page; |
|
124 | + public function addCreatedPage ( PageRiconferma $page ) { |
|
125 | + $this->createdPages[ ] = $page; |
|
126 | 126 | } |
127 | 127 | } |