Log::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

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