Completed
Push — master ( 22d0de...5ae499 )
by smiley
01:45
created

LogOutputAbstract::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 3
crap 2
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
use chillerlan\Traits\ContainerInterface;
17
18
/**
19
 *
20
 */
21
abstract class LogOutputAbstract implements LogOutputInterface{
22
23
	/**
24
	 * @var \chillerlan\Logger\LogOptions
25
	 */
26
	protected $options;
27 1
28 1
	/**
29 1
	 * LogOutputAbstract constructor.
30
	 *
31
	 * @param \chillerlan\Traits\ContainerInterface|null $options
32
	 */
33
	public function __construct(ContainerInterface $options = null){
34
		$this->options = $options ?? new LogOptions;
35
	}
36
37
	/**
38
	 * @inheritdoc
39
	 */
40
	public function __destruct(){
41
		$this->close();
42
	}
43
44
	/**
45
	 * @inheritdoc
46
	 */
47
	public function close():LogOutputInterface{
48
		return $this;
49
	}
50
51
	/**
52
	 * @param string $level
53
	 * @param string $message
54
	 * @param array  $context
55
	 *
56
	 * @return mixed
57
	 */
58
	abstract protected function __log(string $level, string $message, array $context = []);
59
60
	/**
61
	 * @inheritdoc
62
	 */
63
	public function log(string $level, string $message, array $context = []){ // @todo: loglevel bitmask
64
		if((array_key_exists($level, $this::LEVELS) && $this::LEVELS[$level] >= $this::LEVELS[$this->options->minLogLevel]) || (!array_key_exists($level, $this::LEVELS) && !empty($level))){
65
			$this->__log($level, $message, $context);
66
		}
67
	}
68
69
	/**
70
	 * @param string     $level
71
	 * @param string     $message
72
	 * @param array|null $context
73
	 *
74
	 * @return string
75
	 */
76
	protected function message(string $level, string $message, array $context = null){
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

76
	protected function message(string $level, string $message, /** @scrutinizer ignore-unused */ array $context = null){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
		return sprintf($this->options->consoleFormat, date($this->options->consoleDateFormat), $level, $message).PHP_EOL;
78
	}
79
80
}
81