Passed
Push — master ( aeb3c7...3e94dc )
by Daimona
01:51
created
includes/TaskManager.php 1 patch
Spacing   +25 added lines, -25 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
 
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 	/**
32 32
 	 * Should only be used for debugging purpose.
33 33
 	 */
34
-	public static function resetLastRunDate() {
35
-		file_put_contents( self::LOG_FILE, '' );
34
+	public static function resetLastRunDate () {
35
+		file_put_contents ( self::LOG_FILE, '' );
36 36
 	}
37 37
 
38 38
 	/**
@@ -42,24 +42,24 @@  discard block
 block discarded – undo
42 42
 	 * @param string|null $taskName Only used in MODE_SINGLE
43 43
 	 * @return TaskResult
44 44
 	 */
45
-	public function run( int $mode, string $taskName = null ) : TaskResult {
45
+	public function run ( int $mode, string $taskName = null ) : TaskResult {
46 46
 		$this->provider = new TaskDataProvider;
47 47
 		if ( $mode === self::MODE_COMPLETE ) {
48
-			return $this->runAllTasks();
48
+			return $this->runAllTasks ();
49 49
 		} elseif ( $taskName === null ) {
50
-			throw new \BadMethodCallException( 'A task name must be specified in MODE_SINGLE' );
50
+			throw new \BadMethodCallException ( 'A task name must be specified in MODE_SINGLE' );
51 51
 		} else {
52
-			return $this->runTask( $taskName );
52
+			return $this->runTask ( $taskName );
53 53
 		}
54 54
 	}
55 55
 
56 56
 	/**
57 57
 	 * @return TaskResult
58 58
 	 */
59
-	protected function runAllTasks() : TaskResult {
60
-		if ( self::getLastFullRunDate() === date( 'd/m/Y' ) ) {
59
+	protected function runAllTasks () : TaskResult {
60
+		if ( self::getLastFullRunDate () === date ( 'd/m/Y' ) ) {
61 61
 			// Really avoid executing twice the same day
62
-			return new TaskResult( TaskResult::STATUS_ERROR, [ 'A full run was already executed today.' ] );
62
+			return new TaskResult ( TaskResult::STATUS_ERROR, [ 'A full run was already executed today.' ] );
63 63
 		}
64 64
 
65 65
 		// Order matters here
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
 			'user-notice'
71 71
 		];
72 72
 
73
-		$res = new TaskResult( TaskResult::STATUS_OK );
73
+		$res = new TaskResult ( TaskResult::STATUS_OK );
74 74
 		do {
75
-			$res->merge( $this->runTask( current( $list ) ) );
76
-		} while ( $res->isOK() && next( $list ) );
75
+			$res->merge ( $this->runTask ( current ( $list ) ) );
76
+		} while ( $res->isOK () && next ( $list ) );
77 77
 
78
-		if ( $res->isOK() ) {
79
-			self::setLastFullRunDate();
78
+		if ( $res->isOK () ) {
79
+			self::setLastFullRunDate ();
80 80
 		}
81 81
 
82 82
 		return $res;
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 	 * Get the last execution date to ensure no more than one full run is executed every day
87 87
 	 * @return string|null d/m/Y or null if no last run registered
88 88
 	 */
89
-	public static function getLastFullRunDate() : ?string {
90
-		if ( file_exists( self::LOG_FILE ) ) {
91
-			return file_get_contents( self::LOG_FILE ) ?: null;
89
+	public static function getLastFullRunDate () : ?string {
90
+		if ( file_exists ( self::LOG_FILE ) ) {
91
+			return file_get_contents ( self::LOG_FILE ) ?: null;
92 92
 		} else {
93 93
 			return null;
94 94
 		}
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
 	 * @param string $task Defined in self::TASKS_MAP
99 99
 	 * @return TaskResult
100 100
 	 */
101
-	protected function runTask( string $task ) : TaskResult {
101
+	protected function runTask ( string $task ) : TaskResult {
102 102
 		if ( !isset( self::TASKS_MAP[ $task ] ) ) {
103
-			throw new \InvalidArgumentException( "'$task' is not a valid task." );
103
+			throw new \InvalidArgumentException ( "'$task' is not a valid task." );
104 104
 		}
105 105
 
106 106
 		$class = self::TASKS_MAP[ $task ];
107
-		return $this->getTaskInstance( $class )->run();
107
+		return $this->getTaskInstance ( $class )->run ();
108 108
 	}
109 109
 
110 110
 	/**
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
 	 * @param string $class
114 114
 	 * @return Task
115 115
 	 */
116
-	private function getTaskInstance( string $class ) : Task {
117
-		return new $class( $this->provider );
116
+	private function getTaskInstance ( string $class ) : Task {
117
+		return new $class ( $this->provider );
118 118
 	}
119 119
 
120
-	public static function setLastFullRunDate() {
121
-		file_put_contents( self::LOG_FILE, date( 'd/m/Y' ) );
120
+	public static function setLastFullRunDate () {
121
+		file_put_contents ( self::LOG_FILE, date ( 'd/m/Y' ) );
122 122
 	}
123 123
 }
Please login to merge, or discard this patch.