Passed
Push — master ( b953c9...de8e3d )
by Ron
02:53
created

ClosureQueryLogger::logError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 3
1
<?php
2
namespace Kir\MySQL\QueryLogger;
3
4
use Throwable;
5
6
class ClosureQueryLogger implements QueryLogger {
7
	/** @var callable(string, float, string, Throwable|null): void */
8
	private $fn;
9
10
	/**
11
	 * @param callable(string, float, string, Throwable|null): void $fn
12
	 */
13
	public function __construct(callable $fn) {
14
		$this->fn = $fn;
15
	}
16
17
	/**
18
	 * @inheritDoc
19
	 */
20
	public function log(string $query, float $duration): void {
21
		call_user_func($this->fn, $query, $duration, 'INFO', null);
22
	}
23
24
	/**
25
	 * @inheritDoc
26
	 */
27
	public function logError(string $query, Throwable $exception, float $duration): void {
28
		call_user_func($this->fn, $query, $duration, 'ERROR', $exception);
29
	}
30
}
31