Passed
Push — master ( b237e3...69f046 )
by Daimona
01:32
created
includes/Task/CreatePages.php 1 patch
Spacing   +11 added lines, -11 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
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 	/**
14 14
 	 * @inheritDoc
15 15
 	 */
16
-	public function run() : TaskResult {
16
+	public function run () : TaskResult {
17 17
 		$this->getLogger()->info( 'Starting task CreatePages' );
18 18
 		$users = $this->getDataProvider()->getUsersToProcess();
19 19
 
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * @param string $user
36 36
 	 * @param array $groups
37 37
 	 */
38
-	protected function processUser( string $user, array $groups ) {
38
+	protected function processUser ( string $user, array $groups ) {
39 39
 		try {
40 40
 			$num = $this->getLastPageNum( $user ) + 1;
41 41
 		} catch ( TaskException $e ) {
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 	 * @return int
66 66
 	 * @throws TaskException
67 67
 	 */
68
-	protected function getLastPageNum( string $user ) : int {
68
+	protected function getLastPageNum ( string $user ) : int {
69 69
 		$this->getLogger()->debug( "Retrieving previous pages for $user" );
70
-		$unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[1];
70
+		$unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[ 1 ];
71 71
 		$params = [
72 72
 			'action' => 'query',
73 73
 			'list' => 'allpages',
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
 	 * @param string $user
103 103
 	 * @param array $groups
104 104
 	 */
105
-	protected function createPage( string $title, string $user, array $groups ) {
105
+	protected function createPage ( string $title, string $user, array $groups ) {
106 106
 		$this->getLogger()->info( "Creating page $title" );
107 107
 		$text = $this->getConfig()->get( 'ric-page-text' );
108 108
 		$textParams = [
109 109
 			'$user' => $user,
110
-			'$date' => $groups['sysop'],
111
-			'$burocrate' => $groups['bureaucrat'] ?? '',
112
-			'$checkuser' => $groups['checkuser'] ?? ''
110
+			'$date' => $groups[ 'sysop' ],
111
+			'$burocrate' => $groups[ 'bureaucrat' ] ?? '',
112
+			'$checkuser' => $groups[ 'checkuser' ] ?? ''
113 113
 		];
114 114
 		$text = strtr( $text, $textParams );
115 115
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @param string $title
129 129
 	 * @param string $newText
130 130
 	 */
131
-	protected function createBasePage( string $title, string $newText ) {
131
+	protected function createBasePage ( string $title, string $newText ) {
132 132
 		$this->getLogger()->info( "Creating base page $title" );
133 133
 
134 134
 		$params = [
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @param string $title
146 146
 	 * @param string $newText
147 147
 	 */
148
-	protected function updateBasePage( string $title, string $newText ) {
148
+	protected function updateBasePage ( string $title, string $newText ) {
149 149
 		$this->getLogger()->info( "Updating base page $title" );
150 150
 
151 151
 		$params = [
Please login to merge, or discard this patch.
includes/Task/ClosePages.php 1 patch
Spacing   +19 added lines, -19 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
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	/**
15 15
 	 * @inheritDoc
16 16
 	 */
17
-	public function run() : TaskResult {
17
+	public function run () : TaskResult {
18 18
 		$this->getLogger()->info( 'Starting task ClosePages' );
19 19
 
20 20
 		$titles = $this->getPagesList();
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return string[]
40 40
 	 */
41
-	protected function getPagesList() : array {
41
+	protected function getPagesList () : array {
42 42
 		$allPages = $this->getTranscludedPages();
43
-		$ret = [];
43
+		$ret = [ ];
44 44
 		foreach ( $allPages as $page ) {
45 45
 			$created = $this->getController()->getPageCreationTS( $page );
46 46
 			if ( time() - $created <= 60 * 60 * 24 * 7 && !$this->hasOpposition( $page ) ) {
47
-				$ret[] = $page;
47
+				$ret[ ] = $page;
48 48
 			}
49 49
 		}
50 50
 		return $ret;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @return string[]
57 57
 	 */
58
-	protected function getTranscludedPages() : array {
58
+	protected function getTranscludedPages () : array {
59 59
 		$baseTitle = $this->getConfig()->get( 'ric-main-page' );
60 60
 		$params = [
61 61
 			'action' => 'query',
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
 
68 68
 		$res = RequestBase::newFromParams( $params )->execute();
69 69
 		$pages = $res->query->pages;
70
-		$ret = [];
70
+		$ret = [ ];
71 71
 		foreach ( reset( $pages )->templates as $page ) {
72 72
 			if ( preg_match( "!$baseTitle\/[^\/]+\/\d!", $page->title ) !== false ) {
73
-				$ret[] = $page->title;
73
+				$ret[ ] = $page->title;
74 74
 			}
75 75
 		}
76 76
 		return $ret;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 * @param string $page
81 81
 	 * @return bool
82 82
 	 */
83
-	protected function hasOpposition( string $page ) : bool {
83
+	protected function hasOpposition ( string $page ) : bool {
84 84
 		$params = [
85 85
 			'action' => 'query',
86 86
 			'prop' => 'revisions',
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 	 * @param string[] $titles
101 101
 	 * @see UpdatesAround::addToMainPage()
102 102
 	 */
103
-	protected function removeFromMainPage( array $titles ) {
103
+	protected function removeFromMainPage ( array $titles ) {
104 104
 		$this->getLogger()->info( 'Removing from main: ' . implode( ', ', $titles ) );
105 105
 
106 106
 		$mainPage = $this->getConfig()->get( 'ric-main-page' );
107 107
 		$content = $this->getController()->getPageContent( $mainPage );
108
-		$translations = [];
108
+		$translations = [ ];
109 109
 		foreach ( $titles as $title ) {
110 110
 			$translations[ '{{' . $title . '}}' ] = '';
111 111
 		}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 *
124 124
 	 * @param string[] $titles
125 125
 	 */
126
-	protected function addToArchive( array $titles ) {
126
+	protected function addToArchive ( array $titles ) {
127 127
 		$this->getLogger()->info( 'Adding to archive: ' . implode( ', ', $titles ) );
128 128
 
129 129
 		$archiveTitle = $this->getConfig()->get( 'close-archive-title' );
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 * @param string $title
148 148
 	 * @see CreatePages::updateBasePage()
149 149
 	 */
150
-	protected function updateBasePage( string $title ) {
150
+	protected function updateBasePage ( string $title ) {
151 151
 		$this->getLogger()->info( "Updating base page $title" );
152 152
 
153 153
 		$baseTitle = substr( $title, 0, strrpos( $title, '/' ) );
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 * @param string[] $titles
168 168
 	 * @see UpdatesAround::addVote()
169 169
 	 */
170
-	protected function updateVote( array $titles ) {
170
+	protected function updateVote ( array $titles ) {
171 171
 		$votePage = $this->getConfig()->get( 'ric-vote-page' );
172 172
 		$content = $this->getController()->getPageContent( $votePage );
173 173
 
@@ -193,19 +193,19 @@  discard block
 block discarded – undo
193 193
 	 * @throws TaskException
194 194
 	 * @see UpdatesAround::addNews()
195 195
 	 */
196
-	protected function updateNews( int $amount ) {
196
+	protected function updateNews ( int $amount ) {
197 197
 		$this->getLogger()->info( "Decreasing the news counter by $amount" );
198 198
 		$newsPage = $this->getConfig()->get( 'ric-news-page' );
199 199
 
200 200
 		$content = $this->getController()->getPageContent( $newsPage );
201 201
 		$reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!';
202 202
 
203
-		$matches = [];
203
+		$matches = [ ];
204 204
 		if ( preg_match( $reg, $content, $matches ) === false ) {
205 205
 			throw new TaskException( 'Param not found in news page' );
206 206
 		}
207 207
 
208
-		$newNum = (int)$matches[2] - $amount;
208
+		$newNum = (int)$matches[ 2 ] - $amount;
209 209
 		$newContent = preg_replace( $reg, '${1}' . $newNum, $content );
210 210
 
211 211
 		$params = [
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
 	 *
223 223
 	 * @param string[] $titles
224 224
 	 */
225
-	protected function updateAdminList( array $titles ) {
225
+	protected function updateAdminList ( array $titles ) {
226 226
 		$listTitle = $this->getConfig()->get( 'admins-list' );
227 227
 		$content = $this->getController()->getPageContent( $listTitle );
228 228
 		$newDate = date( 'Ymd', strtotime( '+1 year' ) );
229 229
 		foreach ( $titles as $title ) {
230
-			$user = explode( '/', $title )[2];
230
+			$user = explode( '/', $title )[ 2 ];
231 231
 			$reg = "!(\{\{Amministratore\/riga\|$user.+\| *)\d+(?= *\|(?: *pausa)? *\}\})!";
232 232
 			$content = preg_replace( $reg, '$1' . $newDate, $content );
233 233
 		}
Please login to merge, or discard this patch.
includes/WikiController.php 1 patch
Spacing   +11 added lines, -11 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
 
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	/** @var string[] */
20 20
 	private $tokens;
21 21
 
22
-	public function __construct() {
22
+	public function __construct () {
23 23
 		$this->logger = new Logger;
24 24
 	}
25 25
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 * @return string
31 31
 	 * @throws MissingPageException
32 32
 	 */
33
-	public function getPageContent( string $title ) : string {
33
+	public function getPageContent ( string $title ) : string {
34 34
 		$this->logger->debug( "Retrieving page $title" );
35 35
 		$params = [
36 36
 			'action' => 'query',
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 			throw new MissingPageException( $title );
48 48
 		}
49 49
 
50
-		return $page->revisions[0]->slots->main->{ '*' };
50
+		return $page->revisions[ 0 ]->slots->main->{ '*' };
51 51
 	}
52 52
 
53 53
 	/**
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 * @param array $params
57 57
 	 * @throws EditException
58 58
 	 */
59
-	public function editPage( array $params ) {
59
+	public function editPage ( array $params ) {
60 60
 		$this->login();
61 61
 
62 62
 		$params = [
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * Login wrapper. Checks if we're already logged in and clears tokens cache
76 76
 	 * @throws LoginException
77 77
 	 */
78
-	public function login() {
78
+	public function login () {
79 79
 		if ( self::$loggedIn ) {
80 80
 			$this->logger->debug( 'Already logged in' );
81 81
 			return;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 
103 103
 		self::$loggedIn = true;
104 104
 		// Clear tokens cache
105
-		$this->tokens = [];
105
+		$this->tokens = [ ];
106 106
 		$this->logger->info( 'Login succeeded' );
107 107
 	}
108 108
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @param string $type
113 113
 	 * @return string
114 114
 	 */
115
-	public function getToken( string $type ) : string {
115
+	public function getToken ( string $type ) : string {
116 116
 		if ( !isset( $this->tokens[ $type ] ) ) {
117 117
 			$params = [
118 118
 				'action' => 'query',
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	 * @param string $title
136 136
 	 * @return int
137 137
 	 */
138
-	public function getPageCreationTS( string $title ) : int {
138
+	public function getPageCreationTS ( string $title ) : int {
139 139
 		$params = [
140 140
 			'action' => 'query',
141 141
 			'prop' => 'revisions',
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 
149 149
 		$res = ( RequestBase::newFromParams( $params ) )->execute();
150 150
 		$data = $res->query->pages;
151
-		return strtotime( reset( $data )->revisions[0]->timestamp );
151
+		return strtotime( reset( $data )->revisions[ 0 ]->timestamp );
152 152
 	}
153 153
 
154 154
 	/**
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 * @param string $title
158 158
 	 * @param string $reason
159 159
 	 */
160
-	public function protectPage( string $title, string $reason ) {
160
+	public function protectPage ( string $title, string $reason ) {
161 161
 		$this->logger->info( "Protecting page $title" );
162 162
 		$this->login();
163 163
 
Please login to merge, or discard this patch.