Indent   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 196
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 19
c 1
b 1
f 1
lcom 1
cbo 1
dl 0
loc 196
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A increaseSpecialIndent() 0 10 2
A increaseBlockIndent() 0 10 2
A decreaseIndentLevelUntilIndentTypeIsSpecial() 0 14 3
A decreaseSpecialIndentIfCurrentIndentTypeIsSpecial() 0 11 2
A getIncreaseBlockIndent() 0 4 1
A getIncreaseSpecialIndent() 0 4 1
A getIndentLvl() 0 4 1
A getIndentTypes() 0 4 1
A setIncreaseBlockIndent() 0 6 1
A setIncreaseSpecialIndent() 0 6 1
A setIndentLvl() 0 6 1
A setIndentTypes() 0 6 1
A setInlineIndented() 0 6 1
A getInlineIndented() 0 4 1
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 12/22/14
5
 * Time: 11:37 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\QueryFormatter\Helper;
12
13
use NilPortugues\Sql\QueryFormatter\Formatter;
14
15
/**
16
 * Class Indent.
17
 */
18
class Indent
19
{
20
    /**
21
     * @var bool
22
     */
23
    protected $inlineIndented = false;
24
25
    /**
26
     * @var bool
27
     */
28
    protected $increaseSpecialIndent = false;
29
30
    /**
31
     * @var int
32
     */
33
    protected $indentLvl = 0;
34
35
    /**
36
     * @var bool
37
     */
38
    protected $increaseBlockIndent = false;
39
40
    /**
41
     * @var array
42
     */
43
    protected $indentTypes = [];
44
45
    /**
46
     * Increase the Special Indent if increaseSpecialIndent is true after the current iteration.
47
     *
48
     * @return $this
49
     */
50
    public function increaseSpecialIndent()
51
    {
52
        if ($this->increaseSpecialIndent) {
53
            ++$this->indentLvl;
54
            $this->increaseSpecialIndent = false;
55
            \array_unshift($this->indentTypes, 'special');
56
        }
57
58
        return $this;
59
    }
60
61
    /**
62
     * Increase the Block Indent if increaseBlockIndent is true after the current iteration.
63
     *
64
     * @return $this
65
     */
66
    public function increaseBlockIndent()
67
    {
68
        if ($this->increaseBlockIndent) {
69
            ++$this->indentLvl;
70
            $this->increaseBlockIndent = false;
71
            \array_unshift($this->indentTypes, 'block');
72
        }
73
74
        return $this;
75
    }
76
77
    /**
78
     * Closing parentheses decrease the block indent level.
79
     *
80
     * @param Formatter $formatter
81
     *
82
     * @return $this
83
     */
84
    public function decreaseIndentLevelUntilIndentTypeIsSpecial(Formatter $formatter)
85
    {
86
        $formatter->setFormattedSql(\rtrim($formatter->getFormattedSql(), ' '));
87
        --$this->indentLvl;
88
89
        while ($j = \array_shift($this->indentTypes)) {
90
            if ('special' !== $j) {
91
                break;
92
            }
93
            --$this->indentLvl;
94
        }
95
96
        return $this;
97
    }
98
99
    /**
100
     * @return $this
101
     */
102
    public function decreaseSpecialIndentIfCurrentIndentTypeIsSpecial()
103
    {
104
        \reset($this->indentTypes);
105
106
        if (\current($this->indentTypes) === 'special') {
107
            --$this->indentLvl;
108
            \array_shift($this->indentTypes);
109
        }
110
111
        return $this;
112
    }
113
114
    /**
115
     * @return bool
116
     */
117
    public function getIncreaseBlockIndent()
118
    {
119
        return $this->increaseBlockIndent;
120
    }
121
122
    /**
123
     * @return bool
124
     */
125
    public function getIncreaseSpecialIndent()
126
    {
127
        return $this->increaseSpecialIndent;
128
    }
129
130
    /**
131
     * @return int
132
     */
133
    public function getIndentLvl()
134
    {
135
        return $this->indentLvl;
136
    }
137
138
    /**
139
     * @return mixed
140
     */
141
    public function getIndentTypes()
142
    {
143
        return $this->indentTypes;
144
    }
145
146
    /**
147
     * @param bool $increaseBlockIndent
148
     *
149
     * @return $this
150
     */
151
    public function setIncreaseBlockIndent($increaseBlockIndent)
152
    {
153
        $this->increaseBlockIndent = $increaseBlockIndent;
154
155
        return $this;
156
    }
157
158
    /**
159
     * @param bool $increaseSpecialIndent
160
     *
161
     * @return $this
162
     */
163
    public function setIncreaseSpecialIndent($increaseSpecialIndent)
164
    {
165
        $this->increaseSpecialIndent = $increaseSpecialIndent;
166
167
        return $this;
168
    }
169
170
    /**
171
     * @param int $indentLvl
172
     *
173
     * @return $this
174
     */
175
    public function setIndentLvl($indentLvl)
176
    {
177
        $this->indentLvl = $indentLvl;
178
179
        return $this;
180
    }
181
182
    /**
183
     * @param array $indentTypes
184
     *
185
     * @return $this
186
     */
187
    public function setIndentTypes($indentTypes)
188
    {
189
        $this->indentTypes = $indentTypes;
190
191
        return $this;
192
    }
193
194
    /**
195
     * @param bool $inlineIndented
196
     *
197
     * @return $this
198
     */
199
    public function setInlineIndented($inlineIndented)
200
    {
201
        $this->inlineIndented = $inlineIndented;
202
203
        return $this;
204
    }
205
206
    /**
207
     * @return bool
208
     */
209
    public function getInlineIndented()
210
    {
211
        return $this->inlineIndented;
212
    }
213
}
214