Passed
Push — master ( 35639c...18326f )
by Daimona
01:42
created

Bot   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 9 2
A __construct() 0 2 1
A runSubtask() 0 9 2
A runTask() 0 9 2
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
	 * Entry point for the whole process
20
	 */
21
	public function run() {
22
		$this->logger->info( 'Starting full process.' );
23
		$manager = new TaskManager;
24
		$res = $manager->run( TaskManager::MODE_COMPLETE );
25
		$line = '---------------------------------------------------';
26
		if ( $res->isOK() ) {
27
			$this->logger->info( "Execution completed successfully.\n$line\n\n" );
28
		} else {
29
			$this->logger->error( "Execution failed.\n$res\n$line\n\n" );
30
		}
31
	}
32
33
	/**
34
	 * Run a single task
35
	 *
36
	 * @param string $task
37
	 */
38
	public function runTask( string $task ) {
39
		$this->logger->info( "Starting single task $task." );
40
		$manager = new TaskManager;
41
		$res = $manager->run( TaskManager::MODE_TASK, $task );
42
		$line = '---------------------------------------------------';
43
		if ( $res->isOK() ) {
44
			$this->logger->info( "Execution of task $task completed successfully.\n$line\n\n" );
45
		} else {
46
			$this->logger->error( "Execution of task $task failed.\n$res\n$line\n\n" );
47
		}
48
	}
49
50
	/**
51
	 * Run a single subtask, e.g. for debugging purposes
52
	 *
53
	 * @param string $subtask
54
	 */
55
	public function runSubtask( string $subtask ) {
56
		$this->logger->info( "Starting single subtask $subtask." );
57
		$manager = new TaskManager;
58
		$res = $manager->run( TaskManager::MODE_SUBTASK, $subtask );
59
		$line = '---------------------------------------------------';
60
		if ( $res->isOK() ) {
61
			$this->logger->info( "Execution of subtask $subtask completed successfully.\n$line\n\n" );
62
		} else {
63
			$this->logger->error( "Execution of subtask $subtask failed.\n$res\n$line\n\n" );
64
		}
65
	}
66
}
67