Passed
Push — master ( f088dd...ffd2c6 )
by Daimona
01:47
created
src/Task/UpdateList.php 1 patch
Spacing   +44 added lines, -44 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
 
@@ -22,15 +22,15 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @inheritDoc
24 24
 	 */
25
-	protected function getSubtasksMap(): array {
25
+	protected function getSubtasksMap (): array {
26 26
 		// Everything is done here.
27
-		return [];
27
+		return [ ];
28 28
 	}
29 29
 
30 30
 	/**
31 31
 	 * @inheritDoc
32 32
 	 */
33
-	public function runInternal(): int {
33
+	public function runInternal (): int {
34 34
 		$this->actualList = $this->computeActualList();
35 35
 		$pageBotList = $this->getBotList();
36 36
 		$botList = $pageBotList->getDecodedContent();
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 * @return string[][]
56 56
 	 * @phan-return array<string,string[]>
57 57
 	 */
58
-	private function computeActualList(): array {
58
+	private function computeActualList (): array {
59 59
 		$params = [
60 60
 			'action' => 'query',
61 61
 			'list' => 'allusers',
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	 * @return string[][]
74 74
 	 * @phan-return array<string,string[]>
75 75
 	 */
76
-	private function extractAdminsData( Generator $data ): array {
77
-		$ret = [];
76
+	private function extractAdminsData ( Generator $data ): array {
77
+		$ret = [ ];
78 78
 		$blacklist = $this->getOpt( 'exclude-admins' );
79 79
 		foreach ( $data as $user ) {
80 80
 			if ( in_array( $user->name, $blacklist, true ) ) {
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 * @phan-param array<string,array{sysop:string,checkuser?:string,bureaucrat?:string,override?:string,override-perm?:string,aliases?:list<string>}> $curList
95 95
 	 * @return array[]
96 96
 	 */
97
-	private function computeNewList( array $curList ): array {
97
+	private function computeNewList ( array $curList ): array {
98 98
 		$newList = $curList;
99 99
 
100 100
 		$extra = $this->getExtraAdminGroups( $curList );
@@ -114,21 +114,21 @@  discard block
 block discarded – undo
114 114
 	 * @phan-param array<string,array<string,string|string[]>> $newContent
115 115
 	 * @param array $extra
116 116
 	 */
117
-	private function handleExtraAndMissing( array &$newList, array $extra ): void {
117
+	private function handleExtraAndMissing ( array &$newList, array $extra ): void {
118 118
 		$missing = $this->getMissingAdminGroups( $newList );
119 119
 
120
-		$removed = [];
120
+		$removed = [ ];
121 121
 		foreach ( $newList as $user => $data ) {
122
-			if ( isset( $missing[$user] ) ) {
123
-				$newList[$user] = array_merge( $data, $missing[$user] );
124
-				unset( $missing[$user] );
125
-			} elseif ( isset( $extra[$user] ) ) {
126
-				$newGroups = array_diff_key( $data, $extra[$user] );
122
+			if ( isset( $missing[ $user ] ) ) {
123
+				$newList[ $user ] = array_merge( $data, $missing[ $user ] );
124
+				unset( $missing[ $user ] );
125
+			} elseif ( isset( $extra[ $user ] ) ) {
126
+				$newGroups = array_diff_key( $data, $extra[ $user ] );
127 127
 				if ( array_diff_key( $newGroups, self::NON_GROUP_KEYS ) ) {
128
-					$newList[$user] = $newGroups;
128
+					$newList[ $user ] = $newGroups;
129 129
 				} else {
130
-					$removed[] = $user;
131
-					unset( $newList[$user] );
130
+					$removed[ ] = $user;
131
+					unset( $newList[ $user ] );
132 132
 				}
133 133
 			}
134 134
 		}
@@ -145,17 +145,17 @@  discard block
 block discarded – undo
145 145
 	 * @param array $botList
146 146
 	 * @return string[][]
147 147
 	 */
148
-	private function getMissingAdminGroups( array $botList ): array {
149
-		$missing = [];
148
+	private function getMissingAdminGroups ( array $botList ): array {
149
+		$missing = [ ];
150 150
 		foreach ( $this->actualList as $admin => $groups ) {
151
-			$missingGroups = array_diff( $groups, array_keys( $botList[$admin] ?? [] ) );
151
+			$missingGroups = array_diff( $groups, array_keys( $botList[ $admin ] ?? [ ] ) );
152 152
 			foreach ( $missingGroups as $group ) {
153 153
 				$ts = $this->getFlagDate( $admin, $group );
154 154
 				if ( $ts === null ) {
155
-					$this->errors[] = "$group flag date unavailable for $admin";
155
+					$this->errors[ ] = "$group flag date unavailable for $admin";
156 156
 					continue;
157 157
 				}
158
-				$missing[$admin][$group] = $ts;
158
+				$missing[ $admin ][ $group ] = $ts;
159 159
 			}
160 160
 		}
161 161
 		return $missing;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @param string $group
169 169
 	 * @return string|null
170 170
 	 */
171
-	private function getFlagDate( string $admin, string $group ): ?string {
171
+	private function getFlagDate ( string $admin, string $group ): ?string {
172 172
 		$this->getLogger()->info( "Retrieving $group flag date for $admin" );
173 173
 
174 174
 		$wiki = $this->getWiki();
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	 * @param string $group
200 200
 	 * @return string|null
201 201
 	 */
202
-	private function extractTimestamp( Generator $data, string $group ): ?string {
202
+	private function extractTimestamp ( Generator $data, string $group ): ?string {
203 203
 		$ts = null;
204 204
 		foreach ( $data as $entry ) {
205 205
 			if (
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 	 * @phan-param array<string,array{sysop:string,checkuser?:string,bureaucrat?:string,override?:string,override-perm?:string,aliases?:list<string>}> $botList
222 222
 	 * @return string[][]
223 223
 	 */
224
-	private function getExtraAdminGroups( array $botList ): array {
225
-		$extra = [];
224
+	private function getExtraAdminGroups ( array $botList ): array {
225
+		$extra = [ ];
226 226
 		foreach ( $botList as $name => $data ) {
227 227
 			$groups = array_diff_key( $data, self::NON_GROUP_KEYS );
228
-			if ( !isset( $this->actualList[$name] ) ) {
229
-				$extra[$name] = $groups;
230
-			} elseif ( count( $groups ) > count( $this->actualList[$name] ) ) {
231
-				$extra[$name] = array_diff_key( $groups, $this->actualList[$name] );
228
+			if ( !isset( $this->actualList[ $name ] ) ) {
229
+				$extra[ $name ] = $groups;
230
+			} elseif ( count( $groups ) > count( $this->actualList[ $name ] ) ) {
231
+				$extra[ $name ] = array_diff_key( $groups, $this->actualList[ $name ] );
232 232
 			}
233 233
 		}
234 234
 		return $extra;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 	 * @param string[] $oldNames
239 239
 	 * @return Generator
240 240
 	 */
241
-	private function getRenameEntries( array $oldNames ): Generator {
241
+	private function getRenameEntries ( array $oldNames ): Generator {
242 242
 		$titles = array_map( static function ( string $x ): string {
243 243
 			return "Utente:$x";
244 244
 		}, $oldNames );
@@ -262,14 +262,14 @@  discard block
 block discarded – undo
262 262
 	 * @param string[] $oldNames
263 263
 	 * @return string[] [ old_name => new_name ]
264 264
 	 */
265
-	private function getRenamedUsers( array $oldNames ): array {
265
+	private function getRenamedUsers ( array $oldNames ): array {
266 266
 		if ( !$oldNames ) {
267
-			return [];
267
+			return [ ];
268 268
 		}
269 269
 		$this->getLogger()->info( 'Checking rename for ' . implode( ', ', $oldNames ) );
270 270
 
271 271
 		$data = $this->getRenameEntries( $oldNames );
272
-		$ret = [];
272
+		$ret = [ ];
273 273
 		foreach ( $data as $entry ) {
274 274
 			// 1 month is arbitrary
275 275
 			if ( strtotime( $entry->timestamp ) > strtotime( '-1 month' ) ) {
@@ -290,15 +290,15 @@  discard block
 block discarded – undo
290 290
 	 * @param string[][] $extra
291 291
 	 * @return array<string,string> Map of renamed users
292 292
 	 */
293
-	private function handleRenames( array &$newList, array $extra ): array {
293
+	private function handleRenames ( array &$newList, array $extra ): array {
294 294
 		$renameMap = $this->getRenamedUsers( array_keys( $extra ) );
295 295
 		foreach ( $renameMap as $oldName => $newName ) {
296 296
 			$this->getLogger()->info( "Found rename $oldName -> $newName" );
297
-			$newList[$newName] = $newList[$oldName];
298
-			$newList[$newName]['aliases'] = array_unique(
299
-				array_merge( $newList[$newName]['aliases'] ?? [], [ $oldName ] )
297
+			$newList[ $newName ] = $newList[ $oldName ];
298
+			$newList[ $newName ][ 'aliases' ] = array_unique(
299
+				array_merge( $newList[ $newName ][ 'aliases' ] ?? [ ], [ $oldName ] )
300 300
 			);
301
-			unset( $newList[$oldName] );
301
+			unset( $newList[ $oldName ] );
302 302
 		}
303 303
 		return $renameMap;
304 304
 	}
@@ -308,12 +308,12 @@  discard block
 block discarded – undo
308 308
 	 *
309 309
 	 * @param array[] &$newList
310 310
 	 */
311
-	private function removeOverrides( array &$newList ): void {
312
-		$removed = [];
311
+	private function removeOverrides ( array &$newList ): void {
312
+		$removed = [ ];
313 313
 		foreach ( $newList as $user => $data ) {
314 314
 			if ( PageBotList::isOverrideExpired( $data ) ) {
315
-				unset( $newList[$user]['override'] );
316
-				$removed[] = $user;
315
+				unset( $newList[ $user ][ 'override' ] );
316
+				$removed[ ] = $user;
317 317
 			}
318 318
 		}
319 319
 
Please login to merge, or discard this patch.