AdapterPlugin::beforeQuery()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 20
ccs 17
cts 17
cp 1
rs 9.2
cc 4
eloc 13
nc 8
nop 2
crap 4
1
<?php
2
/**
3
 * @author @fabfuel <[email protected]>
4
 * @created 14.11.14, 08:39
5
 */
6
namespace Fabfuel\Prophiler\Plugin\Phalcon\Db;
7
8
use Fabfuel\Prophiler\Benchmark\BenchmarkInterface;
9
use Fabfuel\Prophiler\Plugin\PluginAbstract;
10
use Phalcon\Events\Event;
11
use Phalcon\Db\Adapter;
12
13
/**
14
 * Class AdapterPlugin
15
 */
16
class AdapterPlugin extends PluginAbstract
17
{
18
    /**
19
     * @var BenchmarkInterface
20
     */
21
    private $benchmark;
22
23
    /**
24
     * Start the query benchmark
25
     *
26
     * @param Event $event
27
     * @param Adapter $database
28
     */
29 1
    public function beforeQuery(Event $event, Adapter $database)
30
    {
31
        $metadata = [
32 1
            'query' => $database->getSQLStatement()
33 1
        ];
34 1
        $params = $database->getSQLVariables();
35 1
        if (isset($params)) {
36 1
            $metadata['params'] = $params;
37 1
        }
38 1
        $bindtypes = $database->getSQLBindTypes();
39 1
        if (isset($bindtypes)) {
40 1
            $metadata['bindTypes'] = $bindtypes;
41 1
        }
42 1
        $desc = $database->getDescriptor();
43 1
        if (isset($desc['dbname'])) {
44 1
            $metadata['database'] = $desc['dbname'];
45 1
        }
46
47 1
        $this->benchmark = $this->getProfiler()->start(get_class($event->getSource()) . '::query', $metadata, 'Database');
48 1
    }
49
50
    /**
51
     * Stop the query benchmark
52
     */
53 1
    public function afterQuery()
54
    {
55 1
        $this->getProfiler()->stop($this->benchmark);
56 1
    }
57
}
58