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

ClosureQueryLogger   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 23
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A log() 0 2 1
A __construct() 0 2 1
A logError() 0 2 1
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