Passed
Push — master ( 1a47f4...ba2710 )
by Daimona
01:58
created

Bot::runAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme;
4
5
/**
6
 * Higher-level class. It only wraps tasks executions, and contains generic data
7
 */
8
class Bot {
9
	/** @var Logger */
10
	private $logger;
11
12
	const VERSION = 1.0;
13
14
	public function __construct() {
15
		$this->logger = new Logger;
16
	}
17
18
	/**
19
	 * Internal call to TaskManager
20
	 *
21
	 * @param string $mode
22
	 * @param string|null $name
23
	 */
24
	private function run( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) {
25
		$activity = $mode === TaskManager::MODE_COMPLETE ? TaskManager::MODE_COMPLETE : "$mode $name";
26
		$this->logger->info( "Starting $activity" );
27
		$manager = new TaskManager;
28
		$res = $manager->run( $mode, $name );
29
		$line = '---------------------------------------------------';
30
		if ( $res->isOK() ) {
31
			$this->logger->info( "Execution of $activity completed successfully.\n$line\n\n" );
32
		} else {
33
			$this->logger->error( "Execution of $activity failed.\n$res\n$line\n\n" );
34
		}
35
	}
36
37
	/**
38
	 * Entry point for the whole process
39
	 */
40
	public function runAll() {
41
		$this->run();
42
	}
43
44
	/**
45
	 * Run a single task
46
	 *
47
	 * @param string $task
48
	 */
49
	public function runTask( string $task ) {
50
		$this->run( TaskManager::MODE_TASK, $task );
51
	}
52
53
	/**
54
	 * Run a single subtask, e.g. for debugging purposes
55
	 *
56
	 * @param string $subtask
57
	 */
58
	public function runSubtask( string $subtask ) {
59
		$this->run( TaskManager::MODE_SUBTASK, $subtask );
60
	}
61
}
62