TraceLogger::startQuery()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Brouzie\Sphinxy\Logging;
4
5
/**
6
 * Logger that store backtraces.
7
 *
8
 * @author Konstantin Myakshin <[email protected]>
9
 */
10
class TraceLogger extends DebugStack
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function startQuery($sql, array $params = null)
16
    {
17
        $backtrace = $this->getBactrace();
18
19
        $this->start = microtime(true);
20
        $this->queries[++$this->currentQuery] = array(
21
            'sql' => $sql,
22
            'params' => $params,
23
            'executionMS' => 0,
24
            'stacktrace' => $backtrace,
25
        );
26
    }
27
28
    private function getBactrace()
29
    {
30
        //TODO: format args using ValueExporter() class
31
        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
32
33
        foreach ($backtrace as $key => $debug) {
34
            if (!isset($debug['class'])) {
35
                continue;
36
            }
37
38
            if (!$this->isInternalClass($debug['class'])) {
39
                return array_slice($backtrace, $key - 1, 10);
40
            }
41
        }
42
43
        return array();
44
    }
45
46
    private function isInternalClass($class)
47
    {
48
        return strpos($class, 'Brouzie\\Sphinxy') === 0 || strpos($class, 'Brouzie\\Bundle\\SphinxyBundle') === 0;
49
    }
50
}
51