AdapterPlugin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 42
ccs 20
cts 20
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A afterQuery() 0 4 1
A beforeQuery() 0 20 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