Passed
Push — master ( 505550...c52a51 )
by Daimona
01:45
created
includes/Exception/LoginException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme\Exception;
4 4
 
Please login to merge, or discard this patch.
includes/Logger.php 1 patch
Spacing   +3 added lines, -3 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
 
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 	/**
9 9
 	 * @inheritDoc
10 10
 	 */
11
-	public function log( $level, $message, array $context = [] ) {
12
-		error_log( "$level - $message" );
11
+	public function log($level, $message, array $context = []) {
12
+		error_log("$level - $message");
13 13
 	}
14 14
 }
Please login to merge, or discard this patch.
includes/Task/UserNotice.php 1 patch
Spacing   +16 added lines, -16 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
 
@@ -9,39 +9,39 @@  discard block
 block discarded – undo
9 9
 	 * @inheritDoc
10 10
 	 */
11 11
 	public function run() : TaskResult {
12
-		$this->getLogger()->info( 'Starting task UserNotice' );
12
+		$this->getLogger()->info('Starting task UserNotice');
13 13
 
14 14
 		$ricNums = [];
15
-		foreach ( $this->getDataProvider()->getCreatedPages() as $page ) {
16
-			$bits = explode( '/', $page );
17
-			$num = intval( array_pop( $bits ) );
18
-			$ricNums[ array_pop( $bits ) ] = $num;
15
+		foreach ($this->getDataProvider()->getCreatedPages() as $page) {
16
+			$bits = explode('/', $page);
17
+			$num = intval(array_pop($bits));
18
+			$ricNums[array_pop($bits)] = $num;
19 19
 		}
20 20
 
21
-		foreach ( $this->getDataProvider()->getUsersToProcess() as $user => $_ ) {
22
-			$this->addMsg( $user, $ricNums[ $user ] );
21
+		foreach ($this->getDataProvider()->getUsersToProcess() as $user => $_) {
22
+			$this->addMsg($user, $ricNums[$user]);
23 23
 		}
24 24
 
25
-		$this->getLogger()->info( 'Task UserNotice completed successfully' );
26
-		return new TaskResult( self::STATUS_OK );
25
+		$this->getLogger()->info('Task UserNotice completed successfully');
26
+		return new TaskResult(self::STATUS_OK);
27 27
 	}
28 28
 
29 29
 	/**
30 30
 	 * @param string $user
31 31
 	 * @param int $ricNum
32 32
 	 */
33
-	protected function addMsg( string $user, int $ricNum ) {
34
-		$this->getLogger()->info( "Leaving msg to $user" );
35
-		$msg = str_replace( '$num', "$ricNum", $this->getConfig()->get( 'user-notice-msg' ) );
33
+	protected function addMsg(string $user, int $ricNum) {
34
+		$this->getLogger()->info("Leaving msg to $user");
35
+		$msg = str_replace('$num', "$ricNum", $this->getConfig()->get('user-notice-msg'));
36 36
 
37 37
 		$params = [
38 38
 			'title' => "User talk:$user",
39 39
 			'section' => 'new',
40 40
 			'text' => $msg,
41
-			'sectiontitle' => $this->getConfig()->get( 'user-notice-title' ),
42
-			'summary' => $this->getConfig()->get( 'user-notice-summary' )
41
+			'sectiontitle' => $this->getConfig()->get('user-notice-title'),
42
+			'summary' => $this->getConfig()->get('user-notice-summary')
43 43
 		];
44 44
 
45
-		$this->getController()->editPage( $params );
45
+		$this->getController()->editPage($params);
46 46
 	}
47 47
 }
Please login to merge, or discard this patch.
includes/Task/UpdatesAround.php 1 patch
Spacing   +41 added lines, -41 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
 
@@ -10,83 +10,83 @@  discard block
 block discarded – undo
10 10
 	 * @inheritDoc
11 11
 	 */
12 12
 	public function run() : TaskResult {
13
-		$this->getLogger()->info( 'Starting task UpdatesAround' );
13
+		$this->getLogger()->info('Starting task UpdatesAround');
14 14
 
15
-		foreach ( $this->getDataProvider()->getCreatedPages() as $page ) {
15
+		foreach ($this->getDataProvider()->getCreatedPages() as $page) {
16 16
 			// Wikipedia:Amministratori/Riconferma annuale
17
-			$this->addToMainPage( $page );
17
+			$this->addToMainPage($page);
18 18
 			// WP:Wikipediano/Votazioni
19
-			$this->addVote( $page );
19
+			$this->addVote($page);
20 20
 			// Template:VotazioniRCnews
21
-			$this->addNews( $page );
21
+			$this->addNews($page);
22 22
 		}
23 23
 
24
-		$this->getLogger()->info( 'Task UpdatesAround completed successfully' );
25
-		return new TaskResult( self::STATUS_OK );
24
+		$this->getLogger()->info('Task UpdatesAround completed successfully');
25
+		return new TaskResult(self::STATUS_OK);
26 26
 	}
27 27
 
28 28
 	/**
29 29
 	 * @param string $page
30 30
 	 */
31
-	protected function addToMainPage( string $page ) {
32
-		$this->getLogger()->info( "Adding $page to main" );
31
+	protected function addToMainPage(string $page) {
32
+		$this->getLogger()->info("Adding $page to main");
33 33
 
34 34
 		$params = [
35
-			'title' => $this->getConfig()->get( 'ric-main-page' ),
35
+			'title' => $this->getConfig()->get('ric-main-page'),
36 36
 			'appendtext' => '{{' . $page . '}}',
37
-			'summary' => $this->getConfig()->get( 'ric-main-page-summary' )
37
+			'summary' => $this->getConfig()->get('ric-main-page-summary')
38 38
 		];
39 39
 
40
-		$this->getController()->editPage( $params );
40
+		$this->getController()->editPage($params);
41 41
 	}
42 42
 
43 43
 	/**
44 44
 	 * @param string $page
45 45
 	 */
46
-	protected function addVote( string $page ) {
47
-		$this->getLogger()->info( "Adding $page to votes" );
48
-		$votePage = $this->getConfig()->get( 'ric-vote-page' );
46
+	protected function addVote(string $page) {
47
+		$this->getLogger()->info("Adding $page to votes");
48
+		$votePage = $this->getConfig()->get('ric-vote-page');
49 49
 
50
-		$content = $this->getController()->getPageContent( $votePage );
50
+		$content = $this->getController()->getPageContent($votePage);
51 51
 		// Remove comments etc.
52
-		$visibleContent = strip_tags( $content );
53
-		$user = explode( '/', $page )[2];
52
+		$visibleContent = strip_tags($content);
53
+		$user = explode('/', $page)[2];
54 54
 		$time = $this->getTimeWithArticle();
55 55
 
56 56
 		$newLine = "*[[Utente:$user|]]. La [[$page|procedura]] termina $time";
57 57
 
58 58
 		$introReg = '!^;È in corso la .*riconferma tacita.* degli .*amministratori.+!m';
59
-		if ( preg_match( $introReg, $visibleContent ) ) {
60
-			$newContent = preg_replace( $introReg, "$0\n$newLine;", $content, 1 );
59
+		if (preg_match($introReg, $visibleContent)) {
60
+			$newContent = preg_replace($introReg, "$0\n$newLine;", $content, 1);
61 61
 		} else {
62 62
 			$matches = [];
63
-			if ( preg_match( $introReg, $content, $matches ) === false ) {
64
-				throw new TaskException( 'Intro not found in vote page' );
63
+			if (preg_match($introReg, $content, $matches) === false) {
64
+				throw new TaskException('Intro not found in vote page');
65 65
 			}
66 66
 			$beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m';
67
-			$newContent = preg_replace( $beforeReg, "$0\n{$matches[0]}\n$newLine.", $content, 1 );
67
+			$newContent = preg_replace($beforeReg, "$0\n{$matches[0]}\n$newLine.", $content, 1);
68 68
 		}
69 69
 
70 70
 		$params = [
71 71
 			'title' => $votePage,
72 72
 			'text' => $newContent,
73
-			'summary' => $this->getConfig()->get( 'ric-vote-page-summary' )
73
+			'summary' => $this->getConfig()->get('ric-vote-page-summary')
74 74
 		];
75 75
 
76
-		$this->getController()->editPage( $params );
76
+		$this->getController()->editPage($params);
77 77
 	}
78 78
 
79 79
 	/**
80 80
 	 * @return string
81 81
 	 */
82 82
 	private function getTimeWithArticle() : string {
83
-		$oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' );
84
-		$endTS = time() + ( 60 * 60 * 24 * 7 );
85
-		$endTime = strftime( '%e %B alle %R', $endTS );
83
+		$oldLoc = setlocale(LC_TIME, 'it_IT', 'Italian_Italy', 'Italian');
84
+		$endTS = time() + (60 * 60 * 24 * 7);
85
+		$endTime = strftime('%e %B alle %R', $endTS);
86 86
 		// Remove the left space if day has a single digit
87
-		$endTime = ltrim( $endTime );
88
-		$artic = in_array( date( 'j', $endTS ), [ 8, 11 ] ) ? "l'" : "il ";
89
-		setlocale( LC_TIME, $oldLoc );
87
+		$endTime = ltrim($endTime);
88
+		$artic = in_array(date('j', $endTS), [8, 11]) ? "l'" : "il ";
89
+		setlocale(LC_TIME, $oldLoc);
90 90
 
91 91
 		return $artic . $endTime;
92 92
 	}
@@ -94,27 +94,27 @@  discard block
 block discarded – undo
94 94
 	/**
95 95
 	 * @param string $page
96 96
 	 */
97
-	protected function addNews( string $page ) {
98
-		$this->getLogger()->info( "Adding $page to news" );
99
-		$newsPage = $this->getConfig()->get( 'ric-news-page' );
97
+	protected function addNews(string $page) {
98
+		$this->getLogger()->info("Adding $page to news");
99
+		$newsPage = $this->getConfig()->get('ric-news-page');
100 100
 
101
-		$content = $this->getController()->getPageContent( $newsPage );
101
+		$content = $this->getController()->getPageContent($newsPage);
102 102
 		$reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!';
103 103
 
104 104
 		$matches = [];
105
-		if ( preg_match( $reg, $content, $matches ) === false ) {
106
-			throw new TaskException( 'Param not found in news page' );
105
+		if (preg_match($reg, $content, $matches) === false) {
106
+			throw new TaskException('Param not found in news page');
107 107
 		}
108 108
 
109 109
 		$newNum = (int)$matches[2] + 1;
110
-		$newContent = preg_replace( $reg, '${1}' . $newNum, $content );
110
+		$newContent = preg_replace($reg, '${1}' . $newNum, $content);
111 111
 
112 112
 		$params = [
113 113
 			'title' => $newsPage,
114 114
 			'text' => $newContent,
115
-			'summary' => $this->getConfig()->get( 'ric-news-page-summary' )
115
+			'summary' => $this->getConfig()->get('ric-news-page-summary')
116 116
 		];
117 117
 
118
-		$this->getController()->editPage( $params );
118
+		$this->getController()->editPage($params);
119 119
 	}
120 120
 }
Please login to merge, or discard this patch.
includes/Task/UpdateList.php 1 patch
Spacing   +66 added lines, -66 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
 
@@ -16,18 +16,18 @@  discard block
 block discarded – undo
16 16
 	 * @inheritDoc
17 17
 	 */
18 18
 	public function run() : TaskResult {
19
-		$this->getLogger()->info( 'Starting task UpdateList' );
19
+		$this->getLogger()->info('Starting task UpdateList');
20 20
 		$this->actualList = $this->getActualAdmins();
21 21
 		$this->botList = $this->getList();
22 22
 
23 23
 		$missing = $this->getMissingGroups();
24 24
 		$extra = $this->getExtraGroups();
25 25
 
26
-		if ( $missing || $extra ) {
27
-			$this->doUpdateList( $this->getNewContent( $missing, $extra ) );
26
+		if ($missing || $extra) {
27
+			$this->doUpdateList($this->getNewContent($missing, $extra));
28 28
 		}
29 29
 
30
-		if ( $this->errors ) {
30
+		if ($this->errors) {
31 31
 			// We're fine with it, but don't run other tasks
32 32
 			$msg = 'Task UpdateList completed with warnings.';
33 33
 			$status = self::STATUS_ERROR;
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
 			$status = self::STATUS_OK;
37 37
 		}
38 38
 
39
-		$this->getLogger()->info( $msg );
40
-		return new TaskResult( $status, $this->errors );
39
+		$this->getLogger()->info($msg);
40
+		return new TaskResult($status, $this->errors);
41 41
 	}
42 42
 
43 43
 	/**
44 44
 	 * @return array
45 45
 	 */
46 46
 	protected function getActualAdmins() : array {
47
-		$this->getLogger()->debug( 'Retrieving admins - API' );
47
+		$this->getLogger()->debug('Retrieving admins - API');
48 48
 		$params = [
49 49
 			'action' => 'query',
50 50
 			'list' => 'allusers',
@@ -53,23 +53,23 @@  discard block
 block discarded – undo
53 53
 			'aulimit' => 'max',
54 54
 		];
55 55
 
56
-		$req = RequestBase::newFromParams( $params );
57
-		return $this->extractAdmins( $req->execute() );
56
+		$req = RequestBase::newFromParams($params);
57
+		return $this->extractAdmins($req->execute());
58 58
 	}
59 59
 
60 60
 	/**
61 61
 	 * @param array $data
62 62
 	 * @return array
63 63
 	 */
64
-	protected function extractAdmins( array $data ) : array {
64
+	protected function extractAdmins(array $data) : array {
65 65
 		$ret = [];
66
-		$blacklist = $this->getConfig()->get( 'exclude-admins' );
67
-		foreach ( $data['query']['allusers'] as $u ) {
68
-			if ( in_array( $u['name'], $blacklist ) ) {
66
+		$blacklist = $this->getConfig()->get('exclude-admins');
67
+		foreach ($data['query']['allusers'] as $u) {
68
+			if (in_array($u['name'], $blacklist)) {
69 69
 				continue;
70 70
 			}
71
-			$interestingGroups = array_intersect( $u['groups'], [ 'sysop', 'bureaucrat', 'checkuser' ] );
72
-			$ret[ $u['name'] ] = $interestingGroups;
71
+			$interestingGroups = array_intersect($u['groups'], ['sysop', 'bureaucrat', 'checkuser']);
72
+			$ret[$u['name']] = $interestingGroups;
73 73
 		}
74 74
 		return $ret;
75 75
 	}
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 	 * @return array
79 79
 	 */
80 80
 	protected function getList() : array {
81
-		$this->getLogger()->debug( 'Retrieving admins - JSON list' );
82
-		$content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) );
81
+		$this->getLogger()->debug('Retrieving admins - JSON list');
82
+		$content = $this->getController()->getPageContent($this->getConfig()->get('list-title'));
83 83
 
84
-		return json_decode( $content, true );
84
+		return json_decode($content, true);
85 85
 	}
86 86
 
87 87
 	/**
@@ -89,20 +89,20 @@  discard block
 block discarded – undo
89 89
 	 */
90 90
 	protected function getMissingGroups() : array {
91 91
 		$missing = [];
92
-		foreach ( $this->actualList as $adm => $groups ) {
93
-			if ( !isset( $this->botList[ $adm ] ) ) {
92
+		foreach ($this->actualList as $adm => $groups) {
93
+			if (!isset($this->botList[$adm])) {
94 94
 				$groupsList = $groups;
95
-			} elseif ( count( $groups ) > count( $this->botList[$adm] ) ) {
95
+			} elseif (count($groups) > count($this->botList[$adm])) {
96 96
 				// Only some groups are missing
97
-				$groupsList = array_diff_key( $groups, $this->botList[$adm] );
97
+				$groupsList = array_diff_key($groups, $this->botList[$adm]);
98 98
 			} else {
99 99
 				continue;
100 100
 			}
101 101
 
102
-			foreach ( $groupsList as $group ) {
102
+			foreach ($groupsList as $group) {
103 103
 				try {
104
-					$missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group );
105
-				} catch ( TaskException $e ) {
104
+					$missing[$adm][$group] = $this->getFlagDate($adm, $group);
105
+				} catch (TaskException $e) {
106 106
 					$this->errors[] = $e->getMessage();
107 107
 				}
108 108
 			}
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
 	 * @return string
117 117
 	 * @throws TaskException
118 118
 	 */
119
-	protected function getFlagDate( string $admin, string $group ) : string {
120
-		$this->getLogger()->info( "Retrieving $group flag date for $admin" );
119
+	protected function getFlagDate(string $admin, string $group) : string {
120
+		$this->getLogger()->info("Retrieving $group flag date for $admin");
121 121
 
122
-		if ( $group === 'checkuser' ) {
122
+		if ($group === 'checkuser') {
123 123
 			// Little hack
124
-			$oldUrl = $this->getConfig()->get( 'url' );
125
-			$this->getConfig()->set( 'url', 'https://meta.wikimedia.org/w/api.php' );
124
+			$oldUrl = $this->getConfig()->get('url');
125
+			$this->getConfig()->set('url', 'https://meta.wikimedia.org/w/api.php');
126 126
 			$admin .= '@itwiki';
127 127
 		}
128 128
 
@@ -135,19 +135,19 @@  discard block
 block discarded – undo
135 135
 			'lelimit' => 'max'
136 136
 		];
137 137
 
138
-		$req = RequestBase::newFromParams( $params );
138
+		$req = RequestBase::newFromParams($params);
139 139
 		$data = $req->execute();
140
-		$ts = $this->extractTimestamp( $data, $group );
140
+		$ts = $this->extractTimestamp($data, $group);
141 141
 
142
-		if ( isset( $oldUrl ) ) {
143
-			$this->getConfig()->set( 'url', $oldUrl );
142
+		if (isset($oldUrl)) {
143
+			$this->getConfig()->set('url', $oldUrl);
144 144
 		}
145 145
 
146
-		if ( $ts === null ) {
147
-			throw new TaskException( "$group flag date unavailable for $admin" );
146
+		if ($ts === null) {
147
+			throw new TaskException("$group flag date unavailable for $admin");
148 148
 		}
149 149
 
150
-		return date( "d/m/Y", strtotime( $ts ) );
150
+		return date("d/m/Y", strtotime($ts));
151 151
 	}
152 152
 
153 153
 	/**
@@ -155,15 +155,15 @@  discard block
 block discarded – undo
155 155
 	 * @param string $group
156 156
 	 * @return string|null
157 157
 	 */
158
-	private function extractTimestamp( array $data, string $group ) : ?string {
158
+	private function extractTimestamp(array $data, string $group) : ?string {
159 159
 		$ts = null;
160
-		foreach ( $data['query']['logevents'] as $entry ) {
161
-			if ( !isset( $entry['params'] ) ) {
160
+		foreach ($data['query']['logevents'] as $entry) {
161
+			if (!isset($entry['params'])) {
162 162
 				// Old entries
163 163
 				continue;
164 164
 			}
165
-			if ( in_array( $group, $entry['params']['newgroups'] ) &&
166
-				!in_array( $group, $entry['params']['oldgroups'] )
165
+			if (in_array($group, $entry['params']['newgroups']) &&
166
+				!in_array($group, $entry['params']['oldgroups'])
167 167
 			) {
168 168
 				$ts = $entry['timestamp'];
169 169
 				break;
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	protected function getExtraGroups() : array {
178 178
 		$extra = [];
179
-		foreach ( $this->botList as $name => $groups ) {
180
-			if ( !isset( $this->actualList[ $name ] ) ) {
181
-				$extra[ $name ] = $groups;
182
-			} elseif ( count( $groups ) > count( $this->actualList[ $name ] ) ) {
183
-				$extra[ $name ] = array_diff_key( $groups, $this->actualList[ $name ] );
179
+		foreach ($this->botList as $name => $groups) {
180
+			if (!isset($this->actualList[$name])) {
181
+				$extra[$name] = $groups;
182
+			} elseif (count($groups) > count($this->actualList[$name])) {
183
+				$extra[$name] = array_diff_key($groups, $this->actualList[$name]);
184 184
 			}
185 185
 		}
186 186
 		return $extra;
@@ -189,25 +189,25 @@  discard block
 block discarded – undo
189 189
 	/**
190 190
 	 * @param array $newContent
191 191
 	 */
192
-	protected function doUpdateList( array $newContent ) {
193
-		ksort( $newContent );
192
+	protected function doUpdateList(array $newContent) {
193
+		ksort($newContent);
194 194
 
195
-		if ( $newContent !== $this->botList ) {
196
-			$this->getLogger()->info( 'Updating admin list' );
195
+		if ($newContent !== $this->botList) {
196
+			$this->getLogger()->info('Updating admin list');
197 197
 		} else {
198
-			$this->getLogger()->info( 'Admin list already up-to-date' );
198
+			$this->getLogger()->info('Admin list already up-to-date');
199 199
 			return;
200 200
 		}
201 201
 
202
-		$stringified = json_encode( $newContent );
202
+		$stringified = json_encode($newContent);
203 203
 
204 204
 		$params = [
205
-			'title' => $this->getConfig()->get( 'list-title' ),
205
+			'title' => $this->getConfig()->get('list-title'),
206 206
 			'text' => $stringified,
207
-			'summary' => $this->getConfig()->get( 'list-update-summary' )
207
+			'summary' => $this->getConfig()->get('list-update-summary')
208 208
 		];
209 209
 
210
-		$this->getController()->editPage( $params );
210
+		$this->getController()->editPage($params);
211 211
 	}
212 212
 
213 213
 	/**
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
 	 * @param array[] $extra
216 216
 	 * @return array[]
217 217
 	 */
218
-	protected function getNewContent( array $missing, array $extra ) : array {
218
+	protected function getNewContent(array $missing, array $extra) : array {
219 219
 		$newContent = $this->botList;
220
-		foreach ( $newContent as $user => $groups ) {
221
-			if ( isset( $missing[ $user ] ) ) {
222
-				$newContent[ $user ] = array_merge( $groups, $missing[ $user ] );
223
-				unset( $missing[ $user ] );
224
-			} elseif ( isset( $extra[ $user ] ) ) {
225
-				$newContent[ $user ] = array_diff_key( $groups, $extra[ $user ] );
220
+		foreach ($newContent as $user => $groups) {
221
+			if (isset($missing[$user])) {
222
+				$newContent[$user] = array_merge($groups, $missing[$user]);
223
+				unset($missing[$user]);
224
+			} elseif (isset($extra[$user])) {
225
+				$newContent[$user] = array_diff_key($groups, $extra[$user]);
226 226
 			}
227 227
 		}
228 228
 		// Add users which don't have an entry at all
229
-		$newContent = array_merge( $newContent, $missing );
229
+		$newContent = array_merge($newContent, $missing);
230 230
 		// And remove empty users
231
-		return array_filter( $newContent );
231
+		return array_filter($newContent);
232 232
 	}
233 233
 }
Please login to merge, or discard this patch.
includes/Task/Task.php 1 patch
Spacing   +8 added lines, -8 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
 
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
 	/**
19 19
 	 * @param TaskDataProvider $dataProvider
20 20
 	 */
21
-	public function __construct( TaskDataProvider $dataProvider ) {
22
-		set_exception_handler( [ $this, 'handleException' ] );
23
-		set_error_handler( [ $this, 'handleError' ] );
21
+	public function __construct(TaskDataProvider $dataProvider) {
22
+		set_exception_handler([$this, 'handleException']);
23
+		set_error_handler([$this, 'handleError']);
24 24
 		parent::__construct();
25 25
 		$this->dataProvider = $dataProvider;
26 26
 	}
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	 * @param \Throwable $ex
44 44
 	 * @protected
45 45
 	 */
46
-	public function handleException( \Throwable $ex ) {
46
+	public function handleException(\Throwable $ex) {
47 47
 		$this->getLogger()->error(
48
-			get_class( $ex ) . ': ' .
48
+			get_class($ex) . ': ' .
49 49
 			$ex->getMessage() . "\nTrace:\n" .
50 50
 			$ex->getTraceAsString()
51 51
 		);
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 	 * @param int $errline
61 61
 	 * @protected
62 62
 	 */
63
-	public function handleError( $errno, $errstr, $errfile, $errline ) {
64
-		throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline );
63
+	public function handleError($errno, $errstr, $errfile, $errline) {
64
+		throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
65 65
 	}
66 66
 
67 67
 	/**
Please login to merge, or discard this patch.
includes/Task/CreatePage.php 1 patch
Spacing   +47 added lines, -47 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
 
@@ -11,42 +11,42 @@  discard block
 block discarded – undo
11 11
 	 * @inheritDoc
12 12
 	 */
13 13
 	public function run() : TaskResult {
14
-		$this->getLogger()->info( 'Starting task CreatePage' );
14
+		$this->getLogger()->info('Starting task CreatePage');
15 15
 		$users = $this->getDataProvider()->getUsersToProcess();
16 16
 
17
-		foreach ( $users as $user => $groups ) {
18
-			$this->processUser( $user, $groups );
17
+		foreach ($users as $user => $groups) {
18
+			$this->processUser($user, $groups);
19 19
 		}
20 20
 
21
-		$this->getLogger()->info( 'Task CreatePage completed successfully' );
22
-		return new TaskResult( self::STATUS_OK );
21
+		$this->getLogger()->info('Task CreatePage completed successfully');
22
+		return new TaskResult(self::STATUS_OK);
23 23
 	}
24 24
 
25 25
 	/**
26 26
 	 * @param string $user
27 27
 	 * @param array $groups
28 28
 	 */
29
-	protected function processUser( string $user, array $groups ) {
29
+	protected function processUser(string $user, array $groups) {
30 30
 		try {
31
-			$num = $this->getLastPageNum( $user ) + 1;
32
-		} catch ( TaskException $e ) {
31
+			$num = $this->getLastPageNum($user) + 1;
32
+		} catch (TaskException $e) {
33 33
 			// The page was already created.
34
-			$this->getDataProvider()->removeUser( $user );
35
-			$this->getLogger()->warning( $e->getMessage() . "\nRemoving $user." );
34
+			$this->getDataProvider()->removeUser($user);
35
+			$this->getLogger()->warning($e->getMessage() . "\nRemoving $user.");
36 36
 			return;
37 37
 		}
38 38
 
39
-		$baseTitle = $this->getConfig()->get( 'ric-main-page' ) . "/$user";
39
+		$baseTitle = $this->getConfig()->get('ric-main-page') . "/$user";
40 40
 		$pageTitle = "$baseTitle/$num";
41
-		$this->doCreatePage( $pageTitle, $user, $groups );
41
+		$this->doCreatePage($pageTitle, $user, $groups);
42 42
 
43
-		$newText = str_replace( '$title', $pageTitle, $this->getConfig()->get( 'ric-base-page-text' ) );
44
-		if ( $num === 1 ) {
45
-			$this->createBasePage( $baseTitle, $newText );
43
+		$newText = str_replace('$title', $pageTitle, $this->getConfig()->get('ric-base-page-text'));
44
+		if ($num === 1) {
45
+			$this->createBasePage($baseTitle, $newText);
46 46
 		} else {
47
-			$this->updateBasePage( $baseTitle, $newText );
47
+			$this->updateBasePage($baseTitle, $newText);
48 48
 		}
49
-		$this->getDataProvider()->addCreatedPages( $pageTitle );
49
+		$this->getDataProvider()->addCreatedPages($pageTitle);
50 50
 	}
51 51
 
52 52
 	/**
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 	 * @return int
55 55
 	 * @throws TaskException
56 56
 	 */
57
-	protected function getLastPageNum( string $user ) : int {
58
-		$this->getLogger()->debug( "Retrieving previous pages for $user" );
59
-		$unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[1];
57
+	protected function getLastPageNum(string $user) : int {
58
+		$this->getLogger()->debug("Retrieving previous pages for $user");
59
+		$unprefixedTitle = explode(':', $this->getConfig()->get('ric-main-page'), 2)[1];
60 60
 		$params = [
61 61
 			'action' => 'query',
62 62
 			'list' => 'allpages',
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
 			'aplimit' => 'max'
66 66
 		];
67 67
 
68
-		$res = ( RequestBase::newFromParams( $params ) )->execute();
68
+		$res = (RequestBase::newFromParams($params))->execute();
69 69
 
70 70
 		$last = 0;
71
-		foreach ( $res['query']['allpages'] as $page ) {
72
-			if ( $this->pageWasCreatedToday( $page['title'] ) ) {
73
-				throw new TaskException( 'Page ' . $page['title'] . ' was already created.' );
71
+		foreach ($res['query']['allpages'] as $page) {
72
+			if ($this->pageWasCreatedToday($page['title'])) {
73
+				throw new TaskException('Page ' . $page['title'] . ' was already created.');
74 74
 			}
75
-			$bits = explode( '/', $page['title'] );
76
-			$cur = intval( end( $bits ) );
77
-			if ( is_numeric( $cur ) && $cur > $last ) {
75
+			$bits = explode('/', $page['title']);
76
+			$cur = intval(end($bits));
77
+			if (is_numeric($cur) && $cur > $last) {
78 78
 				$last = $cur;
79 79
 			}
80 80
 		}
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @param string $title
86 86
 	 * @return bool
87 87
 	 */
88
-	private function pageWasCreatedToday( string $title ) : bool {
88
+	private function pageWasCreatedToday(string $title) : bool {
89 89
 		$params = [
90 90
 			'action' => 'query',
91 91
 			'prop' => 'revisions',
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 			'rvdir' => 'newer'
97 97
 		];
98 98
 
99
-		$res = ( RequestBase::newFromParams( $params ) )->execute();
99
+		$res = (RequestBase::newFromParams($params))->execute();
100 100
 		$data = $res['query']['pages'];
101
-		$time = strtotime( reset( $data )['revisions'][0]['timestamp'] );
102
-		return date( 'z/Y' ) === date( 'z/Y', $time );
101
+		$time = strtotime(reset($data)['revisions'][0]['timestamp']);
102
+		return date('z/Y') === date('z/Y', $time);
103 103
 	}
104 104
 
105 105
 	/**
@@ -107,56 +107,56 @@  discard block
 block discarded – undo
107 107
 	 * @param string $user
108 108
 	 * @param array $groups
109 109
 	 */
110
-	protected function doCreatePage( string $title, string $user, array $groups ) {
111
-		$this->getLogger()->info( "Creating page $title" );
112
-		$text = $this->getConfig()->get( 'ric-page-text' );
110
+	protected function doCreatePage(string $title, string $user, array $groups) {
111
+		$this->getLogger()->info("Creating page $title");
112
+		$text = $this->getConfig()->get('ric-page-text');
113 113
 		$textParams = [
114 114
 			'$user' => $user,
115 115
 			'$date' => $groups['sysop'],
116
-			'$quorum' => '',##################################################################Handle on-wiki
116
+			'$quorum' => '', ##################################################################Handle on-wiki
117 117
 			'$burocrate' => $groups['bureaucrat'] ?? '',
118 118
 			'$checkuser' => $groups['checkuser'] ?? ''
119 119
 		];
120
-		$text = strtr( $text, $textParams );
120
+		$text = strtr($text, $textParams);
121 121
 
122 122
 		$params = [
123 123
 			'title' => $title,
124 124
 			'text' => $text,
125
-			'summary' => $this->getConfig()->get( 'ric-page-summary' )
125
+			'summary' => $this->getConfig()->get('ric-page-summary')
126 126
 		];
127 127
 
128
-		$this->getController()->editPage( $params );
128
+		$this->getController()->editPage($params);
129 129
 	}
130 130
 
131 131
 	/**
132 132
 	 * @param string $title
133 133
 	 * @param string $newText
134 134
 	 */
135
-	protected function createBasePage( string $title, string $newText ) {
136
-		$this->getLogger()->info( "Creating base page $title" );
135
+	protected function createBasePage(string $title, string $newText) {
136
+		$this->getLogger()->info("Creating base page $title");
137 137
 
138 138
 		$params = [
139 139
 			'title' => $title,
140 140
 			'text' => $newText,
141
-			'summary' => $this->getConfig()->get( 'ric-base-page-summary' )
141
+			'summary' => $this->getConfig()->get('ric-base-page-summary')
142 142
 		];
143 143
 
144
-		$this->getController()->editPage( $params );
144
+		$this->getController()->editPage($params);
145 145
 	}
146 146
 
147 147
 	/**
148 148
 	 * @param string $title
149 149
 	 * @param string $newText
150 150
 	 */
151
-	protected function updateBasePage( string $title, string $newText ) {
152
-		$this->getLogger()->info( "Updating base page $title" );
151
+	protected function updateBasePage(string $title, string $newText) {
152
+		$this->getLogger()->info("Updating base page $title");
153 153
 
154 154
 		$params = [
155 155
 			'title' => $title,
156 156
 			'appendtext' => $newText,
157
-			'summary' => $this->getConfig()->get( 'ric-base-page-summary-update' )
157
+			'summary' => $this->getConfig()->get('ric-base-page-summary-update')
158 158
 		];
159 159
 
160
-		$this->getController()->editPage( $params );
160
+		$this->getController()->editPage($params);
161 161
 	}
162 162
 }
Please login to merge, or discard this patch.
includes/Config.php 1 patch
Spacing   +21 added lines, -21 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
 
@@ -22,27 +22,27 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param array $defaults
24 24
 	 */
25
-	public static function init( array $defaults ) {
26
-		if ( self::$instance ) {
27
-			throw new ConfigException( 'Config was already initialized' );
25
+	public static function init(array $defaults) {
26
+		if (self::$instance) {
27
+			throw new ConfigException('Config was already initialized');
28 28
 		}
29 29
 
30 30
 		$inst = new self;
31
-		$inst->set( 'url', $defaults['url'] );
32
-		$inst->set( 'list-title', $defaults['list-title'] );
33
-		$inst->set( 'username', $defaults['username'] );
34
-		$inst->set( 'password', $defaults['password'] );
31
+		$inst->set('url', $defaults['url']);
32
+		$inst->set('list-title', $defaults['list-title']);
33
+		$inst->set('username', $defaults['username']);
34
+		$inst->set('password', $defaults['password']);
35 35
 		self::$instance = $inst;
36 36
 
37 37
 		// On-wiki values
38 38
 		try {
39
-			$conf = ( new WikiController )->getPageContent( $defaults[ 'config-title' ] );
40
-		} catch ( MissingPageException $e ) {
41
-			throw new ConfigException( 'Please create a config page.' );
39
+			$conf = (new WikiController)->getPageContent($defaults['config-title']);
40
+		} catch (MissingPageException $e) {
41
+			throw new ConfigException('Please create a config page.');
42 42
 		}
43 43
 
44
-		foreach ( json_decode( $conf, true ) as $key => $val ) {
45
-			self::$instance->set( $key, $val );
44
+		foreach (json_decode($conf, true) as $key => $val) {
45
+			self::$instance->set($key, $val);
46 46
 		}
47 47
 	}
48 48
 
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 * @param string $key
51 51
 	 * @param mixed $value
52 52
 	 */
53
-	public function set( string $key, $value ) {
54
-		$this->opts[ $key ] = $value;
53
+	public function set(string $key, $value) {
54
+		$this->opts[$key] = $value;
55 55
 	}
56 56
 
57 57
 	/**
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 	 * @return self
61 61
 	 */
62 62
 	public static function getInstance() : self {
63
-		if ( !self::$instance ) {
64
-			throw new ConfigException( 'Config not yet initialized' );
63
+		if (!self::$instance) {
64
+			throw new ConfigException('Config not yet initialized');
65 65
 		}
66 66
 		return self::$instance;
67 67
 	}
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 	 * @param string $opt
71 71
 	 * @return mixed
72 72
 	 */
73
-	public function get( string $opt ) {
74
-		if ( !isset( $this->opts[ $opt ] ) ) {
75
-			throw new ConfigException( "Config option '$opt' not set." );
73
+	public function get(string $opt) {
74
+		if (!isset($this->opts[$opt])) {
75
+			throw new ConfigException("Config option '$opt' not set.");
76 76
 		}
77
-		return $this->opts[ $opt ];
77
+		return $this->opts[$opt];
78 78
 	}
79 79
 }
Please login to merge, or discard this patch.
includes/TaskResult.php 1 patch
Spacing   +7 added lines, -7 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
 
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 * @param int $status One of the Task::STATUS_* constants
18 18
 	 * @param string[] $errors
19 19
 	 */
20
-	public function __construct( int $status, array $errors = [] ) {
20
+	public function __construct(int $status, array $errors = []) {
21 21
 		$this->status = $status;
22 22
 		$this->errors = $errors;
23 23
 	}
@@ -39,25 +39,25 @@  discard block
 block discarded – undo
39 39
 	/**
40 40
 	 * @param TaskResult $that
41 41
 	 */
42
-	public function merge( TaskResult $that ) {
42
+	public function merge(TaskResult $that) {
43 43
 		$this->status |= $that->status;
44
-		$this->errors = array_merge( $this->errors, $that->errors );
44
+		$this->errors = array_merge($this->errors, $that->errors);
45 45
 	}
46 46
 
47 47
 	/**
48 48
 	 * @return string
49 49
 	 */
50 50
 	public function __toString() {
51
-		if ( $this->isOK() ) {
51
+		if ($this->isOK()) {
52 52
 			$stat = 'OK';
53 53
 			$errs = "\tNo errors.";
54 54
 		} else {
55 55
 			$stat = 'ERROR';
56 56
 			$formattedErrs = [];
57
-			foreach ( $this->errors as $err ) {
57
+			foreach ($this->errors as $err) {
58 58
 				$formattedErrs[] = "\t - $err";
59 59
 			}
60
-			$errs = implode( "\n", $formattedErrs );
60
+			$errs = implode("\n", $formattedErrs);
61 61
 		}
62 62
 		return "=== RESULT ===\n - Status: $stat\n - Errors:\n$errs\n";
63 63
 	}
Please login to merge, or discard this patch.