MySqlBuilder::writeColumnName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
c 1
b 0
f 0
rs 9.4286
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 6/3/14
5
 * Time: 12:07 AM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Sql\QueryBuilder\Builder;
12
13
use NilPortugues\Sql\QueryBuilder\Syntax\Column;
14
use NilPortugues\Sql\QueryBuilder\Syntax\Table;
15
16
/**
17
 * Class MySqlBuilder.
18
 */
19
class MySqlBuilder extends GenericBuilder
20
{
21
    /**
22
     * {@inheritdoc}
23
     *
24
     * @param Column $column
25
     *
26
     * @return string
27
     */
28
    public function writeColumnName(Column $column)
29
    {
30
        if ($column->isAll()) {
31
            return '*';
32
        }
33
34
        if (false !== strpos($column->getName(), "(")) {
35
            return parent::writeColumnName($column);
36
        }
37
38
        return $this->wrapper(parent::writeColumnName($column));
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     *
44
     * @param Table $table
45
     *
46
     * @return string
47
     */
48
    public function writeTableName(Table $table)
49
    {
50
        return $this->wrapper(parent::writeTableName($table));
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     *
56
     * @param $alias
57
     *
58
     * @return string
59
     */
60
    public function writeTableAlias($alias)
61
    {
62
        return $this->wrapper(parent::writeTableAlias($alias));
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     *
68
     * @param $alias
69
     *
70
     * @return string
71
     */
72
    public function writeColumnAlias($alias)
73
    {
74
        return $this->wrapper($alias);
75
    }
76
77
    /**
78
     * @param        $string
79
     * @param string $char
80
     *
81
     * @return string
82
     */
83
    protected function wrapper($string, $char = '`')
84
    {
85
        if (0 === strlen($string)) {
86
            return '';
87
        }
88
89
        return $char.$string.$char;
90
    }
91
}
92