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

Log::log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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