Passed
Push — master ( 42aaff...766431 )
by Daimona
01:42
created
includes/Task/Subtask/Subtask.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\Task\Subtask;
4 4
 
Please login to merge, or discard this patch.
includes/Task/Subtask/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\Subtask;
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 CreatePages' );
19 19
 		$users = $this->getDataProvider()->getUsersToProcess();
20 20
 
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * @param string $user
37 37
 	 * @param array $groups
38 38
 	 */
39
-	protected function processUser( string $user, array $groups ) {
39
+	protected function processUser ( string $user, array $groups ) {
40 40
 		try {
41 41
 			$num = $this->getLastPageNum( $user ) + 1;
42 42
 		} catch ( TaskException $e ) {
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 	 * @return int
69 69
 	 * @throws TaskException
70 70
 	 */
71
-	protected function getLastPageNum( string $user ) : int {
71
+	protected function getLastPageNum ( string $user ) : int {
72 72
 		$this->getLogger()->debug( "Retrieving previous pages for $user" );
73
-		$unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[1];
73
+		$unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[ 1 ];
74 74
 		$params = [
75 75
 			'action' => 'query',
76 76
 			'list' => 'allpages',
@@ -105,14 +105,14 @@  discard block
 block discarded – undo
105 105
 	 * @param string $user
106 106
 	 * @param array $groups
107 107
 	 */
108
-	protected function createPage( string $title, string $user, array $groups ) {
108
+	protected function createPage ( string $title, string $user, array $groups ) {
109 109
 		$this->getLogger()->info( "Creating page $title" );
110 110
 		$text = $this->getConfig()->get( 'ric-page-text' );
111 111
 		$textParams = [
112 112
 			'$user' => $user,
113
-			'$date' => $groups['sysop'],
114
-			'$burocrate' => $groups['bureaucrat'] ?? '',
115
-			'$checkuser' => $groups['checkuser'] ?? ''
113
+			'$date' => $groups[ 'sysop' ],
114
+			'$burocrate' => $groups[ 'bureaucrat' ] ?? '',
115
+			'$checkuser' => $groups[ 'checkuser' ] ?? ''
116 116
 		];
117 117
 		$text = strtr( $text, $textParams );
118 118
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 	 * @param string $title
132 132
 	 * @param string $newText
133 133
 	 */
134
-	protected function createBasePage( string $title, string $newText ) {
134
+	protected function createBasePage ( string $title, string $newText ) {
135 135
 		$this->getLogger()->info( "Creating base page $title" );
136 136
 
137 137
 		$params = [
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 * @param string $title
149 149
 	 * @param string $newText
150 150
 	 */
151
-	protected function updateBasePage( string $title, string $newText ) {
151
+	protected function updateBasePage ( string $title, string $newText ) {
152 152
 		$this->getLogger()->info( "Updating base page $title" );
153 153
 
154 154
 		$params = [
Please login to merge, or discard this patch.
includes/Task/UpdateList.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
 
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
 	/**
19 19
 	 * @inheritDoc
20 20
 	 */
21
-	protected function getSubtasksMap(): array {
21
+	protected function getSubtasksMap (): array {
22 22
 		// Everything is done here.
23
-		return [];
23
+		return [ ];
24 24
 	}
25 25
 
26 26
 	/**
27 27
 	 * @inheritDoc
28 28
 	 */
29
-	public function run() : TaskResult {
29
+	public function run () : TaskResult {
30 30
 		$this->getLogger()->info( 'Starting task UpdateList' );
31 31
 		$this->actualList = $this->getActualAdmins();
32 32
 		$this->botList = $this->getDataProvider()->getUsersList();
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	/**
62 62
 	 * @return array
63 63
 	 */
64
-	protected function getActualAdmins() : array {
64
+	protected function getActualAdmins () : array {
65 65
 		$this->getLogger()->debug( 'Retrieving admins - API' );
66 66
 		$params = [
67 67
 			'action' => 'query',
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 	 * @param \stdClass $data
80 80
 	 * @return array
81 81
 	 */
82
-	protected function extractAdmins( \stdClass $data ) : array {
83
-		$ret = [];
82
+	protected function extractAdmins ( \stdClass $data ) : array {
83
+		$ret = [ ];
84 84
 		$blacklist = $this->getConfig()->get( 'exclude-admins' );
85 85
 		foreach ( $data->query->allusers as $u ) {
86 86
 			if ( in_array( $u->name, $blacklist ) ) {
@@ -97,22 +97,22 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @return array[]
99 99
 	 */
100
-	protected function getMissingGroups() : array {
101
-		$missing = [];
100
+	protected function getMissingGroups () : array {
101
+		$missing = [ ];
102 102
 		foreach ( $this->actualList as $adm => $groups ) {
103
-			$groupsList = [];
103
+			$groupsList = [ ];
104 104
 			if ( !isset( $this->botList[ $adm ] ) ) {
105 105
 				$groupsList = $groups;
106
-			} elseif ( count( $groups ) > count( $this->botList[$adm] ) ) {
106
+			} elseif ( count( $groups ) > count( $this->botList[ $adm ] ) ) {
107 107
 				// Only some groups are missing
108
-				$groupsList = array_diff_key( $groups, $this->botList[$adm] );
108
+				$groupsList = array_diff_key( $groups, $this->botList[ $adm ] );
109 109
 			}
110 110
 
111 111
 			foreach ( $groupsList as $group ) {
112 112
 				try {
113 113
 					$missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group );
114 114
 				} catch ( TaskException $e ) {
115
-					$this->errors[] = $e->getMessage();
115
+					$this->errors[ ] = $e->getMessage();
116 116
 				}
117 117
 			}
118 118
 		}
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	 * @return string
128 128
 	 * @throws TaskException
129 129
 	 */
130
-	protected function getFlagDate( string $admin, string $group ) : string {
130
+	protected function getFlagDate ( string $admin, string $group ) : string {
131 131
 		$this->getLogger()->info( "Retrieving $group flag date for $admin" );
132 132
 
133 133
 		$url = DEFAULT_URL;
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * @param string $group
163 163
 	 * @return string|null
164 164
 	 */
165
-	private function extractTimestamp( \stdClass $data, string $group ) : ?string {
165
+	private function extractTimestamp ( \stdClass $data, string $group ) : ?string {
166 166
 		$ts = null;
167 167
 		foreach ( $data->query->logevents as $entry ) {
168 168
 			if ( !isset( $entry->params ) ) {
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 *
185 185
 	 * @return array[]
186 186
 	 */
187
-	protected function getExtraGroups() : array {
188
-		$extra = [];
187
+	protected function getExtraGroups () : array {
188
+		$extra = [ ];
189 189
 		foreach ( $this->botList as $name => $groups ) {
190 190
 			if ( !isset( $this->actualList[ $name ] ) ) {
191 191
 				$extra[ $name ] = $groups;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 *
202 202
 	 * @param array $newContent
203 203
 	 */
204
-	protected function doUpdateList( array $newContent ) {
204
+	protected function doUpdateList ( array $newContent ) {
205 205
 		$this->getLogger()->info( 'Updating admin list' );
206 206
 
207 207
 		$params = [
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 * @param array[] $extra
221 221
 	 * @return array[]
222 222
 	 */
223
-	protected function getNewContent( array $missing, array $extra ) : array {
223
+	protected function getNewContent ( array $missing, array $extra ) : array {
224 224
 		$newContent = $this->botList;
225 225
 		foreach ( $newContent as $user => $groups ) {
226 226
 			if ( isset( $missing[ $user ] ) ) {
Please login to merge, or discard this patch.
includes/Task/Task.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\Task;
4 4
 
@@ -14,13 +14,13 @@  discard block
 block discarded – undo
14 14
 	 *
15 15
 	 * @return string[]
16 16
 	 */
17
-	abstract protected function getSubtasksMap() : array;
17
+	abstract protected function getSubtasksMap () : array;
18 18
 
19 19
 	/**
20 20
 	 * @param string $subtask Defined in self::SUBTASKS_MAP
21 21
 	 * @return TaskResult
22 22
 	 */
23
-	protected function runSubtask( string $subtask ) : TaskResult {
23
+	protected function runSubtask ( string $subtask ) : TaskResult {
24 24
 		$map = $this->getSubtasksMap();
25 25
 		if ( !isset( $map[ $subtask ] ) ) {
26 26
 			throw new \InvalidArgumentException( "'$subtask' is not a valid task." );
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * @param string $class
37 37
 	 * @return Subtask
38 38
 	 */
39
-	private function getSubtaskInstance( string $class ) : Subtask {
39
+	private function getSubtaskInstance ( string $class ) : Subtask {
40 40
 		return new $class( $this->getDataProvider() );
41 41
 	}
42 42
 }
Please login to merge, or discard this patch.
includes/Task/StartNew.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\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
 		$orderedList = [
19 19
 			'update-list',
20 20
 			'create-pages',
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	/**
34 34
 	 * @inheritDoc
35 35
 	 */
36
-	protected function getSubtasksMap() : array {
36
+	protected function getSubtasksMap () : array {
37 37
 		return [
38 38
 			'create-pages' => CreatePages::class,
39 39
 			'update-list' => UpdateList::class,
Please login to merge, or discard this patch.
includes/Task/TaskBase.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
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	const STATUS_OK = 0;
15 15
 	const STATUS_ERROR = 1;
16 16
 	/** @var string[] */
17
-	protected $errors = [];
17
+	protected $errors = [ ];
18 18
 	/** @var TaskDataProvider */
19 19
 	protected $dataProvider;
20 20
 
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param TaskDataProvider $dataProvider
25 25
 	 */
26
-	final public function __construct( TaskDataProvider $dataProvider ) {
26
+	final public function __construct ( TaskDataProvider $dataProvider ) {
27 27
 		set_exception_handler( [ $this, 'handleException' ] );
28 28
 		set_error_handler( [ $this, 'handleError' ] );
29 29
 		parent::__construct();
30 30
 		$this->dataProvider = $dataProvider;
31 31
 	}
32 32
 
33
-	public function __destruct() {
33
+	public function __destruct () {
34 34
 		restore_error_handler();
35 35
 		restore_exception_handler();
36 36
 	}
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @return TaskResult
42 42
 	 */
43
-	abstract public function run() : TaskResult;
43
+	abstract public function run () : TaskResult;
44 44
 
45 45
 	/**
46 46
 	 * Exception handler.
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @param \Throwable $ex
49 49
 	 * @protected
50 50
 	 */
51
-	public function handleException( \Throwable $ex ) {
51
+	public function handleException ( \Throwable $ex ) {
52 52
 		$this->getLogger()->error(
53 53
 			get_class( $ex ) . ': ' .
54 54
 			$ex->getMessage() . "\nTrace:\n" .
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
 	 * @param int $errline
66 66
 	 * @protected
67 67
 	 */
68
-	public function handleError( $errno, $errstr, $errfile, $errline ) {
68
+	public function handleError ( $errno, $errstr, $errfile, $errline ) {
69 69
 		throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline );
70 70
 	}
71 71
 
72 72
 	/**
73 73
 	 * @return TaskDataProvider
74 74
 	 */
75
-	protected function getDataProvider() : TaskDataProvider {
75
+	protected function getDataProvider () : TaskDataProvider {
76 76
 		return $this->dataProvider;
77 77
 	}
78 78
 }
Please login to merge, or discard this patch.
includes/Bot.php 1 patch
Spacing   +5 added lines, -5 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,14 +11,14 @@  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
 
18 18
 	/**
19 19
 	 * Entry point for the whole process
20 20
 	 */
21
-	public function run() {
21
+	public function run () {
22 22
 		$this->logger->info( 'Starting full process.' );
23 23
 		$manager = new TaskManager;
24 24
 		$res = $manager->run( TaskManager::MODE_COMPLETE );
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param string $task
37 37
 	 */
38
-	public function runTask( string $task ) {
38
+	public function runTask ( string $task ) {
39 39
 		$this->logger->info( "Starting single task $task." );
40 40
 		$manager = new TaskManager;
41 41
 		$res = $manager->run( TaskManager::MODE_TASK, $task );
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @param string $subtask
54 54
 	 */
55
-	public function runSubtask( string $subtask ) {
55
+	public function runSubtask ( string $subtask ) {
56 56
 		$this->logger->info( "Starting single subtask $subtask." );
57 57
 		$manager = new TaskManager;
58 58
 		$res = $manager->run( TaskManager::MODE_SUBTASK, $subtask );
Please login to merge, or discard this patch.
includes/TaskManager.php 1 patch
Spacing   +9 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
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 * @param string|null $name Only used in MODE_TASK and MODE_SUBTASK
48 48
 	 * @return TaskResult
49 49
 	 */
50
-	public function run( int $mode, string $name = null ) : TaskResult {
50
+	public function run ( int $mode, string $name = null ) : TaskResult {
51 51
 		$this->provider = new TaskDataProvider;
52 52
 
53 53
 		if ( $mode === self::MODE_COMPLETE ) {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 *
65 65
 	 * @return TaskResult
66 66
 	 */
67
-	protected function runAllTasks() : TaskResult {
67
+	protected function runAllTasks () : TaskResult {
68 68
 		if ( self::getLastFullRunDate() === date( 'd/m/Y' ) ) {
69 69
 			// Really avoid executing twice the same day
70 70
 			return new TaskResult( TaskResult::STATUS_ERROR, [ 'A full run was already executed today.' ] );
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * @param string $name
96 96
 	 * @return TaskResult
97 97
 	 */
98
-	protected function runTask( string $name ) : TaskResult {
98
+	protected function runTask ( string $name ) : TaskResult {
99 99
 		if ( !isset( self::TASKS_MAP[ $name ] ) ) {
100 100
 			throw new \InvalidArgumentException( "'$name' is not a valid task." );
101 101
 		}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @param string $name
111 111
 	 * @return TaskResult
112 112
 	 */
113
-	protected function runSubtask( string $name ) : TaskResult {
113
+	protected function runSubtask ( string $name ) : TaskResult {
114 114
 		if ( !isset( self::SUBTASKS_MAP[ $name ] ) ) {
115 115
 			throw new \InvalidArgumentException( "'$name' is not a valid subtask." );
116 116
 		}
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 * @return string|null d/m/Y or null if no last run registered
125 125
 	 * @fixme Is this even necessary?
126 126
 	 */
127
-	public static function getLastFullRunDate() : ?string {
127
+	public static function getLastFullRunDate () : ?string {
128 128
 		if ( file_exists( self::LOG_FILE ) ) {
129 129
 			return file_get_contents( self::LOG_FILE ) ?: null;
130 130
 		} else {
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 * @param string $class
139 139
 	 * @return Task
140 140
 	 */
141
-	private function getTaskInstance( string $class ) : Task {
141
+	private function getTaskInstance ( string $class ) : Task {
142 142
 		return new $class( $this->provider );
143 143
 	}
144 144
 
@@ -148,11 +148,11 @@  discard block
 block discarded – undo
148 148
 	 * @param string $class
149 149
 	 * @return Subtask
150 150
 	 */
151
-	private function getSubtaskInstance( string $class ) : Subtask {
151
+	private function getSubtaskInstance ( string $class ) : Subtask {
152 152
 		return new $class( $this->provider );
153 153
 	}
154 154
 
155
-	public static function setLastFullRunDate() {
155
+	public static function setLastFullRunDate () {
156 156
 		file_put_contents( self::LOG_FILE, date( 'd/m/Y' ) );
157 157
 	}
158 158
 }
Please login to merge, or discard this patch.
run.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
  * Entry point for the bot, called by CLI
4 4
  */
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
 /* URL (for debugging purpose) */
39 39
 $urlParam = getopt( '', [ 'force-url:' ] );
40
-$url = $urlParam['force-url'] ?? 'https://it.wikipedia.org/w/api.php';
40
+$url = $urlParam[ 'force-url' ] ?? 'https://it.wikipedia.org/w/api.php';
41 41
 
42 42
 define( 'DEFAULT_URL', $url );
43 43
 
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 
88 88
 if ( count( $taskOpts ) === 2 ) {
89 89
 	throw new InvalidArgumentException( 'Cannot specify both task and subtask.' );
90
-} elseif ( isset( $taskOpts['task'] ) ) {
90
+} elseif ( isset( $taskOpts[ 'task' ] ) ) {
91 91
 	$bot->runTask( $taskOpts[ 'task' ] );
92
-} elseif ( isset( $taskOpts['subtask'] ) ) {
92
+} elseif ( isset( $taskOpts[ 'subtask' ] ) ) {
93 93
 	$bot->runSubtask( $taskOpts[ 'subtask' ] );
94 94
 } else {
95 95
 	$bot->run();
Please login to merge, or discard this patch.