Passed
Push — master ( 267c20...89d164 )
by Daimona
01:43
created
includes/Task/UpdateList.php 1 patch
Spacing   +30 added lines, -30 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
 
@@ -19,15 +19,15 @@  discard block
 block discarded – undo
19 19
 	/**
20 20
 	 * @inheritDoc
21 21
 	 */
22
-	protected function getSubtasksMap(): array {
22
+	protected function getSubtasksMap (): array {
23 23
 		// Everything is done here.
24
-		return [];
24
+		return [ ];
25 25
 	}
26 26
 
27 27
 	/**
28 28
 	 * @inheritDoc
29 29
 	 */
30
-	public function runInternal() : int {
30
+	public function runInternal () : int {
31 31
 		$this->actualList = $this->getActualAdmins();
32 32
 		$pageBotList = PageBotList::get( $this->getWiki() );
33 33
 		$this->botList = $pageBotList->getAdminsList();
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	/**
55 55
 	 * @return array
56 56
 	 */
57
-	protected function getActualAdmins() : array {
57
+	protected function getActualAdmins () : array {
58 58
 		$params = [
59 59
 			'action' => 'query',
60 60
 			'list' => 'allusers',
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 	 * @param \stdClass $data
72 72
 	 * @return array
73 73
 	 */
74
-	protected function extractAdmins( \stdClass $data ) : array {
75
-		$ret = [];
74
+	protected function extractAdmins ( \stdClass $data ) : array {
75
+		$ret = [ ];
76 76
 		$blacklist = $this->getOpt( 'exclude-admins' );
77 77
 		foreach ( $data->query->allusers as $u ) {
78 78
 			if ( in_array( $u->name, $blacklist ) ) {
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return array[]
91 91
 	 */
92
-	protected function getMissingGroups() : array {
93
-		$missing = [];
92
+	protected function getMissingGroups () : array {
93
+		$missing = [ ];
94 94
 		foreach ( $this->actualList as $adm => $groups ) {
95
-			$curMissing = array_diff( $groups, array_keys( $this->botList[$adm] ?? [] ) );
95
+			$curMissing = array_diff( $groups, array_keys( $this->botList[ $adm ] ?? [ ] ) );
96 96
 
97 97
 			foreach ( $curMissing as $group ) {
98 98
 				try {
99 99
 					$missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group );
100 100
 				} catch ( TaskException $e ) {
101
-					$this->errors[] = $e->getMessage();
101
+					$this->errors[ ] = $e->getMessage();
102 102
 				}
103 103
 			}
104 104
 		}
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 * @return string
114 114
 	 * @throws TaskException
115 115
 	 */
116
-	protected function getFlagDate( string $admin, string $group ) : string {
116
+	protected function getFlagDate ( string $admin, string $group ) : string {
117 117
 		$this->getLogger()->info( "Retrieving $group flag date for $admin" );
118 118
 
119 119
 		$url = DEFAULT_URL;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @param string $group
150 150
 	 * @return string|null
151 151
 	 */
152
-	private function extractTimestamp( \stdClass $data, string $group ) : ?string {
152
+	private function extractTimestamp ( \stdClass $data, string $group ) : ?string {
153 153
 		$ts = null;
154 154
 		foreach ( $data->query->logevents as $entry ) {
155 155
 			if ( isset( $entry->params ) ) {
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 	 *
169 169
 	 * @return array[]
170 170
 	 */
171
-	protected function getExtraGroups() : array {
172
-		$extra = [];
171
+	protected function getExtraGroups () : array {
172
+		$extra = [ ];
173 173
 		foreach ( $this->botList as $name => $groups ) {
174 174
 			$groups = array_diff_key( $groups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) );
175 175
 			if ( !isset( $this->actualList[ $name ] ) ) {
@@ -187,9 +187,9 @@  discard block
 block discarded – undo
187 187
 	 * @param string[] $names
188 188
 	 * @return string[] [ old_name => new_name ]
189 189
 	 */
190
-	protected function checkRenamedUsers( array $names ) : array {
190
+	protected function checkRenamedUsers ( array $names ) : array {
191 191
 		if ( !$names ) {
192
-			return [];
192
+			return [ ];
193 193
 		}
194 194
 		$this->getLogger()->info( 'Checking rename for ' . implode( ', ', $names ) );
195 195
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 		];
208 208
 
209 209
 		$data = RequestBase::newFromParams( $params )->execute();
210
-		$ret = [];
210
+		$ret = [ ];
211 211
 		foreach ( $data->query->logevents as $entry ) {
212 212
 			$time = strtotime( $entry->timestamp );
213 213
 			// 1 month is arbitrary
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 	 * @param array[] $extra
228 228
 	 * @return array[]
229 229
 	 */
230
-	protected function getNewContent( array $missing, array $extra ) : array {
230
+	protected function getNewContent ( array $missing, array $extra ) : array {
231 231
 		$newContent = $this->botList;
232 232
 		$renameMap = $this->checkRenamedUsers( array_keys( $extra ) );
233
-		$removed = [];
233
+		$removed = [ ];
234 234
 		foreach ( $newContent as $user => $groups ) {
235 235
 			if ( isset( $missing[ $user ] ) ) {
236 236
 				$newContent[ $user ] = array_merge( $groups, $missing[ $user ] );
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 				if ( array_diff_key( $newGroups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ) ) {
241 241
 					$newContent[ $user ] = $newGroups;
242 242
 				} else {
243
-					$removed[$user] = $newContent[$user];
243
+					$removed[ $user ] = $newContent[ $user ];
244 244
 					unset( $newContent[ $user ] );
245 245
 				}
246 246
 			}
@@ -251,17 +251,17 @@  discard block
 block discarded – undo
251 251
 		foreach ( $removed as $oldName => $info ) {
252 252
 			if (
253 253
 				array_key_exists( $oldName, $renameMap ) &&
254
-				array_key_exists( $renameMap[$oldName], $newContent )
254
+				array_key_exists( $renameMap[ $oldName ], $newContent )
255 255
 			) {
256 256
 				// This user was renamed! Add this name as alias, if they're still listed
257 257
 				$newName = $renameMap[ $oldName ];
258 258
 				$this->getLogger()->info( "Found rename $oldName -> $newName" );
259 259
 				if ( array_key_exists( 'aliases', $newContent[ $newName ] ) ) {
260
-					if ( !in_array( $oldName, $newContent[ $newName ]['aliases'] ) ) {
261
-						$newContent[ $newName ]['aliases'][] = $oldName;
260
+					if ( !in_array( $oldName, $newContent[ $newName ][ 'aliases' ] ) ) {
261
+						$newContent[ $newName ][ 'aliases' ][ ] = $oldName;
262 262
 					}
263 263
 				} else {
264
-					$newContent[ $newName ]['aliases'] = [ $oldName ];
264
+					$newContent[ $newName ][ 'aliases' ] = [ $oldName ];
265 265
 				}
266 266
 				// Transfer overrides to the new name.
267 267
 				$overrides = array_diff_key( $info, [ 'override' => 1, 'override-perm' => 1 ] );
@@ -281,21 +281,21 @@  discard block
 block discarded – undo
281 281
 	 * @param array[] $newContent
282 282
 	 * @return array[]
283 283
 	 */
284
-	protected function removeOverrides( array $newContent ) : array {
285
-		$removed = [];
284
+	protected function removeOverrides ( array $newContent ) : array {
285
+		$removed = [ ];
286 286
 		foreach ( $newContent as $user => $groups ) {
287
-			if ( !isset( $groups['override'] ) ) {
287
+			if ( !isset( $groups[ 'override' ] ) ) {
288 288
 				continue;
289 289
 			}
290 290
 
291 291
 			$flagTS = PageBotList::getValidFlagTimestamp( $groups );
292 292
 			$usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) );
293
-			$overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp();
293
+			$overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp();
294 294
 			$delay = 60 * 60 * 24 * 3;
295 295
 
296 296
 			if ( time() > $usualTS + $delay && time() > $overrideTS + $delay ) {
297 297
 				unset( $newContent[ $user ][ 'override' ] );
298
-				$removed[] = $user;
298
+				$removed[ ] = $user;
299 299
 			}
300 300
 		}
301 301
 
Please login to merge, or discard this patch.