Passed
Push — master ( 6f3cd3...2e7fdd )
by Daimona
01:50
created
includes/PageRiconferma.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme;
4 4
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @param string $title
30 30
 	 * @param WikiController $controller
31 31
 	 */
32
-	public function __construct( string $title, WikiController $controller ) {
32
+	public function __construct ( string $title, WikiController $controller ) {
33 33
 		$this->title = $title;
34 34
 		$this->controller = $controller;
35 35
 	}
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @return string
39 39
 	 */
40
-	public function getTitle() : string {
40
+	public function getTitle () : string {
41 41
 		return $this->title;
42 42
 	}
43 43
 
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @return string
48 48
 	 */
49
-	public function getUser() : string {
50
-		return explode( '/', $this->title )[2];
49
+	public function getUser () : string {
50
+		return explode( '/', $this->title )[ 2 ];
51 51
 	}
52 52
 
53 53
 	/**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
74 74
 	 *
75 75
 	 * @return string
76 76
 	 */
77
-	public function getBaseTitle() : string {
77
+	public function getBaseTitle () : string {
78 78
 		// @phan-suppress-next-line PhanTypeMismatchArgumentInternal Phan bug
79 79
 		return substr( $this->getTitle(), 0, strrpos( $this->getTitle(), '/' ) );
80 80
 	}
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @return string
86 86
 	 */
87
-	public function getContent() : string {
87
+	public function getContent () : string {
88 88
 		if ( $this->content === null ) {
89 89
 			$this->content = $this->controller->getPageContent( $this->title );
90 90
 		}
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 	 * @return int
98 98
 	 */
99
-	public function getOpposingCount() : int {
99
+	public function getOpposingCount () : int {
100 100
 		return $this->getCountForSection( self::SECTION_OPPOSE );
101 101
 	}
102 102
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @return int
107 107
 	 */
108
-	public function getSupportCount() : int {
108
+	public function getSupportCount () : int {
109 109
 		return $this->getCountForSection( self::SECTION_SUPPORT );
110 110
 	}
111 111
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @param int $secNum
116 116
 	 * @return int
117 117
 	 */
118
-	protected function getCountForSection( int $secNum ) : int {
118
+	protected function getCountForSection ( int $secNum ) : int {
119 119
 		$params = [
120 120
 			'action' => 'query',
121 121
 			'prop' => 'revisions',
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 
128 128
 		$res = RequestBase::newFromParams( $params )->execute();
129 129
 		$page = reset( $res->query->pages );
130
-		$content = $page->revisions[0]->slots->main->{ '*' };
130
+		$content = $page->revisions[ 0 ]->slots->main->{ '*' };
131 131
 		// Let's hope that this is good enough...
132 132
 		return substr_count( $content, "\n\# *(?![#*])" );
133 133
 	}
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
 	 *
138 138
 	 * @return int
139 139
 	 */
140
-	protected function getQuorum() : int {
140
+	protected function getQuorum () : int {
141 141
 		$reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!";
142
-		$matches = [];
142
+		$matches = [ ];
143 143
 		preg_match( $reg, $this->getContent(), $matches );
144
-		return intval( $matches[1] );
144
+		return intval( $matches[ 1 ] );
145 145
 	}
146 146
 
147 147
 	/**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 *
150 150
 	 * @return bool
151 151
 	 */
152
-	public function hasOpposition() : bool {
152
+	public function hasOpposition () : bool {
153 153
 		return $this->getOpposingCount() >= 15;
154 154
 	}
155 155
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @return int One of the OUTCOME_* constants
160 160
 	 * @throws \BadMethodCallException
161 161
 	 */
162
-	public function getOutcome() : int {
162
+	public function getOutcome () : int {
163 163
 		if ( !$this->isVote() ) {
164 164
 			throw new \BadMethodCallException( 'Cannot get outcome for a non-vote page.' );
165 165
 		}
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @return string
179 179
 	 * @throws \BadMethodCallException
180 180
 	 */
181
-	public function getOutcomeText() : string {
181
+	public function getOutcomeText () : string {
182 182
 		if ( !$this->isVote() ) {
183 183
 			throw new \BadMethodCallException( 'No need for an outcome text.' );
184 184
 		}
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	 *
211 211
 	 * @return bool
212 212
 	 */
213
-	public function isVote() : bool {
213
+	public function isVote () : bool {
214 214
 		$sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/';
215 215
 		return preg_match( $sectionReg, $this->getContent() ) === false;
216 216
 	}
@@ -220,9 +220,9 @@  discard block
 block discarded – undo
220 220
 	 *
221 221
 	 * @return int
222 222
 	 */
223
-	public function getEndTimestamp() : int {
223
+	public function getEndTimestamp () : int {
224 224
 		if ( $this->isVote() ) {
225
-			$matches = [];
225
+			$matches = [ ];
226 226
 			$reg = "!La votazione ha inizio il.+ e ha termine.+ '''([^']+)''' alle ore '''([^']+)'''!";
227 227
 			preg_match( $reg, $this->getContent(), $matches );
228 228
 			list( , $day, $hours ) = $matches;
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		}
235 235
 	}
236 236
 
237
-	public function __toString() {
237
+	public function __toString () {
238 238
 		return $this->getTitle();
239 239
 	}
240 240
 }
Please login to merge, or discard this patch.
includes/Task/ClosePages.php 1 patch
Spacing   +33 added lines, -34 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme\Task;
4 4
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 	/**
14 14
 	 * @inheritDoc
15 15
 	 */
16
-	public function run() : TaskResult {
16
+	public function run () : TaskResult {
17 17
 		$this->getLogger()->info( 'Starting task ClosePages' );
18 18
 
19 19
 		$pages = $this->getPagesList();
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @return PageRiconferma[]
43 43
 	 */
44
-	protected function getPagesList() : array {
44
+	protected function getPagesList () : array {
45 45
 		$allPages = $this->getDataProvider()->getOpenPages();
46
-		$ret = [];
46
+		$ret = [ ];
47 47
 		foreach ( $allPages as $page ) {
48 48
 			if ( time() > $page->getEndTimestamp() ) {
49
-				$ret[] = $page;
49
+				$ret[ ] = $page;
50 50
 			}
51 51
 		}
52 52
 		return $ret;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	/**
56 56
 	 * @param PageRiconferma $page
57 57
 	 */
58
-	protected function addVoteCloseText( PageRiconferma $page ) {
58
+	protected function addVoteCloseText ( PageRiconferma $page ) {
59 59
 		$content = $page->getContent();
60 60
 		$beforeReg = '!è necessario ottenere una maggioranza .+ votanti\.!';
61 61
 		$newContent = preg_replace( $beforeReg, '$0' . "\n" . $page->getOutcomeText(), $content );
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 	 * @param PageRiconferma[] $pages
75 75
 	 * @see UpdatesAround::addToMainPage()
76 76
 	 */
77
-	protected function removeFromMainPage( array $pages ) {
77
+	protected function removeFromMainPage ( array $pages ) {
78 78
 		$this->getLogger()->info(
79 79
 			'Removing from main: ' . implode( ', ', array_map( 'strval', $pages ) )
80 80
 		);
81 81
 
82 82
 		$mainPage = $this->getConfig()->get( 'ric-main-page' );
83 83
 		$content = $this->getController()->getPageContent( $mainPage );
84
-		$translations = [];
84
+		$translations = [ ];
85 85
 		foreach ( $pages as $page ) {
86 86
 			$translations[ '{{' . $page->getTitle() . '}}' ] = '';
87 87
 		}
@@ -99,17 +99,17 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 * @param PageRiconferma[] $pages
101 101
 	 */
102
-	protected function addToArchive( array $pages ) {
102
+	protected function addToArchive ( array $pages ) {
103 103
 		$this->getLogger()->info(
104 104
 			'Adding to archive: ' . implode( ', ', array_map( 'strval', $pages ) )
105 105
 		);
106 106
 
107
-		$simple = $votes = [];
107
+		$simple = $votes = [ ];
108 108
 		foreach ( $pages as $page ) {
109 109
 			if ( $page->isVote() ) {
110
-				$votes[] = $page;
110
+				$votes[ ] = $page;
111 111
 			} else {
112
-				$simple[] = $page;
112
+				$simple[ ] = $page;
113 113
 			}
114 114
 		}
115 115
 
@@ -126,21 +126,21 @@  discard block
 block discarded – undo
126 126
 	 * @param string $archiveTitle
127 127
 	 * @param array $pages
128 128
 	 */
129
-	private function reallyAddToArchive( string $archiveTitle, array $pages ) {
129
+	private function reallyAddToArchive ( string $archiveTitle, array $pages ) {
130 130
 		$curTitle = "$archiveTitle/" . date( 'Y' );
131 131
 
132 132
 		$append = '';
133
-		$archivedList = [];
133
+		$archivedList = [ ];
134 134
 		foreach ( $pages as $page ) {
135 135
 			$append .= '{{' . $page->getTitle() . "}}\n";
136
-			$archivedList[] = $page->getUserNum();
136
+			$archivedList[ ] = $page->getUserNum();
137 137
 		}
138 138
 
139 139
 		if ( count( $archivedList ) > 1 ) {
140 140
 			$last = array_pop( $archivedList );
141 141
 			$userNums = implode( ', ', $archivedList ) . " e $last";
142 142
 		} else {
143
-			$userNums = $archivedList[0];
143
+			$userNums = $archivedList[ 0 ];
144 144
 		}
145 145
 
146 146
 		$summary = strtr(
@@ -161,14 +161,13 @@  discard block
 block discarded – undo
161 161
 	 * @param PageRiconferma $page
162 162
 	 * @see CreatePages::updateBasePage()
163 163
 	 */
164
-	protected function updateBasePage( PageRiconferma $page ) {
164
+	protected function updateBasePage ( PageRiconferma $page ) {
165 165
 		$this->getLogger()->info( "Updating base page for $page" );
166 166
 
167 167
 		$current = $this->getController()->getPageContent( $page->getBaseTitle() );
168 168
 
169 169
 		$outcomeText = $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ?
170
-			'non riconfermato' :
171
-			'riconfermato';
170
+			'non riconfermato' : 'riconfermato';
172 171
 		$text = $page->isVote() ? "votazione: $outcomeText" : 'riconferma tacita';
173 172
 
174 173
 		$newContent = str_replace( 'riconferma in corso', $text, $current );
@@ -185,13 +184,13 @@  discard block
 block discarded – undo
185 184
 	 * @param PageRiconferma[] $pages
186 185
 	 * @see UpdatesAround::addVote()
187 186
 	 */
188
-	protected function updateVote( array $pages ) {
187
+	protected function updateVote ( array $pages ) {
189 188
 		$votePage = $this->getConfig()->get( 'ric-vote-page' );
190 189
 		$content = $this->getController()->getPageContent( $votePage );
191 190
 
192
-		$titles = [];
191
+		$titles = [ ];
193 192
 		foreach ( $pages as $page ) {
194
-			$titles[] = preg_quote( $page->getTitle() );
193
+			$titles[ ] = preg_quote( $page->getTitle() );
195 194
 		}
196 195
 
197 196
 		$titleReg = implode( '|', $titles );
@@ -214,7 +213,7 @@  discard block
 block discarded – undo
214 213
 		$summary = preg_replace_callback(
215 214
 			'!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!',
216 215
 			function ( $matches ) {
217
-				return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] );
216
+				return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] );
218 217
 			},
219 218
 			$summary
220 219
 		);
@@ -232,7 +231,7 @@  discard block
 block discarded – undo
232 231
 	 * @param array $pages
233 232
 	 * @see UpdatesAround::addNews()
234 233
 	 */
235
-	protected function updateNews( array $pages ) {
234
+	protected function updateNews ( array $pages ) {
236 235
 		$simpleAmount = $voteAmount = 0;
237 236
 		foreach ( $pages as $page ) {
238 237
 			if ( $page->isVote() ) {
@@ -252,12 +251,12 @@  discard block
 block discarded – undo
252 251
 		$simpleReg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!';
253 252
 		$voteReg = '!(\| *riconferme[ _]voto[ _]amministratori *= *)(\d+)!';
254 253
 
255
-		$simpleMatches = $voteMatches = [];
254
+		$simpleMatches = $voteMatches = [ ];
256 255
 		preg_match( $simpleReg, $content, $simpleMatches );
257 256
 		preg_match( $voteReg, $content, $voteMatches );
258 257
 
259
-		$newSimp = (int)$simpleMatches[2] - $simpleAmount ?: '';
260
-		$newVote = (int)$voteMatches[2] - $voteAmount ?: '';
258
+		$newSimp = (int)$simpleMatches[ 2 ] - $simpleAmount ?: '';
259
+		$newVote = (int)$voteMatches[ 2 ] - $voteAmount ?: '';
261 260
 		$newContent = preg_replace( $simpleReg, '${1}' . $newSimp, $content );
262 261
 		$newContent = preg_replace( $voteReg, '${1}' . $newVote, $newContent );
263 262
 
@@ -268,7 +267,7 @@  discard block
 block discarded – undo
268 267
 		$summary = preg_replace_callback(
269 268
 			'!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!',
270 269
 			function ( $matches ) {
271
-				return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] );
270
+				return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] );
272 271
 			},
273 272
 			$summary
274 273
 		);
@@ -287,22 +286,22 @@  discard block
 block discarded – undo
287 286
 	 *
288 287
 	 * @param PageRiconferma[] $pages
289 288
 	 */
290
-	protected function updateAdminList( array $pages ) {
289
+	protected function updateAdminList ( array $pages ) {
291 290
 		$listTitle = $this->getConfig()->get( 'admins-list' );
292 291
 		$newContent = $this->getController()->getPageContent( $listTitle );
293 292
 		$newDate = date( 'Ymd', strtotime( '+1 year' ) );
294 293
 
295
-		$riconfNames = $removeNames = [];
294
+		$riconfNames = $removeNames = [ ];
296 295
 		foreach ( $pages as $page ) {
297 296
 			$user = $page->getUser();
298 297
 			$reg = "!(\{\{Amministratore\/riga\|$user.+\| *)\d+( *\|(?: *pausa)? *\}\}\n)!";
299 298
 			if ( $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ) {
300 299
 				// Remove the line
301 300
 				$newContent = preg_replace( $reg, '', $newContent );
302
-				$removeNames[] = $user;
301
+				$removeNames[ ] = $user;
303 302
 			} else {
304 303
 				$newContent = preg_replace( $reg, '$1' . $newDate . '$2', $newContent );
305
-				$riconfNames[] = $user;
304
+				$riconfNames[ ] = $user;
306 305
 			}
307 306
 		}
308 307
 
@@ -310,7 +309,7 @@  discard block
 block discarded – undo
310 309
 			$lastUser = array_pop( $riconfNames );
311 310
 			$riconfList = implode( ', ', $riconfNames ) . " e $lastUser";
312 311
 		} elseif ( $riconfNames ) {
313
-			$riconfList = $riconfNames[0];
312
+			$riconfList = $riconfNames[ 0 ];
314 313
 		} else {
315 314
 			$riconfList = 'nessuno';
316 315
 		}
@@ -319,7 +318,7 @@  discard block
 block discarded – undo
319 318
 			$lastUser = array_pop( $removeNames );
320 319
 			$removeList = implode( ', ', $removeNames ) . " e $lastUser";
321 320
 		} elseif ( $removeNames ) {
322
-			$removeList = $removeNames[0];
321
+			$removeList = $removeNames[ 0 ];
323 322
 		} else {
324 323
 			$removeList = 'nessuno';
325 324
 		}
Please login to merge, or discard this patch.