| 1 | <?php |
||
| 2 | |||
| 3 | namespace Kir\MySQL\QueryLogger; |
||
| 4 | |||
| 5 | use Throwable; |
||
| 6 | |||
| 7 | class QueryLoggers { |
||
| 8 | /** @var QueryLogger[] */ |
||
| 9 | private array $queryLoggers = []; |
||
| 10 | |||
| 11 | public function add(QueryLogger $queryLogger): void { |
||
| 12 | $this->queryLoggers[] = $queryLogger; |
||
| 13 | } |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @template T |
||
| 17 | * @param string $query |
||
| 18 | * @param callable(): T $fn |
||
| 19 | * @return T |
||
|
0 ignored issues
–
show
|
|||
| 20 | */ |
||
| 21 | public function logRegion(string $query, $fn) { |
||
| 22 | $exception = null; |
||
| 23 | $timer = microtime(true); |
||
| 24 | try { |
||
| 25 | return $fn(); |
||
| 26 | } catch(Throwable $e) { |
||
| 27 | $exception = $e; |
||
| 28 | throw $e; |
||
| 29 | } finally { |
||
| 30 | $finalTimer = microtime(true) - $timer; |
||
| 31 | if($exception === null) { |
||
| 32 | $this->log($query, $finalTimer); |
||
| 33 | } else { |
||
| 34 | $this->logError($query, $exception, $finalTimer); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param string $query |
||
| 41 | * @param float $duration |
||
| 42 | */ |
||
| 43 | public function log(string $query, float $duration): void { |
||
| 44 | foreach($this->queryLoggers as $queryLogger) { |
||
| 45 | try { |
||
| 46 | $queryLogger->log($query, $duration); |
||
| 47 | } catch(Throwable) { |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
| 48 | } |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param string $query |
||
| 54 | * @param Throwable $exception |
||
| 55 | * @param float $duration |
||
| 56 | */ |
||
| 57 | public function logError(string $query, Throwable $exception, float $duration): void { |
||
| 58 | foreach($this->queryLoggers as $queryLogger) { |
||
| 59 | try { |
||
| 60 | $queryLogger->logError($query, $exception, $duration); |
||
| 61 | } catch(Throwable) { |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths