Completed
Push — master ( f745f1...d70d44 )
by Mahmoud
03:16
created

QueryDebuggerTask::run()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 24
rs 8.6845
cc 4
eloc 12
nc 2
nop 0
1
<?php
2
3
namespace App\Containers\Debugger\Tasks;
4
5
use App;
6
use DB;
7
use Illuminate\Support\Facades\Config;
8
use Log;
9
10
/**
11
 * Class QueryDebuggerTask.
12
 *
13
 * @author  Mahmoud Zalt <[email protected]>
14
 */
15
class QueryDebuggerTask
16
{
17
18
    /**
19
     * Write the DB queries in the Log and Display them in the
20
     * terminal (in case you want to see them while executing the tests).
21
     *
22
     * @param bool|false $terminal
0 ignored issues
show
Bug introduced by
There is no parameter named $terminal. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
23
     */
24
    public function run()
25
    {
26
        $debuggerEnabled = Config::get('debugger.queries.debug');
27
28
        if ($debuggerEnabled) {
29
30
            $consoleOutputEnabled = Config::get('debugger.queries.output.console');
31
            $logOutputEnabled = Config::get('debugger.queries.output.log');
32
33
            DB::listen(function ($event) use ($consoleOutputEnabled, $logOutputEnabled) {
34
                $fullQuery = vsprintf(str_replace(['%', '?'], ['%%', '%s'], $event->sql), $event->bindings);
35
36
                $result = $event->connectionName . ' (' . $event->time . '): ' . $fullQuery;
37
38
                if ($consoleOutputEnabled) {
39
                    dump($result);
40
                }
41
42
                if ($logOutputEnabled) {
43
                    Log::info($result);
44
                }
45
            });
46
        }
47
    }
48
49
}
50