Passed
Push — master ( 86a446...eb1346 )
by Daimona
03:08
created
includes/Wiki/Controller.php 1 patch
Spacing   +13 added lines, -13 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\Wiki;
4 4
 
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * @param string $domain The URL of the wiki, if different from default
29 29
 	 */
30
-	public function __construct( string $domain = DEFAULT_URL ) {
30
+	public function __construct ( string $domain = DEFAULT_URL ) {
31 31
 		$this->logger = new Logger;
32 32
 		$this->domain = $domain;
33 33
 	}
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 * @throws MissingPageException
42 42
 	 * @throws MissingSectionException
43 43
 	 */
44
-	public function getPageContent( string $title, int $section = null ) : string {
44
+	public function getPageContent ( string $title, int $section = null ) : string {
45 45
 		$msg = "Retrieving content of $title" . ( $section !== null ? ", section $section" : '' );
46 46
 		$this->logger->debug( $msg );
47 47
 		$params = [
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 		];
54 54
 
55 55
 		if ( $section !== null ) {
56
-			$params['rvsection'] = $section;
56
+			$params[ 'rvsection' ] = $section;
57 57
 		}
58 58
 
59 59
 		$req = RequestBase::newFromParams( $params )->setUrl( $this->domain );
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 			throw new MissingPageException( $title );
64 64
 		}
65 65
 
66
-		$mainSlot = $page->revisions[0]->slots->main;
66
+		$mainSlot = $page->revisions[ 0 ]->slots->main;
67 67
 
68 68
 		if ( $section !== null && isset( $mainSlot->nosuchsection ) ) {
69 69
 			throw new MissingSectionException( $title, $section );
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * @param array $params
78 78
 	 * @throws EditException
79 79
 	 */
80
-	public function editPage( array $params ) {
80
+	public function editPage ( array $params ) {
81 81
 		$this->login();
82 82
 
83 83
 		$params = [
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		] + $params;
87 87
 
88 88
 		if ( Config::getInstance()->get( 'bot-edits' ) ) {
89
-			$params['bot'] = 1;
89
+			$params[ 'bot' ] = 1;
90 90
 		}
91 91
 
92 92
 		$res = RequestBase::newFromParams( $params )
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 * Login wrapper. Checks if we're already logged in and clears tokens cache
108 108
 	 * @throws LoginException
109 109
 	 */
110
-	public function login() {
110
+	public function login () {
111 111
 		if ( self::$loggedIn ) {
112 112
 			return;
113 113
 		}
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 		self::$loggedIn = true;
136 136
 		// Clear tokens cache
137
-		$this->tokens = [];
137
+		$this->tokens = [ ];
138 138
 		$this->logger->info( 'Login succeeded' );
139 139
 	}
140 140
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @param string $type
145 145
 	 * @return string
146 146
 	 */
147
-	public function getToken( string $type ) : string {
147
+	public function getToken ( string $type ) : string {
148 148
 		if ( !isset( $this->tokens[ $type ] ) ) {
149 149
 			$params = [
150 150
 				'action' => 'query',
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 * @param string $title
168 168
 	 * @return int
169 169
 	 */
170
-	public function getPageCreationTS( string $title ) : int {
170
+	public function getPageCreationTS ( string $title ) : int {
171 171
 		$params = [
172 172
 			'action' => 'query',
173 173
 			'prop' => 'revisions',
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 
181 181
 		$res = RequestBase::newFromParams( $params )->setUrl( $this->domain )->execute();
182 182
 		$data = $res->query->pages;
183
-		return strtotime( reset( $data )->revisions[0]->timestamp );
183
+		return strtotime( reset( $data )->revisions[ 0 ]->timestamp );
184 184
 	}
185 185
 
186 186
 	/**
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @param string $title
190 190
 	 * @param string $reason
191 191
 	 */
192
-	public function protectPage( string $title, string $reason ) {
192
+	public function protectPage ( string $title, string $reason ) {
193 193
 		$this->logger->info( "Protecting page $title" );
194 194
 		$this->login();
195 195
 
Please login to merge, or discard this patch.
includes/Logger.php 1 patch
Spacing   +4 added lines, -4 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
 
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	/**
16 16
 	 * @param string $minlevel
17 17
 	 */
18
-	public function __construct( $minlevel = LogLevel::INFO ) {
18
+	public function __construct ( $minlevel = LogLevel::INFO ) {
19 19
 		$this->minLevel = $this->levelToInt( $minlevel );
20 20
 	}
21 21
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 * @param string $level
26 26
 	 * @return int
27 27
 	 */
28
-	private function levelToInt( string $level ) : int {
28
+	private function levelToInt ( string $level ) : int {
29 29
 		// Order matters
30 30
 		$mapping = [
31 31
 			LogLevel::DEBUG,
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	/**
44 44
 	 * @inheritDoc
45 45
 	 */
46
-	public function log( $level, $message, array $context = [] ) {
46
+	public function log ( $level, $message, array $context = [ ] ) {
47 47
 		if ( $this->levelToInt( $level ) >= $this->minLevel ) {
48 48
 			printf( "%s [%s] - %s\n", date( 'd M H:i:s' ), $level, $message );
49 49
 		}
Please login to merge, or discard this patch.
includes/Bot.php 1 patch
Spacing   +8 added lines, -9 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
 
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 	const VERSION = '1.0';
13 13
 
14
-	public function __construct() {
14
+	public function __construct () {
15 15
 		$this->logger = new Logger;
16 16
 	}
17 17
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @param string $mode
22 22
 	 * @param string|null $name
23 23
 	 */
24
-	private function run( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) {
24
+	private function run ( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) {
25 25
 		$activity = $mode === TaskManager::MODE_COMPLETE ? TaskManager::MODE_COMPLETE : "$mode $name";
26 26
 		$this->logger->info( "Running $activity" );
27 27
 		$manager = new TaskManager;
@@ -30,18 +30,17 @@  discard block
 block discarded – undo
30 30
 		$base = "Execution of $activity";
31 31
 		if ( $res->isOK() ) {
32 32
 			$msg = $res->getStatus() === TaskResult::STATUS_NOTHING ?
33
-				': nothing to do' :
34
-				' completed successfully';
33
+				': nothing to do' : ' completed successfully';
35 34
 			$this->logger->info( $base . $msg . ".\n$line\n\n" );
36 35
 		} else {
37
-			$this->logger->error(  "$base failed.\n$res\n$line\n\n" );
36
+			$this->logger->error( "$base failed.\n$res\n$line\n\n" );
38 37
 		}
39 38
 	}
40 39
 
41 40
 	/**
42 41
 	 * Entry point for the whole process
43 42
 	 */
44
-	public function runAll() {
43
+	public function runAll () {
45 44
 		$this->run();
46 45
 	}
47 46
 
@@ -50,7 +49,7 @@  discard block
 block discarded – undo
50 49
 	 *
51 50
 	 * @param string $task
52 51
 	 */
53
-	public function runTask( string $task ) {
52
+	public function runTask ( string $task ) {
54 53
 		$this->run( TaskManager::MODE_TASK, $task );
55 54
 	}
56 55
 
@@ -59,7 +58,7 @@  discard block
 block discarded – undo
59 58
 	 *
60 59
 	 * @param string $subtask
61 60
 	 */
62
-	public function runSubtask( string $subtask ) {
61
+	public function runSubtask ( string $subtask ) {
63 62
 		$this->run( TaskManager::MODE_SUBTASK, $subtask );
64 63
 	}
65 64
 }
Please login to merge, or discard this patch.
includes/Task/Subtask/ClosePages.php 1 patch
Spacing   +5 added lines, -6 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\Subtask;
4 4
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	/**
15 15
 	 * @inheritDoc
16 16
 	 */
17
-	public function runInternal() : int {
17
+	public function runInternal () : int {
18 18
 		$pages = $this->getDataProvider()->getPagesToClose();
19 19
 
20 20
 		if ( !$pages ) {
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	/**
37 37
 	 * @param PageRiconferma $page
38 38
 	 */
39
-	protected function addVoteCloseText( PageRiconferma $page ) {
39
+	protected function addVoteCloseText ( PageRiconferma $page ) {
40 40
 		$content = $page->getContent();
41 41
 		$beforeReg = '!è necessario ottenere una maggioranza .+ votanti\.!';
42 42
 		$newContent = preg_replace( $beforeReg, '$0' . "\n" . $page->getOutcomeText(), $content );
@@ -51,15 +51,14 @@  discard block
 block discarded – undo
51 51
 	 * @param PageRiconferma $page
52 52
 	 * @see CreatePages::updateBasePage()
53 53
 	 */
54
-	protected function updateBasePage( PageRiconferma $page ) {
54
+	protected function updateBasePage ( PageRiconferma $page ) {
55 55
 		$this->getLogger()->info( "Updating base page for $page" );
56 56
 
57 57
 		$basePage = new Page( $page->getBaseTitle() );
58 58
 		$current = $basePage->getContent();
59 59
 
60 60
 		$outcomeText = $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ?
61
-			'non riconfermato' :
62
-			'riconfermato';
61
+			'non riconfermato' : 'riconfermato';
63 62
 		$text = $page->isVote() ? "votazione: $outcomeText" : 'riconferma tacita';
64 63
 
65 64
 		$newContent = str_replace( 'riconferma in corso', $text, $current );
Please login to merge, or discard this patch.
includes/Task/Subtask/FailedUpdates.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\Subtask;
4 4
 
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 	/**
17 17
 	 * @inheritDoc
18 18
 	 */
19
-	public function runInternal() : int {
19
+	public function runInternal () : int {
20 20
 		$failed = $this->getFailures();
21 21
 		if ( !$failed ) {
22 22
 			return TaskResult::STATUS_NOTHING;
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return PageRiconferma[]
40 40
 	 */
41
-	private function getFailures() : array {
42
-		$ret = [];
41
+	private function getFailures () : array {
42
+		$ret = [ ];
43 43
 		$allPages = $this->getDataProvider()->getPagesToClose();
44 44
 		foreach ( $allPages as $page ) {
45 45
 			if ( $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ) {
46
-				$ret[] = $page;
46
+				$ret[ ] = $page;
47 47
 			}
48 48
 		}
49 49
 		return $ret;
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	/**
53 53
 	 * @param User[] $users
54 54
 	 */
55
-	protected function updateBurList( array $users ) {
55
+	protected function updateBurList ( array $users ) {
56 56
 		$this->getLogger()->info( 'Updating bur list. Removing: ' . implode( ', ', $users ) );
57 57
 		$remList = Element::regexFromArray( $users );
58 58
 		$burList = new Page( $this->getOpt( 'bur-list-title' ) );
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @param PageRiconferma[] $pages
77 77
 	 */
78
-	protected function requestRemoval( array $pages ) {
78
+	protected function requestRemoval ( array $pages ) {
79 79
 		$this->getLogger()->info( 'Requesting flag removal for: ' . implode( ', ', $pages ) );
80 80
 
81 81
 		$flagRemPage = new Page(
@@ -111,15 +111,15 @@  discard block
 block discarded – undo
111 111
 	 *
112 112
 	 * @param PageRiconferma[] $pages
113 113
 	 */
114
-	protected function updateAnnunci( array $pages ) {
114
+	protected function updateAnnunci ( array $pages ) {
115 115
 		$this->getLogger()->info( 'Updating annunci' );
116 116
 		$section = 1;
117 117
 
118
-		$names = [];
118
+		$names = [ ];
119 119
 		$text = '';
120 120
 		foreach ( $pages as $page ) {
121 121
 			$user = $page->getUser()->getName();
122
-			$names[] = $user;
122
+			$names[ ] = $user;
123 123
 			$text .= $this->msg( 'annunci-text' )->params( [ '$user' => $user ] )->text();
124 124
 		}
125 125
 
@@ -151,16 +151,16 @@  discard block
 block discarded – undo
151 151
 	 *
152 152
 	 * @param PageRiconferma[] $pages
153 153
 	 */
154
-	protected function updateUltimeNotizie( array $pages ) {
154
+	protected function updateUltimeNotizie ( array $pages ) {
155 155
 		$this->getLogger()->info( 'Updating ultime notizie' );
156 156
 		$notiziePage = new Page( $this->getOpt( 'ultimenotizie-page-title' ) );
157 157
 
158
-		$names = [];
158
+		$names = [ ];
159 159
 		$text = '';
160 160
 		$msg = $this->msg( 'ultimenotizie-text' );
161 161
 		foreach ( $pages as $page ) {
162 162
 			$user = $page->getUser()->getName();
163
-			$names[] = $user;
163
+			$names[ ] = $user;
164 164
 			$text .= $msg->params( [ '$user' => $user, '$title' => $page->getTitle() ] )->text();
165 165
 		}
166 166
 
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
 	 * @param PageRiconferma[] $pages
190 190
 	 * @return User[]
191 191
 	 */
192
-	private function getFailedBureaucrats( array $pages ) : array {
193
-		$ret = [];
192
+	private function getFailedBureaucrats ( array $pages ) : array {
193
+		$ret = [ ];
194 194
 		foreach ( $pages as $page ) {
195 195
 			$user = $page->getUser();
196 196
 			if ( $user->inGroup( 'bureaucrat' ) ) {
197
-				$ret[] = $user;
197
+				$ret[ ] = $user;
198 198
 			}
199 199
 		}
200 200
 		return $ret;
Please login to merge, or discard this patch.
includes/Task/UpdateList.php 1 patch
Spacing   +20 added lines, -20 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
 		$this->botList = PageBotList::get()->getAdminsList();
33 33
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	/**
54 54
 	 * @return array
55 55
 	 */
56
-	protected function getActualAdmins() : array {
56
+	protected function getActualAdmins () : array {
57 57
 		$params = [
58 58
 			'action' => 'query',
59 59
 			'list' => 'allusers',
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 	 * @param \stdClass $data
71 71
 	 * @return array
72 72
 	 */
73
-	protected function extractAdmins( \stdClass $data ) : array {
74
-		$ret = [];
73
+	protected function extractAdmins ( \stdClass $data ) : array {
74
+		$ret = [ ];
75 75
 		$blacklist = $this->getOpt( 'exclude-admins' );
76 76
 		foreach ( $data->query->allusers as $u ) {
77 77
 			if ( in_array( $u->name, $blacklist ) ) {
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @return array[]
90 90
 	 */
91
-	protected function getMissingGroups() : array {
92
-		$missing = [];
91
+	protected function getMissingGroups () : array {
92
+		$missing = [ ];
93 93
 		foreach ( $this->actualList as $adm => $groups ) {
94
-			$curMissing = array_diff( $groups, array_keys( $this->botList[$adm] ?? [] ) );
94
+			$curMissing = array_diff( $groups, array_keys( $this->botList[ $adm ] ?? [ ] ) );
95 95
 
96 96
 			foreach ( $curMissing as $group ) {
97 97
 				try {
98 98
 					$missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group );
99 99
 				} catch ( TaskException $e ) {
100
-					$this->errors[] = $e->getMessage();
100
+					$this->errors[ ] = $e->getMessage();
101 101
 				}
102 102
 			}
103 103
 		}
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @return string
113 113
 	 * @throws TaskException
114 114
 	 */
115
-	protected function getFlagDate( string $admin, string $group ) : string {
115
+	protected function getFlagDate ( string $admin, string $group ) : string {
116 116
 		$this->getLogger()->info( "Retrieving $group flag date for $admin" );
117 117
 
118 118
 		$url = DEFAULT_URL;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 * @param string $group
148 148
 	 * @return string|null
149 149
 	 */
150
-	private function extractTimestamp( \stdClass $data, string $group ) : ?string {
150
+	private function extractTimestamp ( \stdClass $data, string $group ) : ?string {
151 151
 		$ts = null;
152 152
 		foreach ( $data->query->logevents as $entry ) {
153 153
 			if ( isset( $entry->params ) ) {
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
 	 *
167 167
 	 * @return array[]
168 168
 	 */
169
-	protected function getExtraGroups() : array {
170
-		$extra = [];
169
+	protected function getExtraGroups () : array {
170
+		$extra = [ ];
171 171
 		foreach ( $this->botList as $name => $groups ) {
172 172
 			// These are not groups
173 173
 			unset( $groups[ 'override' ], $groups[ 'override-perm' ] );
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 * @param array[] $extra
188 188
 	 * @return array[]
189 189
 	 */
190
-	protected function getNewContent( array $missing, array $extra ) : array {
190
+	protected function getNewContent ( array $missing, array $extra ) : array {
191 191
 		$newContent = $this->botList;
192 192
 		foreach ( $newContent as $user => $groups ) {
193 193
 			if ( isset( $missing[ $user ] ) ) {
@@ -212,15 +212,15 @@  discard block
 block discarded – undo
212 212
 	 * @param array[] $newContent
213 213
 	 * @return array[]
214 214
 	 */
215
-	protected function removeOverrides( array $newContent ) : array {
216
-		$removed = [];
215
+	protected function removeOverrides ( array $newContent ) : array {
216
+		$removed = [ ];
217 217
 		foreach ( $newContent as $user => $groups ) {
218 218
 			$ts = PageBotList::getValidFlagTimestamp( $groups );
219
-			if ( isset( $groups['override'] ) && ( date( 'd/m', $ts ) ===
219
+			if ( isset( $groups[ 'override' ] ) && ( date( 'd/m', $ts ) ===
220 220
 				date( 'd/m', strtotime( '- 1 days' ) ) )
221 221
 			) {
222 222
 				unset( $newContent[ $user ][ 'override' ] );
223
-				$removed[] = $user;
223
+				$removed[ ] = $user;
224 224
 			}
225 225
 		}
226 226
 
Please login to merge, or discard this patch.