ProfilerAwareTrait::getProfiler()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Db
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Db\Traits;
16
17
use Phossa2\Db\Profiler;
18
use Phossa2\Db\Interfaces\ProfilerInterface;
19
use Phossa2\Db\Interfaces\ProfilerAwareInterface;
20
21
/**
22
 * ProfilerAwareTrait
23
 *
24
 * @package Phossa2\Db
25
 * @author  Hong Zhang <[email protected]>
26
 * @see     ProfilerAwareInterface
27
 * @version 2.0.0
28
 * @since   2.0.0 added
29
 */
30
trait ProfilerAwareTrait
31
{
32
    /**
33
     * the profiler
34
     *
35
     * @var    ProfilerInterface
36
     * @access protected
37
     */
38
    protected $profiler;
39
40
    /**
41
     * @var    bool
42
     * @access protected
43
     */
44
    protected $profiling_enabled = false;
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function isProfiling()/*# : bool */
50
    {
51
        return $this->profiling_enabled;
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    public function enableProfiling(/*# bool */ $flag = true)
58
    {
59
        $this->profiling_enabled = (bool) $flag;
60
        return $this;
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66
    public function setProfiler(ProfilerInterface $profiler)
67
    {
68
        $this->profiler = $profiler;
69
        $this->profiler->setDriver($this);
70
        return $this;
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    public function getProfiler()/*# : ProfilerInterface */
77
    {
78
        if (is_null($this->profiler)) {
79
            $this->setProfiler(new Profiler());
80
        }
81
        return $this->profiler;
82
    }
83
}
84