Completed
Push — 3.x-builder-quoter ( 067851 )
by Paul
02:03
created

AbstractBuilder::indentCsv()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
namespace Aura\SqlQuery;
3
4
use Aura\SqlQuery\Exception;
5
6
abstract class AbstractBuilder
7
{
8 408
    public function __construct($quoter)
9
    {
10 408
        $this->quoter = $quoter;
0 ignored issues
show
Bug introduced by
The property quoter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
11 408
    }
12
13
    /**
14
     *
15
     * Builds the flags as a space-separated string.
16
     *
17
     * @return string
18
     *
19
     */
20 253
    public function buildFlags($flags)
21
    {
22 253
        if (empty($flags)) {
23 215
            return ''; // not applicable
24
        }
25
26 38
        return ' ' . implode(' ', array_keys($flags));
27
    }
28
29
    /**
30
     *
31
     * Builds the `WHERE` clause of the statement.
32
     *
33
     * @return string
34
     *
35
     */
36 211
    public function buildWhere($where)
37
    {
38 211
        if (empty($where)) {
39 156
            return ''; // not applicable
40
        }
41
42 60
        return PHP_EOL . 'WHERE' . $this->indent($where);
43
    }
44
45
    /**
46
     *
47
     * Builds the `ORDER BY ...` clause of the statement.
48
     *
49
     * @return string
50
     *
51
     */
52 211
    public function buildOrderBy($order_by)
53
    {
54 211
        if (empty($order_by)) {
55 202
            return ''; // not applicable
56
        }
57
58 9
        return PHP_EOL . 'ORDER BY' . $this->indentCsv($order_by);
59
    }
60
61
    /**
62
     *
63
     * Builds the `LIMIT` clause of the statement.
64
     *
65
     * @return string
66
     *
67
     */
68 9
    public function buildLimit($limit)
69
    {
70 9
        if (empty($limit)) {
71 5
            return '';
72
        }
73 4
        return PHP_EOL . "LIMIT {$limit}";
74
    }
75
76
    /**
77
     *
78
     * Builds the `LIMIT ... OFFSET` clause of the statement.
79
     *
80
     * @return string
81
     *
82
     */
83 159
    public function buildLimitOffset($limit, $offset)
84
    {
85 159
        $clause = '';
86
87 159
        if (!empty($limit)) {
88 15
            $clause .= "LIMIT {$limit}";
89 15
        }
90
91 159
        if (!empty($offset)) {
92 10
            $clause .= " OFFSET {$offset}";
93 10
        }
94
95 159
        if (!empty($clause)) {
96 15
            $clause = PHP_EOL . trim($clause);
97 15
        }
98
99 159
        return $clause;
100
    }
101
102
    /**
103
     *
104
     * Returns an array as an indented comma-separated values string.
105
     *
106
     * @param array $list The values to convert.
107
     *
108
     * @return string
109
     *
110
     */
111 225
    public function indentCsv(array $list)
112
    {
113 225
        return PHP_EOL . '    '
114 225
             . implode(',' . PHP_EOL . '    ', $list);
115
    }
116
117
    /**
118
     *
119
     * Returns an array as an indented string.
120
     *
121
     * @param array $list The values to convert.
122
     *
123
     * @return string
124
     *
125
     */
126 71
    public function indent(array $list)
127
    {
128 71
        return PHP_EOL . '    '
129 71
             . implode(PHP_EOL . '    ', $list);
130
    }
131
}
132