1 | <?php |
||
11 | class ComponentBuffer { |
||
12 | private $buffer = ''; |
||
|
|||
13 | private $literalBuffer = ''; |
||
14 | private $inEcho = false; |
||
15 | private $indent; |
||
16 | private $depth; |
||
17 | private $scopes; |
||
18 | |||
19 | 38 | public function __construct(array $defaults = []) { |
|
20 | $defaults += [ |
||
21 | 38 | 'depth' => 0, |
|
22 | 38 | 'indent' => 0, |
|
23 | 38 | 'scopes' => [] |
|
24 | 38 | ]; |
|
25 | |||
26 | 38 | $this->depth = $defaults['depth']; |
|
27 | 38 | $this->indent = $defaults['indent']; |
|
28 | 38 | $this->scopes = $defaults['scopes']; |
|
29 | 38 | } |
|
30 | |||
31 | 38 | public function echoLiteral($value) { |
|
34 | |||
35 | 26 | public function echoCode($php) { |
|
44 | |||
45 | 38 | private function flushLiteralBuffer() { |
|
46 | 38 | if (!empty($this->literalBuffer)) { |
|
47 | 36 | $this->ensureEcho(true); |
|
48 | 36 | $this->buffer .= var_export($this->literalBuffer, true); |
|
49 | 36 | $this->literalBuffer = ''; |
|
50 | 36 | } |
|
51 | 38 | } |
|
52 | |||
53 | 38 | private function ensureEcho($append) { |
|
54 | 38 | if (!$this->inEcho) { |
|
55 | 38 | $this->buffer .= $this->px().'echo '; |
|
56 | 38 | $this->inEcho = true; |
|
57 | 38 | } elseif ($append) { |
|
58 | 24 | $this->buffer .= ",\n".$this->px(+1); |
|
59 | 24 | } |
|
60 | 38 | } |
|
61 | |||
62 | 38 | protected function px($add = 0) { |
|
65 | |||
66 | 38 | public function appendCode($php) { |
|
72 | |||
73 | 38 | private function flushEcho() { |
|
74 | 38 | $this->flushLiteralBuffer(); |
|
75 | |||
76 | 38 | if ($this->inEcho) { |
|
77 | 38 | $this->buffer .= ";\n"; |
|
78 | 38 | $this->inEcho = false; |
|
79 | 38 | } |
|
80 | 38 | } |
|
81 | |||
82 | 38 | public function indent($add) { |
|
86 | |||
87 | 13 | public function depth($add = 1) { |
|
90 | |||
91 | 13 | public function depthName($name, $add = 0) { |
|
100 | |||
101 | 38 | public function pushScope(array $vars) { |
|
104 | |||
105 | 38 | public function popScope() { |
|
108 | |||
109 | 34 | public function getScopeVariables() { |
|
113 | |||
114 | public function getScope() { |
||
117 | |||
118 | 9 | public function getAllScopes() { |
|
121 | |||
122 | 38 | public function flush() { |
|
127 | |||
128 | /** |
||
129 | * Get the indent. |
||
130 | * |
||
131 | * @return int Returns the indent. |
||
132 | */ |
||
133 | 9 | public function getIndent() { |
|
136 | |||
137 | /** |
||
138 | * Get the depth. |
||
139 | * |
||
140 | * @return mixed Returns the depth. |
||
141 | */ |
||
142 | 9 | public function getDepth() { |
|
145 | } |
||
146 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.