DialectAwareTrait::setDialect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Query
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\Query\Traits;
16
17
use Phossa2\Query\Dialect\Mysql;
18
use Phossa2\Query\Interfaces\DialectInterface;
19
use Phossa2\Query\Interfaces\DialectAwareInterface;
20
21
/**
22
 * DialectAwareTrait
23
 *
24
 * Implementation of DialectAwareInterface
25
 *
26
 * @package Phossa2\Query
27
 * @author  Hong Zhang <[email protected]>
28
 * @see     DialectAwareInterface
29
 * @version 2.0.0
30
 * @since   2.0.0 added
31
 */
32
trait DialectAwareTrait
33
{
34
    /**
35
     * dialect
36
     *
37
     * @var    DialectInterface
38
     * @access protected
39
     */
40
    protected $dialect;
41
42
    /**
43
     * {@inheritDoc}
44
     */
45
    public function setDialect(DialectInterface $dialect = null)
46
    {
47
        $this->dialect = $dialect;
48
        return $this;
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function hasDialect()/*# : bool */
55
    {
56
        return null !== $this->dialect;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function getDialect()/*# : DialectInterface */
63
    {
64
        if (!$this->hasDialect()) {
65
            $this->dialect = new Mysql();
66
        }
67
        return $this->dialect;
68
    }
69
}
70