Passed
Push — master ( 505550...c52a51 )
by Daimona
01:45
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
 
@@ -14,13 +14,13 @@  discard block
 block discarded – undo
14 14
 	 * Entry point for the whole process
15 15
 	 */
16 16
 	public function run() {
17
-		$this->logger->info( 'Starting full process.' );
17
+		$this->logger->info('Starting full process.');
18 18
 		$manager = new TaskManager;
19
-		$res = $manager->run( TaskManager::MODE_COMPLETE );
20
-		if ( $res->isOK() ) {
21
-			$this->logger->info( 'Execution completed successfully.' );
19
+		$res = $manager->run(TaskManager::MODE_COMPLETE);
20
+		if ($res->isOK()) {
21
+			$this->logger->info('Execution completed successfully.');
22 22
 		} else {
23
-			$this->logger->error( "Execution failed.\n$res" );
23
+			$this->logger->error("Execution failed.\n$res");
24 24
 		}
25 25
 	}
26 26
 
@@ -29,14 +29,14 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param string $task
31 31
 	 */
32
-	public function runSingle( string $task ) {
33
-		$this->logger->info( "Starting single task $task." );
32
+	public function runSingle(string $task) {
33
+		$this->logger->info("Starting single task $task.");
34 34
 		$manager = new TaskManager;
35
-		$res = $manager->run( TaskManager::MODE_SINGLE, $task );
36
-		if ( $res->isOK() ) {
37
-			$this->logger->info( "Execution of $task completed successfully." );
35
+		$res = $manager->run(TaskManager::MODE_SINGLE, $task);
36
+		if ($res->isOK()) {
37
+			$this->logger->info("Execution of $task completed successfully.");
38 38
 		} else {
39
-			$this->logger->error( "Execution of $task failed.\n$res" );
39
+			$this->logger->error("Execution of $task failed.\n$res");
40 40
 		}
41 41
 	}
42 42
 }
Please login to merge, or discard this patch.
includes/TaskManager.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
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * Should only be used for debugging purpose.
30 30
 	 */
31 31
 	public static function resetLastRunDate() {
32
-		file_put_contents( self::LOG_FILE, '' );
32
+		file_put_contents(self::LOG_FILE, '');
33 33
 	}
34 34
 
35 35
 	/**
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 	 * @param string|null $taskName Only used in MODE_SINGLE
38 38
 	 * @return TaskResult
39 39
 	 */
40
-	public function run( int $mode, string $taskName = null ) : TaskResult {
40
+	public function run(int $mode, string $taskName = null) : TaskResult {
41 41
 		$this->provider = new TaskDataProvider;
42
-		if ( $mode === self::MODE_COMPLETE ) {
42
+		if ($mode === self::MODE_COMPLETE) {
43 43
 			return $this->runAllTasks();
44 44
 		} else {
45
-			return $this->runTask( $taskName );
45
+			return $this->runTask($taskName);
46 46
 		}
47 47
 	}
48 48
 
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 	 * @return TaskResult
51 51
 	 */
52 52
 	protected function runAllTasks() : TaskResult {
53
-		if ( self::getLastFullRunDate() === date( 'd/m/Y' ) ) {
53
+		if (self::getLastFullRunDate() === date('d/m/Y')) {
54 54
 			// Really avoid executing twice the same day
55
-			return new TaskResult( TaskResult::STATUS_ERROR, [ 'A full run was already executed today.' ] );
55
+			return new TaskResult(TaskResult::STATUS_ERROR, ['A full run was already executed today.']);
56 56
 		}
57 57
 
58 58
 		// Order matters here
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
 			'user-notice'
64 64
 		];
65 65
 
66
-		$res = new TaskResult( TaskResult::STATUS_OK );
66
+		$res = new TaskResult(TaskResult::STATUS_OK);
67 67
 		do {
68
-			$res->merge( $this->runTask( current( $list ) ) );
69
-		} while ( $res->isOK() && next( $list ) );
68
+			$res->merge($this->runTask(current($list)));
69
+		} while ($res->isOK() && next($list));
70 70
 
71
-		if ( $res->isOK() ) {
71
+		if ($res->isOK()) {
72 72
 			self::setLastFullRunDate();
73 73
 		}
74 74
 
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 	 * @return string|null d/m/Y or null if no last run registered
80 80
 	 */
81 81
 	public static function getLastFullRunDate() : ?string {
82
-		if ( file_exists( self::LOG_FILE ) ) {
83
-			return file_get_contents( self::LOG_FILE ) ?: null;
82
+		if (file_exists(self::LOG_FILE)) {
83
+			return file_get_contents(self::LOG_FILE) ?: null;
84 84
 		} else {
85 85
 			return null;
86 86
 		}
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
 	 * @param string $task Defined in self::TASKS_MAP
91 91
 	 * @return TaskResult
92 92
 	 */
93
-	protected function runTask( string $task ) : TaskResult {
94
-		if ( !isset( self::TASKS_MAP[ $task ] ) ) {
95
-			throw new \InvalidArgumentException( "'$task' is not a valid task." );
93
+	protected function runTask(string $task) : TaskResult {
94
+		if (!isset(self::TASKS_MAP[$task])) {
95
+			throw new \InvalidArgumentException("'$task' is not a valid task.");
96 96
 		}
97 97
 
98
-		$class = self::TASKS_MAP[ $task ];
99
-		return $this->getTaskInstance( $class )->run();
98
+		$class = self::TASKS_MAP[$task];
99
+		return $this->getTaskInstance($class)->run();
100 100
 	}
101 101
 
102 102
 	/**
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
 	 * @param string $class
106 106
 	 * @return Task
107 107
 	 */
108
-	private function getTaskInstance( string $class ) : Task {
109
-		return new $class( $this->provider );
108
+	private function getTaskInstance(string $class) : Task {
109
+		return new $class($this->provider);
110 110
 	}
111 111
 
112 112
 	public static function setLastFullRunDate() {
113
-		file_put_contents( self::LOG_FILE, date( 'd/m/Y' ) );
113
+		file_put_contents(self::LOG_FILE, date('d/m/Y'));
114 114
 	}
115 115
 }
Please login to merge, or discard this patch.
run.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  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
 
5 5
 use BotRiconferme\Config;
6 6
 use BotRiconferme\Bot;
7 7
 
8
-if ( PHP_SAPI !== 'cli' ) {
9
-	exit( 'CLI only!' );
8
+if (PHP_SAPI !== 'cli') {
9
+	exit('CLI only!');
10 10
 }
11 11
 
12 12
 /** MAIN PARAMS */
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 	'config-title:'
28 28
 ];
29 29
 
30
-$vals = getopt( '', $params );
31
-if ( count( $vals ) !== count( $params ) ) {
32
-	exit( 'Not enough params!' );
30
+$vals = getopt('', $params);
31
+if (count($vals) !== count($params)) {
32
+	exit('Not enough params!');
33 33
 }
34 34
 
35 35
 /* PASSWORD */
@@ -42,38 +42,38 @@  discard block
 block discarded – undo
42 42
  * --use-password-file
43 43
  * which will look for a $PWFILE file in the current directory containing only the plain password
44 44
  */
45
-$pwParams = getopt( '', [
45
+$pwParams = getopt('', [
46 46
 	'password:',
47 47
 	'use-password-file'
48
-] );
48
+]);
49 49
 
50
-if ( isset( $pwParams[ 'password' ] ) ) {
51
-	$pw = $pwParams[ 'password' ];
52
-} elseif ( isset( $pwParams[ 'use-password-file' ] ) ) {
53
-	if ( file_exists( $PWFILE ) ) {
54
-		$pw = trim( file_get_contents( $PWFILE ) );
50
+if (isset($pwParams['password'])) {
51
+	$pw = $pwParams['password'];
52
+} elseif (isset($pwParams['use-password-file'])) {
53
+	if (file_exists($PWFILE)) {
54
+		$pw = trim(file_get_contents($PWFILE));
55 55
 	} else {
56
-		exit( 'Please create a password.txt file to use with use-password-file' );
56
+		exit('Please create a password.txt file to use with use-password-file');
57 57
 	}
58 58
 } else {
59
-	exit( 'Please provide a password or use a password file' );
59
+	exit('Please provide a password or use a password file');
60 60
 }
61 61
 
62
-$vals[ 'password' ] = $pw;
62
+$vals['password'] = $pw;
63 63
 
64 64
 /* START */
65 65
 
66
-Config::init( $vals );
66
+Config::init($vals);
67 67
 
68 68
 $bot = new Bot();
69 69
 
70 70
 /*
71 71
  * E.g. --task=update-list
72 72
  */
73
-$taskOpts = getopt( '', [ 'task:' ] );
73
+$taskOpts = getopt('', ['task:']);
74 74
 
75
-if ( $taskOpts ) {
76
-	$bot->runSingle( $taskOpts[ 'task' ] );
75
+if ($taskOpts) {
76
+	$bot->runSingle($taskOpts['task']);
77 77
 } else {
78 78
 	$bot->run();
79 79
 }
Please login to merge, or discard this patch.