Passed
Push — master ( baa252...0fef2c )
by Daimona
01:42
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->getDecodedContent();
@@ -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 (
@@ -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 ] ) ) {
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * @param string[] $names
186 186
 	 * @return \stdClass
187 187
 	 */
188
-	private function getRenameEntries( array $names ) : \stdClass {
188
+	private function getRenameEntries ( array $names ) : \stdClass {
189 189
 		$titles = array_map( function ( $x ) {
190 190
 			return "Utente:$x";
191 191
 		}, $names );
@@ -209,14 +209,14 @@  discard block
 block discarded – undo
209 209
 	 * @param string[] $names
210 210
 	 * @return string[] [ old_name => new_name ]
211 211
 	 */
212
-	protected function getRenamedUsers( array $names ) : array {
212
+	protected function getRenamedUsers ( array $names ) : array {
213 213
 		if ( !$names ) {
214
-			return [];
214
+			return [ ];
215 215
 		}
216 216
 		$this->getLogger()->info( 'Checking rename for ' . implode( ', ', $names ) );
217 217
 
218 218
 		$data = $this->getRenameEntries( $names );
219
-		$ret = [];
219
+		$ret = [ ];
220 220
 		foreach ( $data->query->logevents as $entry ) {
221 221
 			// 1 month is arbitrary
222 222
 			if ( strtotime( $entry->timestamp ) > strtotime( '-1 month' ) ) {
@@ -234,18 +234,18 @@  discard block
 block discarded – undo
234 234
 	 * @param array &$newContent
235 235
 	 * @param array $removed
236 236
 	 */
237
-	private function handleRenames( array &$newContent, array $removed ) : void {
237
+	private function handleRenames ( array &$newContent, array $removed ) : void {
238 238
 		$renameMap = $this->getRenamedUsers( array_keys( $removed ) );
239 239
 		foreach ( $removed as $oldName => $info ) {
240 240
 			if (
241 241
 				array_key_exists( $oldName, $renameMap ) &&
242
-				array_key_exists( $renameMap[$oldName], $newContent )
242
+				array_key_exists( $renameMap[ $oldName ], $newContent )
243 243
 			) {
244 244
 				// This user was renamed! Add this name as alias, if they're still listed
245 245
 				$newName = $renameMap[ $oldName ];
246 246
 				$this->getLogger()->info( "Found rename $oldName -> $newName" );
247
-				$aliases = array_unique( array_merge( $newContent[ $newName ]['aliases'], [ $oldName ] ) );
248
-				$newContent[ $newName ]['aliases'] = $aliases;
247
+				$aliases = array_unique( array_merge( $newContent[ $newName ][ 'aliases' ], [ $oldName ] ) );
248
+				$newContent[ $newName ][ 'aliases' ] = $aliases;
249 249
 				// Transfer overrides to the new name.
250 250
 				$overrides = array_diff_key( $info, [ 'override' => 1, 'override-perm' => 1 ] );
251 251
 				$newContent[ $newName ] = array_merge( $newContent[ $newName ], $overrides );
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
 	 * @param array[] $extra
260 260
 	 * @return string[] Removed users
261 261
 	 */
262
-	private function handleExtraAndMissing(
262
+	private function handleExtraAndMissing (
263 263
 		array &$newContent,
264 264
 		array $missing,
265 265
 		array $extra
266 266
 	) : array {
267
-		$removed = [];
267
+		$removed = [ ];
268 268
 		foreach ( $newContent as $user => $groups ) {
269 269
 			if ( isset( $missing[ $user ] ) ) {
270 270
 				$newContent[ $user ] = array_merge( $groups, $missing[ $user ] );
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 				if ( array_diff_key( $newGroups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ) ) {
275 275
 					$newContent[ $user ] = $newGroups;
276 276
 				} else {
277
-					$removed[$user] = $newContent[$user];
277
+					$removed[ $user ] = $newContent[ $user ];
278 278
 					unset( $newContent[ $user ] );
279 279
 				}
280 280
 			}
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 * @param array[] $extra
292 292
 	 * @return array[]
293 293
 	 */
294
-	protected function getNewContent( array $missing, array $extra ) : array {
294
+	protected function getNewContent ( array $missing, array $extra ) : array {
295 295
 		$newContent = $this->botList;
296 296
 
297 297
 		$removed = $this->handleExtraAndMissing( $newContent, $missing, $extra );
@@ -311,12 +311,12 @@  discard block
 block discarded – undo
311 311
 	 *
312 312
 	 * @param array[] &$newContent
313 313
 	 */
314
-	protected function removeOverrides( array &$newContent ) : void {
315
-		$removed = [];
314
+	protected function removeOverrides ( array &$newContent ) : void {
315
+		$removed = [ ];
316 316
 		foreach ( $newContent as $user => $groups ) {
317 317
 			if ( PageBotList::isOverrideExpired( $groups ) ) {
318 318
 				unset( $newContent[ $user ][ 'override' ] );
319
-				$removed[] = $user;
319
+				$removed[ ] = $user;
320 320
 			}
321 321
 		}
322 322
 
Please login to merge, or discard this patch.