Passed
Branch master (5c167b)
by smiley
02:26
created

LogOutputAbstract   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 27.27%

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 24
ccs 3
cts 11
cp 0.2727
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A close() 0 2 1
A __destruct() 0 2 1
B log() 0 3 5
1
<?php
2
/**
3
 * Class LogOutputAbstract
4
 *
5
 * @filesource   LogOutputAbstract.php
6
 * @created      04.01.2018
7
 * @package      chillerlan\Logger\Output
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2018 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Logger\Output;
14
15
use chillerlan\Logger\LogOptions;
16
17
/**
18
 *
19
 */
20
abstract class LogOutputAbstract implements LogOutputInterface{
21
22
	/**
23
	 * @var \chillerlan\Logger\LogOptions
24
	 */
25
	protected $options;
26
27 1
	public function __construct(LogOptions $options = null){
28 1
		$this->options = $options ?? new LogOptions;
29 1
	}
30
31
	public function __destruct(){
32
		$this->close();
33
	}
34
35
	public function close():LogOutputInterface{
36
		return $this;
37
	}
38
39
	abstract protected function __log(string $level, string $message, array $context = null);
40
41
	public function log(string $level, string $message, array $context = null){ // @todo: loglevel bitmask
42
		if((array_key_exists($level, $this::LEVELS) && $this::LEVELS[$level] >= $this::LEVELS[$this->options->minLogLevel]) || (!array_key_exists($level, $this::LEVELS) && !empty($level))){
43
			$this->__log($level, $message, $context);
44
		}
45
	}
46
47
}
48