Debugbar   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 4
eloc 10
c 2
b 1
f 1
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A output() 0 7 2
A boot() 0 6 2
1
<?php
2
3
namespace BeyondCode\QueryDetector\Outputs;
4
5
use Illuminate\Support\Collection;
6
use Symfony\Component\HttpFoundation\Response;
7
8
use Barryvdh\Debugbar\Facade as LaravelDebugbar;
0 ignored issues
show
Bug introduced by
The type Barryvdh\Debugbar\Facade was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use DebugBar\DataCollector\MessagesCollector;
0 ignored issues
show
Bug introduced by
The type DebugBar\DataCollector\MessagesCollector was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class Debugbar implements Output
12
{
13
    protected $collector;
14
15
    public function boot()
16
    {
17
        $this->collector = new MessagesCollector('N+1 Queries');
18
        
19
        if (!LaravelDebugbar::hasCollector($this->collector->getName())) {
20
            LaravelDebugbar::addCollector($this->collector);
21
        }
22
    }
23
24
    public function output(Collection $detectedQueries, Response $response)
25
    {
26
        foreach ($detectedQueries as $detectedQuery) {
27
            $this->collector->addMessage(sprintf('Model: %s => Relation: %s - You should add `with(%s)` to eager-load this relation.',
28
                $detectedQuery['model'],
29
                $detectedQuery['relation'],
30
                $detectedQuery['relation']
31
            ));
32
        }
33
    }
34
}
35