Completed
Push — master ( 33f5e0...a59007 )
by Avtandil
03:17
created

helpers.php ➔ get_db_query()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Laravel Lodash package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
declare(strict_types=1);
11
12
if (! function_exists('p')) {
13
    function p(...$values): void
14
    {
15
        /** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */
16
        $debugbar = app('debugbar');
17
        foreach ($values as $value) {
18
            $debugbar->addMessage($value, 'debug');
19
        }
20
    }
21
}
22
23
if (! function_exists('get_db_query')) {
24
    function get_db_query(): ?string
25
    {
26
        if (! app()->bound('debugbar')) {
27
            return null;
28
        }
29
30
        /** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */
31
        $debugbar = app('debugbar');
32
33
        $queries = $debugbar->getCollector('queries')->collect();
34
        if (empty($queries['statements'])) {
35
            return null;
36
        }
37
38
        $query = end($queries['statements']);
39
40
        return $query['sql'];
41
    }
42
}
43
44
if (! function_exists('get_db_queries')) {
45
    function get_db_queries(): ?array
46
    {
47
        if (! app()->bound('debugbar')) {
48
            return null;
49
        }
50
        /** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */
51
        $debugbar = app('debugbar');
52
53
        try {
54
            $collector = $debugbar->getCollector('queries');
55
        } catch (DebugBarException $e) {
0 ignored issues
show
Bug introduced by
The class DebugBarException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
56
            return null;
57
        }
58
59
        $queries = $collector->collect();
60
        if (empty($queries['statements'])) {
61
            return null;
62
        }
63
64
        $list = [];
65
        foreach ($queries['statements'] as $query) {
66
            $list[] = $query['sql'];
67
        }
68
69
        return $list;
70
    }
71
}
72