Completed
Push — master ( 0fe941...5a01f4 )
by Avtandil
02:44
created

helpers.php ➔ get_db_query()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 4
nop 0
dl 0
loc 24
ccs 0
cts 11
cp 0
crap 20
rs 8.6845
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
        try {
34
            $collector = $debugbar->getCollector('queries');
35
        } catch (Exception $e) {
36
            return null;
37
        }
38
39
        $queries = $collector->collect();
40
        if (empty($queries['statements'])) {
41
            return null;
42
        }
43
44
        $query = end($queries['statements']);
45
46
        return $query['sql'];
47
    }
48
}
49
50
if (! function_exists('get_db_queries')) {
51
    function get_db_queries(): ?array
52
    {
53
        if (! app()->bound('debugbar')) {
54
            return null;
55
        }
56
        /** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */
57
        $debugbar = app('debugbar');
58
59
        try {
60
            $collector = $debugbar->getCollector('queries');
61
        } catch (Exception $e) {
62
            return null;
63
        }
64
65
        $queries = $collector->collect();
66
        if (empty($queries['statements'])) {
67
            return null;
68
        }
69
70
        $list = [];
71
        foreach ($queries['statements'] as $query) {
72
            $list[] = $query['sql'];
73
        }
74
75
        return $list;
76
    }
77
}
78