Passed
Push — master ( 99bd59...4a3a0c )
by Marcel
143:46 queued 125:05
created

Log   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 4
b 0
f 0
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 2 1
A log() 0 3 1
A output() 0 18 3
1
<?php
2
3
namespace BeyondCode\QueryDetector\Outputs;
4
5
use Illuminate\Support\Facades\Log as LaravelLog;
6
use Illuminate\Support\Collection;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class Log implements Output
10
{
11
    public function boot()
12
    {
13
        //
14
    }
15
16
    public function output(Collection $detectedQueries, Response $response)
17
    {
18
        $this->log('Detected N+1 Query');
19
20
        foreach ($detectedQueries as $detectedQuery) {
21
            $logOutput = 'Model: '.$detectedQuery['model'] . PHP_EOL;
22
23
            $logOutput .= 'Relation: '.$detectedQuery['relation'] . PHP_EOL;
24
25
            $logOutput .= 'Num-Called: '.$detectedQuery['count'] . PHP_EOL;
26
27
            $logOutput .= 'Call-Stack:' . PHP_EOL;
28
29
            foreach ($detectedQuery['sources'] as $source) {
30
                $logOutput .= '#'.$source->index.' '.$source->name.':'.$source->line . PHP_EOL;
31
            }
32
33
            $this->log($logOutput);
34
        }
35
    }
36
37
    private function log(string $message)
38
    {
39
        LaravelLog::channel(config('querydetector.log_channel'))->info($message);
40
    }
41
}
42