TraceLogger   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 41
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A startQuery() 0 12 1
A getBactrace() 0 17 4
A isInternalClass() 0 4 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