Passed
Pull Request — master (#12)
by Gabriel
11:49
created

LogCall::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\PsrLogTestDoubles;
6
7
use Psr\Log\LogLevel;
8
9
/**
10
 * Value object representing a call to the logger
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class LogCall {
16
17
	private const ERROR_LEVELS = [ LogLevel::ERROR, LogLevel::CRITICAL, LogLevel::ALERT, LogLevel::EMERGENCY ];
18
19
	private mixed $level;
20
	private string $message;
21
	private array $context;
22
23
	public function __construct( mixed $level, string $message, array $context = [] ) {
24 4
		$this->level = $level;
25 4
		$this->message = $message;
26 4
		$this->context = $context;
27 4
	}
28 4
29
	public function getLevel(): mixed {
30
		return $this->level;
31
	}
32
33 1
	public function getMessage(): string {
34 1
		return $this->message;
35
	}
36
37 2
	public function getContext(): array {
38 2
		return $this->context;
39
	}
40
41 1
	/**
42 1
	 * Returns if the log level is error or above.
43
	 * @since 3.2
44
	 */
45
	public function isError(): bool {
46
		return in_array( $this->level, self::ERROR_LEVELS );
47
	}
48
49
	/**
50
	 * @since 3.2
51
	 */
52
	public function withoutContext(): self {
53
		return new self( $this->level, $this->message, [] );
54
	}
55
56
}
57