Command::log()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Genesis\Commands;
4
5
6
use Genesis\Cli;
7
use Genesis\ErrorException;
8
9
10
/**
11
 * @author Adam Bisek <[email protected]>
12
 */
13
abstract class Command
14
{
15
16
	const SUCCESS = 'success';
17
18
	const ERROR = 'error';
19
20
	private static $severityColors = [
21
		self::SUCCESS => 'green',
22
		self::ERROR => 'red',
23
	];
24
25
26
	/**
27
	 * Trigger an error and ends execution (if not catched)
28
	 * @param $message
29
	 * @throws ErrorException
30
	 */
31 5
	protected function error($message)
32
	{
33 5
		throw new ErrorException($message);
34
	}
35
36
37 9
	protected function log($message, $severity = NULL)
38
	{
39 9
		$color = isset(self::$severityColors[$severity]) ? self::$severityColors[$severity] : NULL;
40 9
		echo Cli::getColoredString($message . PHP_EOL, $color);
41 9
	}
42
43
}