QueryProfile::setAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Nip\Database\Adapters\Profiler;
4
5
use Nip\Profiler\Profile;
6
7
/**
8
 * Class QueryProfile
9
 * @package Nip\Database\Adapters\Profiler
10
 */
11
class QueryProfile extends Profile
12
{
13
    public $query;
14
    public $type;
15
    public $adapter;
16
17
    public $info;
18
    public $affectedRows;
19
    public $columns = ['time', 'type', 'memory', 'query', 'affectedRows', 'info'];
20
21
    /**
22
     * @param null $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
23
     */
24
    public function setName($name)
25
    {
26
        $this->query = $name;
27
        $this->type = $this->detectQueryType();
28
29
        parent::setName($name);
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function detectQueryType()
36
    {
37
        // make sure we have a query type
38
        switch (strtolower(substr($this->query, 0, 6))) {
39
            case 'insert':
40
                return 'INSERT';
41
42
            case 'update':
43
                return 'UPDATE';
44
45
            case 'delete':
46
                return 'DELETE';
47
48
            case 'select':
49
                return 'SELECT';
50
51
            default:
52
                return 'QUERY';
53
        }
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    public function getQuery()
60
    {
61
        return $this->query;
62
    }
63
64
    /**
65
     * @return mixed
66
     */
67
    public function getConnection()
68
    {
69
        return $this->query;
70
    }
71
72
    public function calculateResources()
73
    {
74
        parent::calculateResources();
75
        $this->getInfo();
76
    }
77
78
    public function getInfo()
79
    {
80
        $this->info = $this->getAdapter()->info();
81
        $this->affectedRows = $this->getAdapter()->affectedRows();
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87
    public function getAdapter()
88
    {
89
        return $this->adapter;
90
    }
91
92
    /**
93
     * @param mixed $adapter
94
     */
95
    public function setAdapter($adapter)
96
    {
97
        $this->adapter = $adapter;
98
    }
99
}
100