ClosureQueryLogger   A
last analyzed

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
3
namespace Kir\MySQL\QueryLogger;
4
5
use Throwable;
6
7
class ClosureQueryLogger implements QueryLogger {
8
	/** @var callable(string, float, string, Throwable|null): void */
9
	private $fn;
10
11
	/**
12
	 * @param callable(string, float, string, Throwable|null):void $fn
13
	 */
14
	public function __construct(callable $fn) {
15
		$this->fn = $fn;
16
	}
17
18
	/**
19
	 * @inheritDoc
20
	 */
21
	public function log(string $query, float $duration): void {
22
		call_user_func($this->fn, $query, $duration, 'INFO', null);
23
	}
24
25
	/**
26
	 * @inheritDoc
27
	 */
28
	public function logError(string $query, Throwable $exception, float $duration): void {
29
		call_user_func($this->fn, $query, $duration, 'ERROR', $exception);
30
	}
31
}
32