Passed
Push — master ( f946ea...c739e9 )
by Daimona
02:07
created

LoggerTrait::getFormattedMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 2
rs 10
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme\Logger;
4
5
use Psr\Log\LogLevel;
6
7
trait LoggerTrait {
8
	/**
9
	 * Translate a LogLevel constant to an integer
10
	 *
11
	 * @param string $level
12
	 * @return int
13
	 */
14
	protected function levelToInt( string $level ) : int {
15
		// Order matters
16
		$mapping = [
17
			LogLevel::DEBUG,
18
			LogLevel::INFO,
19
			LogLevel::NOTICE,
20
			LogLevel::WARNING,
21
			LogLevel::ERROR,
22
			LogLevel::CRITICAL,
23
			LogLevel::ALERT,
24
			LogLevel::EMERGENCY
25
		];
26
		return array_search( $level, $mapping );
1 ignored issue
show
Bug Best Practice introduced by
The expression return array_search($level, $mapping) could return the type false|string which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
27
	}
28
29
	/**
30
	 * @param string $level
31
	 * @param string $message
32
	 * @return string
33
	 */
34
	protected function getFormattedMessage( string $level, string $message ) {
35
		return sprintf( "%s [%s] - %s\n", date( 'd M H:i:s' ), $level, $message );
36
	}
37
}
38