Passed
Push — master ( a5fa97...e322fd )
by Daimona
01:42
created
includes/Bot.php 1 patch
Spacing   +12 added lines, -12 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
 
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
 	 * Entry point for the whole process
17 17
 	 */
18 18
 	public function run() {
19
-		$this->logger->info( 'Starting full process.' );
19
+		$this->logger->info('Starting full process.');
20 20
 		$manager = new TaskManager;
21
-		$res = $manager->run( TaskManager::MODE_COMPLETE );
21
+		$res = $manager->run(TaskManager::MODE_COMPLETE);
22 22
 		$line = '---------------------------------------------------';
23
-		if ( $res->isOK() ) {
24
-			$this->logger->info( "Execution completed successfully.\n$line\n\n" );
23
+		if ($res->isOK()) {
24
+			$this->logger->info("Execution completed successfully.\n$line\n\n");
25 25
 		} else {
26
-			$this->logger->error( "Execution failed.\n$res\n$line\n\n" );
26
+			$this->logger->error("Execution failed.\n$res\n$line\n\n");
27 27
 		}
28 28
 	}
29 29
 
@@ -32,15 +32,15 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param string $task
34 34
 	 */
35
-	public function runSingle( string $task ) {
36
-		$this->logger->info( "Starting single task $task." );
35
+	public function runSingle(string $task) {
36
+		$this->logger->info("Starting single task $task.");
37 37
 		$manager = new TaskManager;
38
-		$res = $manager->run( TaskManager::MODE_SINGLE, $task );
38
+		$res = $manager->run(TaskManager::MODE_SINGLE, $task);
39 39
 		$line = '---------------------------------------------------';
40
-		if ( $res->isOK() ) {
41
-			$this->logger->info( "Execution of $task completed successfully.\n$line\n\n" );
40
+		if ($res->isOK()) {
41
+			$this->logger->info("Execution of $task completed successfully.\n$line\n\n");
42 42
 		} else {
43
-			$this->logger->error( "Execution of $task failed.\n$res\n$line\n\n" );
43
+			$this->logger->error("Execution of $task failed.\n$res\n$line\n\n");
44 44
 		}
45 45
 	}
46 46
 }
Please login to merge, or discard this patch.
run.php 1 patch
Spacing   +22 added lines, -22 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
 require __DIR__ . '/vendor/autoload.php';
4 4
 
@@ -6,8 +6,8 @@  discard block
 block discarded – undo
6 6
 use BotRiconferme\Bot;
7 7
 use BotRiconferme\Request\RequestBase;
8 8
 
9
-if ( PHP_SAPI !== 'cli' ) {
10
-	exit( 'CLI only!' );
9
+if (PHP_SAPI !== 'cli') {
10
+	exit('CLI only!');
11 11
 }
12 12
 
13 13
 /** MAIN PARAMS */
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
 	'config-title:'
27 27
 ];
28 28
 
29
-$vals = getopt( '', $params );
30
-if ( count( $vals ) !== count( $params ) ) {
31
-	exit( 'Not enough params!' );
29
+$vals = getopt('', $params);
30
+if (count($vals) !== count($params)) {
31
+	exit('Not enough params!');
32 32
 }
33 33
 
34 34
 /* URL (for debugging purpose) */
35
-$url = getopt( '', [ 'force-url:' ] );
36
-if ( isset( $url['force-url'] ) ) {
35
+$url = getopt('', ['force-url:']);
36
+if (isset($url['force-url'])) {
37 37
 	RequestBase::$url = $url['force-url'];
38 38
 }
39 39
 
@@ -47,38 +47,38 @@  discard block
 block discarded – undo
47 47
  * --use-password-file
48 48
  * which will look for a $PWFILE file in the current directory containing only the plain password
49 49
  */
50
-$pwParams = getopt( '', [
50
+$pwParams = getopt('', [
51 51
 	'password:',
52 52
 	'use-password-file'
53
-] );
53
+]);
54 54
 
55
-if ( isset( $pwParams[ 'password' ] ) ) {
56
-	$pw = $pwParams[ 'password' ];
57
-} elseif ( isset( $pwParams[ 'use-password-file' ] ) ) {
58
-	if ( file_exists( $PWFILE ) ) {
59
-		$pw = trim( file_get_contents( $PWFILE ) );
55
+if (isset($pwParams['password'])) {
56
+	$pw = $pwParams['password'];
57
+} elseif (isset($pwParams['use-password-file'])) {
58
+	if (file_exists($PWFILE)) {
59
+		$pw = trim(file_get_contents($PWFILE));
60 60
 	} else {
61
-		exit( 'Please create a password.txt file to use with use-password-file' );
61
+		exit('Please create a password.txt file to use with use-password-file');
62 62
 	}
63 63
 } else {
64
-	exit( 'Please provide a password or use a password file' );
64
+	exit('Please provide a password or use a password file');
65 65
 }
66 66
 
67
-$vals[ 'password' ] = $pw;
67
+$vals['password'] = $pw;
68 68
 
69 69
 /* START */
70 70
 
71
-Config::init( $vals );
71
+Config::init($vals);
72 72
 
73 73
 $bot = new Bot();
74 74
 
75 75
 /*
76 76
  * E.g. --task=update-list
77 77
  */
78
-$taskOpts = getopt( '', [ 'task:' ] );
78
+$taskOpts = getopt('', ['task:']);
79 79
 
80
-if ( $taskOpts ) {
81
-	$bot->runSingle( $taskOpts[ 'task' ] );
80
+if ($taskOpts) {
81
+	$bot->runSingle($taskOpts['task']);
82 82
 } else {
83 83
 	$bot->run();
84 84
 }
Please login to merge, or discard this patch.
includes/Task/CreatePage.php 1 patch
Spacing   +46 added lines, -46 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,55 +107,55 @@  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 116
 			'$burocrate' => $groups['bureaucrat'] ?? '',
117 117
 			'$checkuser' => $groups['checkuser'] ?? ''
118 118
 		];
119
-		$text = strtr( $text, $textParams );
119
+		$text = strtr($text, $textParams);
120 120
 
121 121
 		$params = [
122 122
 			'title' => $title,
123 123
 			'text' => $text,
124
-			'summary' => $this->getConfig()->get( 'ric-page-summary' )
124
+			'summary' => $this->getConfig()->get('ric-page-summary')
125 125
 		];
126 126
 
127
-		$this->getController()->editPage( $params );
127
+		$this->getController()->editPage($params);
128 128
 	}
129 129
 
130 130
 	/**
131 131
 	 * @param string $title
132 132
 	 * @param string $newText
133 133
 	 */
134
-	protected function createBasePage( string $title, string $newText ) {
135
-		$this->getLogger()->info( "Creating base page $title" );
134
+	protected function createBasePage(string $title, string $newText) {
135
+		$this->getLogger()->info("Creating base page $title");
136 136
 
137 137
 		$params = [
138 138
 			'title' => $title,
139 139
 			'text' => $newText,
140
-			'summary' => $this->getConfig()->get( 'ric-base-page-summary' )
140
+			'summary' => $this->getConfig()->get('ric-base-page-summary')
141 141
 		];
142 142
 
143
-		$this->getController()->editPage( $params );
143
+		$this->getController()->editPage($params);
144 144
 	}
145 145
 
146 146
 	/**
147 147
 	 * @param string $title
148 148
 	 * @param string $newText
149 149
 	 */
150
-	protected function updateBasePage( string $title, string $newText ) {
151
-		$this->getLogger()->info( "Updating base page $title" );
150
+	protected function updateBasePage(string $title, string $newText) {
151
+		$this->getLogger()->info("Updating base page $title");
152 152
 
153 153
 		$params = [
154 154
 			'title' => $title,
155 155
 			'appendtext' => $newText,
156
-			'summary' => $this->getConfig()->get( 'ric-base-page-summary-update' )
156
+			'summary' => $this->getConfig()->get('ric-base-page-summary-update')
157 157
 		];
158 158
 
159
-		$this->getController()->editPage( $params );
159
+		$this->getController()->editPage($params);
160 160
 	}
161 161
 }
Please login to merge, or discard this patch.