Completed
Push — master ( 35f8c9...391757 )
by Hong
02:18
created

DriverAwareTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDriver() 0 5 1
A hasDriver() 0 4 1
A getDriver() 0 10 2
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\Message\Message;
18
use Phossa2\Db\Exception\LogicException;
19
use Phossa2\Db\Interfaces\DriverInterface;
20
use Phossa2\Db\Interfaces\DriverAwareInterface;
21
22
/**
23
 * DriverAwareTrait
24
 *
25
 * @package Phossa2\Db
26
 * @author  Hong Zhang <[email protected]>
27
 * @see     DriverAwareInterface
28
 * @version 2.0.0
29
 * @since   2.0.0 added
30
 */
31
trait DriverAwareTrait
32
{
33
    /**
34
     * the driver
35
     *
36
     * @var    DriverInterface
37
     * @access protected
38
     */
39
    protected $driver;
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function setDriver(DriverInterface $driver)
45
    {
46
        $this->driver = $driver;
47
        return $this;
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53
    public function hasDriver()/*# : bool */
54
    {
55
        return null !== $this->driver;
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61
    public function getDriver()/*# : DriverInterface */
62
    {
63
        if (null === $this->driver) {
64
            throw new LogicException(
65
                Message::get(Message::DB_DRIVER_NOTSET),
66
                Message::DB_DRIVER_NOTSET
67
            );
68
        }
69
        return $this->driver;
70
    }
71
}
72