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

LogCall   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 39
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getLevel() 0 2 1
A getMessage() 0 2 1
A getContext() 0 2 1
A withoutContext() 0 2 1
A __construct() 0 4 1
A isError() 0 2 1
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