This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Htsl\Parser; |
||
4 | |||
5 | use Htsl\Htsl; |
||
6 | use Htsl\ReadingBuffer\Contracts\ABuffer as Buffer; |
||
7 | use Htsl\ReadingBuffer\Line; |
||
8 | use Htsl\Helper\TGetter; |
||
9 | use Htsl\Helper\IConfigProvider; |
||
10 | use Htsl\Parser\Node\TagNode; |
||
11 | use Htsl\Parser\Node\StringNode; |
||
12 | use Htsl\Parser\Node\CommentNode; |
||
13 | use Htsl\Parser\Node\ControlNode; |
||
14 | use Htsl\Parser\Node\SectionNode; |
||
15 | use Htsl\Parser\Node\NamelessSectionNode; |
||
16 | use Htsl\Parser\Node\Contracts\ANode as Node; |
||
17 | |||
18 | //////////////////////////////////////////////////////////////// |
||
19 | |||
20 | /** |
||
21 | * @property-read string $content Result of document executing. |
||
22 | * @property-read string $doctype Type of this document. |
||
23 | * @property-read string|bool $indentation Indentation of document. |
||
24 | * @property-read \Htsl\Parser\Node\Contracts\ANode|bool $scope Current scope on top of stack. |
||
25 | * @property-read \Htsl\Htsl $htsl Htsl main object of document. |
||
26 | * @property-read int $indentLevel Current indent level. |
||
27 | */ |
||
28 | class Document implements IConfigProvider |
||
29 | { |
||
30 | use TGetter; |
||
31 | |||
32 | /** |
||
33 | * Htsl main object owns this document. |
||
34 | * |
||
35 | * @access private |
||
36 | * |
||
37 | * @var \Htsl\Htsl |
||
38 | */ |
||
39 | private $htsl; |
||
40 | |||
41 | /** |
||
42 | * Parent document. |
||
43 | * |
||
44 | * @access private |
||
45 | * |
||
46 | * @var \Htsl\Parser\Document | null |
||
47 | */ |
||
48 | private $parent; |
||
49 | |||
50 | /** |
||
51 | * Reading buffer of this document. |
||
52 | * |
||
53 | * @access private |
||
54 | * |
||
55 | * @var \Htsl\ReadingBuffer\Contracts\ABuffer |
||
56 | */ |
||
57 | private $buffer; |
||
58 | |||
59 | /** |
||
60 | * The indentation and whether output with linefeed and indent. |
||
61 | * |
||
62 | * @access private |
||
63 | * |
||
64 | * @var string | bool |
||
65 | */ |
||
66 | private $indentation; |
||
67 | |||
68 | /** |
||
69 | * Type of this document. |
||
70 | * |
||
71 | * @access private |
||
72 | * |
||
73 | * @var string |
||
74 | */ |
||
75 | private $docType; |
||
76 | |||
77 | /** |
||
78 | * Current embead script. |
||
79 | * |
||
80 | * @access private |
||
81 | * |
||
82 | * @var \Htsl\Embedment\Contract\Embedment |
||
83 | */ |
||
84 | private $embedment; |
||
85 | |||
86 | /** |
||
87 | * Current indent level. |
||
88 | * |
||
89 | * @access private |
||
90 | * |
||
91 | * @var int |
||
92 | */ |
||
93 | private $level= 0; |
||
0 ignored issues
–
show
|
|||
94 | |||
95 | /** |
||
96 | * Section indent level. |
||
97 | * |
||
98 | * @access private |
||
99 | * |
||
100 | * @var int |
||
101 | */ |
||
102 | private $sectionLevel= 0; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
103 | |||
104 | /** |
||
105 | * Opened nodes. |
||
106 | * |
||
107 | * @access private |
||
108 | * |
||
109 | * @var [ Htsl\Parser\Node\Contracts\ANode, ] |
||
110 | */ |
||
111 | private $openedNodes= []; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
112 | |||
113 | /** |
||
114 | * Current scopes. |
||
115 | * |
||
116 | * @access private |
||
117 | * |
||
118 | * @var [ Htsl\Parser\Node\Contracts\ANode, ] |
||
119 | */ |
||
120 | private $scopes= []; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
121 | |||
122 | /** |
||
123 | * Current line number. |
||
124 | * |
||
125 | * @access private |
||
126 | * |
||
127 | * @var int |
||
128 | */ |
||
129 | private $lineNumber= 0; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
130 | |||
131 | /** |
||
132 | * Current line. |
||
133 | * |
||
134 | * @access private |
||
135 | * |
||
136 | * @var \Htsl\ReadingBuffer\Line |
||
137 | */ |
||
138 | private $currentLine; |
||
139 | |||
140 | /** |
||
141 | * Sections that can be show. |
||
142 | * |
||
143 | * @access private |
||
144 | * |
||
145 | * @var [ Htsl\Parser\Section, ] |
||
146 | */ |
||
147 | private $sections=[]; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
148 | |||
149 | /** |
||
150 | * Whether the document is executed. |
||
151 | * |
||
152 | * @access private |
||
153 | * |
||
154 | * @var bool |
||
155 | */ |
||
156 | private $isExecuted; |
||
157 | |||
158 | /** |
||
159 | * Current Section. |
||
160 | * |
||
161 | * @access private |
||
162 | * |
||
163 | * @var \Htsl\Parser\Section |
||
164 | */ |
||
165 | private $currentSection; |
||
166 | |||
167 | /** |
||
168 | * The content of this document. |
||
169 | * |
||
170 | * @access private |
||
171 | * |
||
172 | * @var string |
||
173 | */ |
||
174 | private $content; |
||
175 | |||
176 | /** |
||
177 | * Constructor of the Document. |
||
178 | * |
||
179 | * @access public |
||
180 | * |
||
181 | * @param \Htsl\Htsl $htsl |
||
182 | * @param \Htsl\ReadingBuffer\Contracts\ABuffer $buffer |
||
183 | * @param \Htsl\Parser\Document | null $parent |
||
184 | */ |
||
185 | public function __construct( Htsl$htsl, Buffer$buffer, self$parent=null ) |
||
186 | { |
||
187 | $this->htsl= $htsl; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
188 | $this->buffer= $buffer; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
189 | |||
190 | if( $parent ){ |
||
191 | $this->parent= $parent; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
192 | $this->docType= $parent->docType; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
193 | $this->indentation= $parent->indentation; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
194 | }else{ |
||
195 | $this->parseFirstLine(); |
||
196 | } |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * Executing the document. |
||
201 | * |
||
202 | * @access public |
||
203 | * |
||
204 | * @return \Htsl\Parser\Document |
||
205 | */ |
||
206 | public function execute():self |
||
207 | { |
||
208 | if( $this->isExecuted ){ |
||
209 | return $this; |
||
210 | } |
||
211 | return $this->lineByLine() |
||
212 | ->bubbleSections() |
||
213 | ; |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * Alias of getContent. |
||
218 | * |
||
219 | * @access public |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | public function __toString():string |
||
224 | { |
||
225 | return $this->getContent(); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Getting the result of document executing. |
||
230 | * |
||
231 | * @access protected |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | protected function getContent():string |
||
236 | { |
||
237 | if( $this->parent ){ |
||
238 | return $this->execute()->parent->getContent(); |
||
239 | }else{ |
||
240 | return $this->execute()->content; |
||
241 | } |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * Getting the next line. |
||
246 | * |
||
247 | * @access protected |
||
248 | * |
||
249 | * @return \Htsl\ReadingBuffer\Line |
||
250 | */ |
||
251 | protected function getLine():Line |
||
252 | { |
||
253 | do{ |
||
254 | $line= $this->buffer->getLine(); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
255 | }while( $line->isEmpty() && $line->hasMore() ); |
||
256 | |||
257 | return $line; |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * Getting the config of type of this document. |
||
262 | * |
||
263 | * @access public |
||
264 | * |
||
265 | * @param [ string, ] ...$keys |
||
266 | * |
||
267 | * @return mixed |
||
268 | */ |
||
269 | public function getConfig( string...$keys ) |
||
270 | { |
||
271 | return $this->htsl->getConfig(array_shift($keys),$this->docType,...$keys); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Getting the type of this document. |
||
276 | * |
||
277 | * @access public |
||
278 | * |
||
279 | * @return string |
||
280 | */ |
||
281 | public function getDoctype():string |
||
282 | { |
||
283 | return $this->docType; |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * Getting the indentation. |
||
288 | * |
||
289 | * @access public |
||
290 | * |
||
291 | * @return string | bool |
||
292 | */ |
||
293 | public function getIndentation() |
||
294 | { |
||
295 | return $this->indentation; |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * Getting the indent level. |
||
300 | * |
||
301 | * @access public |
||
302 | * |
||
303 | * @return int |
||
304 | */ |
||
305 | public function getIndentLevel():int |
||
306 | { |
||
307 | return $this->level; |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * Parsing the first line. |
||
312 | * |
||
313 | * @access protected |
||
314 | * |
||
315 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
316 | */ |
||
317 | protected function parseFirstLine():self |
||
318 | { |
||
319 | $line= $this->getLine(); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
320 | |||
321 | if( '@'===$line->getChar(0) ){ |
||
322 | return $this->setExtending($line); |
||
323 | } |
||
324 | |||
325 | $this->docType= $line->content; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
326 | $docTypeContent= $this->getConfig('doc_types') or $this->throw("DocType $this->docType is not supported"); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() As per coding-style, please use concatenation or
sprintf for the variable $this instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
327 | |||
328 | $this->indentation= $this->htsl->getConfig('indentation',$this->docType) ?? ( function( $scalarOrFalse ){ return is_scalar($scalarOrFalse)?$scalarOrFalse:false; } )($this->htsl->getConfig('indentation')); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
329 | |||
330 | return $this->appendLine($docTypeContent); |
||
331 | } |
||
332 | |||
333 | /** |
||
334 | * Setting that this document extends another document. |
||
335 | * |
||
336 | * @access protected |
||
337 | * |
||
338 | * @param \Htsl\ReadingBuffer\Line $firstLine |
||
339 | * |
||
340 | * @return \Htsl\Parser\Document |
||
341 | */ |
||
342 | protected function setExtending( Line$firstLine ):self |
||
343 | { |
||
344 | switch( $name= $firstLine->pregGet('/(?<=^@)[\w-:]+/') ){ |
||
345 | default:{ |
||
346 | $this->throw("The @$name is not supported."); |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $name instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
347 | }break; |
||
348 | case 'extend':{ |
||
349 | $this->extend($firstLine->pregGet('/(?<=\( ).*(?= \))/')); |
||
350 | }break; |
||
351 | case 'show': |
||
352 | case 'include': |
||
353 | case 'section':{ |
||
354 | $this->throw("The @$name can not be used on first line."); |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $name instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
355 | }break; |
||
356 | } |
||
357 | |||
358 | return $this; |
||
359 | } |
||
360 | |||
361 | /** |
||
362 | * Parsing this document line by line. |
||
363 | * |
||
364 | * @access protected |
||
365 | * |
||
366 | * @return \Htsl\Parser\Document |
||
367 | */ |
||
368 | protected function lineByLine():self |
||
369 | { |
||
370 | while( ($line= $this->getLine())->hasMore() ){ |
||
371 | $this->lineNumber+= 1; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
372 | |||
373 | if( $this->embedment ){ |
||
374 | $this->embeddingParse($line); |
||
375 | }else{ |
||
376 | $this->parseLine($line); |
||
377 | } |
||
378 | } |
||
379 | |||
380 | $this->embedment and $this->breakEmbedding(); |
||
381 | |||
382 | $this->closeNodes($this->level); |
||
383 | |||
384 | $this->isExecuted= true; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
385 | |||
386 | return $this; |
||
387 | } |
||
388 | |||
389 | /** |
||
390 | * Parsing embedded line. |
||
391 | * |
||
392 | * @access protected |
||
393 | * |
||
394 | * @param \Htsl\ReadingBuffer\Line $line |
||
395 | * |
||
396 | * @return \Htsl\Parser\Document |
||
397 | */ |
||
398 | protected function embeddingParse( Line$line ):self |
||
399 | { |
||
400 | if( $line->content==='<}' ){ |
||
401 | $this->breakEmbedding(); |
||
402 | }else{ |
||
403 | $this->embedment->parseLine($line->getSubIndentLine()); |
||
404 | } |
||
405 | |||
406 | return $this; |
||
407 | } |
||
408 | |||
409 | /** |
||
410 | * Starting the embedding. |
||
411 | * |
||
412 | * @access protected |
||
413 | * |
||
414 | * @param string $embedType |
||
415 | * |
||
416 | * @return \Htsl\Parser\Document |
||
417 | */ |
||
418 | protected function startEmbedding( string$embedType ):self |
||
419 | { |
||
420 | $embedmentClass= '\\Htsl\\Embedment\\'.ucfirst($embedType).'Embedment'; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
421 | class_exists($embedmentClass) or $this->throw("Embed type $embedType not exists."); |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $embedType instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
422 | |||
423 | $this->embedment= new $embedmentClass($this); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
424 | |||
425 | return $this; |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * Ending the embedding. |
||
430 | * |
||
431 | * @access public |
||
432 | * |
||
433 | * @return \Htsl\Parser\Document |
||
434 | */ |
||
435 | public function breakEmbedding():self |
||
436 | { |
||
437 | $this->append($this->embedment->getContent()); |
||
438 | $this->embedment= null; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
439 | |||
440 | return $this; |
||
441 | } |
||
442 | |||
443 | /** |
||
444 | * Parsing line. |
||
445 | * |
||
446 | * @access protected |
||
447 | * |
||
448 | * @param \Htsl\ReadingBuffer\Line $line |
||
449 | * |
||
450 | * @return \Htsl\Parser\Document |
||
451 | */ |
||
452 | protected function parseLine( Line$line ):self |
||
453 | { |
||
454 | $this->currentLine= $line; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
455 | $this->setLevel($line->getIndentLevel()); |
||
456 | |||
457 | $this->{'parse'.ucfirst($this->getLineType($line))}($line); |
||
458 | |||
459 | return $this; |
||
460 | } |
||
461 | |||
462 | /** |
||
463 | * Getting line type by analyzing first or first two characters of line. |
||
464 | * |
||
465 | * @access protected |
||
466 | * |
||
467 | * @param \Htsl\ReadingBuffer\Line $line |
||
468 | * |
||
469 | * @return string |
||
470 | */ |
||
471 | protected function getLineType( Line$line ):string |
||
472 | { |
||
473 | $possibleType= self::POSSIBLE_LINE_TYPES; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
474 | |||
475 | for( $i=0; is_array($possibleType); ++$i ){ |
||
476 | $possibleType= $possibleType[$line->getChar($i)]??$possibleType[' ']; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
477 | } |
||
478 | |||
479 | return $possibleType; |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * Possible line types. |
||
484 | * |
||
485 | * @access public |
||
486 | * |
||
487 | * @const array |
||
488 | * |
||
489 | * @todo Make this const private when php 7.1 |
||
490 | */ |
||
491 | const POSSIBLE_LINE_TYPES= [ |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
492 | '`'=> [ |
||
493 | '='=> 'expressionHtmlLine', |
||
494 | ' '=> 'htmlLine', |
||
495 | ], |
||
496 | '='=> 'expressionLine', |
||
497 | '!'=> 'commentLine', |
||
498 | '-'=> 'tagLine', |
||
499 | '~'=> 'controlLine', |
||
500 | '@'=> 'docControlLine', |
||
501 | ' '=> 'stringLine', |
||
502 | ]; |
||
503 | |||
504 | /** |
||
505 | * Parsing line as HTML content. |
||
506 | * |
||
507 | * @access protected |
||
508 | * |
||
509 | * @param \Htsl\ReadingBuffer\Line $line |
||
510 | * |
||
511 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
512 | */ |
||
513 | protected function parseHtmlLine( Line$line ):self |
||
514 | { |
||
515 | return $this->openNode(new StringNode($this,$line))->appendLine($line->slice(1)); |
||
516 | } |
||
517 | |||
518 | /** |
||
519 | * Parsing line as string content. |
||
520 | * |
||
521 | * @access protected |
||
522 | * |
||
523 | * @param \Htsl\ReadingBuffer\Line $line |
||
524 | * |
||
525 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
526 | */ |
||
527 | protected function parseStringLine( Line$line ):self |
||
528 | { |
||
529 | return $this->openNode(new StringNode($this,$line))->appendLine($this->htmlEntities(trim($line->getContent()))); |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * Parsing line as PHP expression. |
||
534 | * |
||
535 | * @access protected |
||
536 | * |
||
537 | * @param \Htsl\ReadingBuffer\Line $line |
||
538 | * |
||
539 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
540 | */ |
||
541 | protected function parseExpressionLine( Line$line ):self |
||
542 | { |
||
543 | $content= $line->slice(1); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
544 | $ent_flag= var_export($this->htsl->getConfig('ENT_flags',$this->docType),true); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
545 | $charset= var_export($this->htsl->getConfig('charset'),true); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
546 | |||
547 | return $this->openNode(new StringNode($this,$line))->appendLine("<?=htmlentities($content,$ent_flag,$charset,false)?>"); |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $content instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() As per coding-style, please use concatenation or
sprintf for the variable $ent_flag instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() As per coding-style, please use concatenation or
sprintf for the variable $charset instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
548 | } |
||
549 | |||
550 | /** |
||
551 | * Parsing line as PHP expression with HTML result. |
||
552 | * |
||
553 | * @access protected |
||
554 | * |
||
555 | * @param \Htsl\ReadingBuffer\Line $line |
||
556 | * |
||
557 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
558 | */ |
||
559 | protected function parseExpressionHtmlLine( Line$line ):self |
||
560 | { |
||
561 | $content= $line->slice(1); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
562 | |||
563 | return $this->openNode(new StringNode($this,$line))->appendLine("<?$content?>"); |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $content instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
564 | } |
||
565 | |||
566 | /** |
||
567 | * Parsing line as comment. |
||
568 | * |
||
569 | * @access protected |
||
570 | * |
||
571 | * @param \Htsl\ReadingBuffer\Line $line |
||
572 | * |
||
573 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
574 | */ |
||
575 | protected function parseCommentLine( Line$line ):self |
||
576 | { |
||
577 | $node= new CommentNode($this,$line); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
578 | |||
579 | return $this->openNode($node)->appendLine($node->open()); |
||
580 | } |
||
581 | |||
582 | /** |
||
583 | * Parsing line as HTSL tag. |
||
584 | * |
||
585 | * @access protected |
||
586 | * |
||
587 | * @param \Htsl\ReadingBuffer\Line $line |
||
588 | * |
||
589 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
590 | */ |
||
591 | protected function parseTagLine( Line$line ):self |
||
592 | { |
||
593 | $node= new TagNode($this,$line); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
594 | |||
595 | $this->appendLine($node->open()); |
||
596 | |||
597 | $node->embed and $this->startEmbedding($node->embed); |
||
598 | |||
599 | return $this->openNode($node); |
||
600 | } |
||
601 | |||
602 | /** |
||
603 | * Parsing line as control node of Htsl.php. |
||
604 | * |
||
605 | * @access protected |
||
606 | * |
||
607 | * @param \Htsl\ReadingBuffer\Line $line |
||
608 | * |
||
609 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
610 | */ |
||
611 | protected function parseControlLine( Line$line ):self |
||
612 | { |
||
613 | $node= new ControlNode($this,$line); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
614 | |||
615 | return $this->appendLine($node->open())->openNode($node); |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * Parsing line as document control node of Htsl.php. |
||
620 | * |
||
621 | * @access protected |
||
622 | * |
||
623 | * @param \Htsl\ReadingBuffer\Line $line |
||
624 | * |
||
625 | * @return \Htsl\Parser\Document |
||
626 | */ |
||
627 | protected function parseDocControlLine( Line$line ):self |
||
628 | { |
||
629 | switch( $name= $line->pregGet('/(?<=^@)[\w-:]+/') ){ |
||
630 | default:{ |
||
631 | $this->throw("The @$name is not supported."); |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $name instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
632 | }break; |
||
633 | case 'extend':{ |
||
634 | $this->throw('The @extend can only be used on first line.'); |
||
635 | }break; |
||
636 | case 'include':{ |
||
637 | $this->include($line); |
||
638 | }break; |
||
639 | case 'section':{ |
||
640 | $this->defineSection($line); |
||
641 | }break; |
||
642 | case 'show':{ |
||
643 | $this->showSection($line); |
||
644 | }break; |
||
645 | } |
||
646 | |||
647 | return $this; |
||
648 | } |
||
649 | |||
650 | /** |
||
651 | * Parsing extending defination. |
||
652 | * |
||
653 | * @access protected |
||
654 | * |
||
655 | * @param string $fileName |
||
656 | * |
||
657 | * @return \Htsl\Parser\Document |
||
658 | */ |
||
659 | protected function extend( string$fileName ):self |
||
660 | { |
||
661 | $this->parent= new static($this->htsl,$this->buffer->goSide($fileName)); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
662 | |||
663 | $this->docType= $this->parent->docType; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
664 | $this->indentation= $this->parent->indentation; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
665 | |||
666 | return $this; |
||
667 | } |
||
668 | |||
669 | /** |
||
670 | * Insert indentations into given paragraph. |
||
671 | * |
||
672 | * @access protected |
||
673 | * |
||
674 | * @param string $input |
||
675 | * |
||
676 | * @return string |
||
677 | */ |
||
678 | protected function insertIndentations( string$input ):string |
||
679 | { |
||
680 | return preg_replace('/(?<=^|\\n)(?!$)/',str_repeat($this->indentation,$this->level-$this->sectionLevel),$input); |
||
681 | } |
||
682 | |||
683 | /** |
||
684 | * Include another document. |
||
685 | * |
||
686 | * @access protected |
||
687 | * |
||
688 | * @param \Htsl\ReadingBuffer\Line $line |
||
689 | * |
||
690 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
691 | */ |
||
692 | protected function include( Line$line ):self |
||
693 | { |
||
694 | $inclued= (new static($this->htsl,$this->buffer->goSide($line->pregGet('/(?<=\( ).*(?= \))/')),$this))->execute()->content??null; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
695 | |||
696 | false===$this->indentation or $inclued= $this->insertIndentations($inclued); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
697 | |||
698 | return $this->openNode(new StringNode($this,$line))->append($inclued); |
||
699 | } |
||
700 | |||
701 | /** |
||
702 | * Starting to define a section. |
||
703 | * |
||
704 | * @access protected |
||
705 | * |
||
706 | * @param \Htsl\ReadingBuffer\Line $line |
||
707 | * |
||
708 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
709 | */ |
||
710 | protected function defineSection( Line$line ):self |
||
711 | { |
||
712 | $node= new SectionNode($this,$line); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
713 | |||
714 | $node->open(); |
||
715 | |||
716 | return $this->openNode($node); |
||
717 | } |
||
718 | |||
719 | /** |
||
720 | * Showing a section. |
||
721 | * |
||
722 | * @access protected |
||
723 | * |
||
724 | * @param \Htsl\ReadingBuffer\Line $line |
||
725 | * |
||
726 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
727 | */ |
||
728 | protected function showSection( Line$line ):self |
||
729 | { |
||
730 | $sectionName= $line->pregGet('/(?<=\( ).*(?= \))/'); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
731 | |||
732 | if( !isset($this->sections[$sectionName]) ){ |
||
733 | return $this->openNode(new StringNode($this,$line)); |
||
734 | } |
||
735 | $content= $this->sections[$sectionName]->content; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
736 | |||
737 | false===$this->indentation or $content= $this->insertIndentations($content); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
738 | |||
739 | $this->append($content); |
||
740 | |||
741 | $node= new NamelessSectionNode($this,$line); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
742 | |||
743 | $node->open(); |
||
744 | |||
745 | return $this->openNode($node); |
||
746 | } |
||
747 | |||
748 | /** |
||
749 | * Setting document as section definer. |
||
750 | * |
||
751 | * @access public |
||
752 | * |
||
753 | * @param Section | null $section |
||
754 | */ |
||
755 | public function setSection( Section$section=null ):self |
||
756 | { |
||
757 | if( !$section ){ |
||
758 | $this->sectionLevel= 0; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
759 | $this->currentSection= null; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 0 spaces
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
760 | |||
761 | return $this; |
||
762 | } |
||
763 | |||
764 | if( $this->currentSection ){ |
||
765 | $this->throw('Nesting definition of section is forbidden.'); |
||
766 | } |
||
767 | |||
768 | if( isset($this->parent->sections[$section->name]) ){ |
||
769 | $this->throw("Section {$section->name} already defined."); |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $section instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
770 | } |
||
771 | |||
772 | $this->currentSection= $section; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
773 | |||
774 | if( $section->name ){ |
||
775 | $this->parent->sections[$section->name]=$section; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
776 | } |
||
777 | |||
778 | $this->sectionLevel= $this->level+1; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
779 | |||
780 | return $this; |
||
781 | } |
||
782 | |||
783 | /** |
||
784 | * Bubble the sections to parent document. |
||
785 | * |
||
786 | * @access protected |
||
787 | * |
||
788 | * @return \Htsl\Parser\Document |
||
789 | */ |
||
790 | protected function bubbleSections():self |
||
791 | { |
||
792 | if( $this->parent ){ |
||
793 | foreach( $this->sections as $name=>$section ){ |
||
794 | if( !isset($this->parent->sections[$name]) ){ |
||
795 | $this->parent->sections[$name]=$section; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
796 | }; |
||
797 | } |
||
798 | } |
||
799 | |||
800 | return $this; |
||
801 | } |
||
802 | |||
803 | /** |
||
804 | * Escaping characters to HTML entities. |
||
805 | * |
||
806 | * @access public |
||
807 | * |
||
808 | * @param string $input |
||
809 | * |
||
810 | * @return string |
||
811 | */ |
||
812 | public function htmlEntities( string$input ):string |
||
813 | { |
||
814 | return htmlentities($input,$this->htsl->getConfig('ENT_flags',$this->docType),$this->htsl->getConfig('charset'),false); |
||
815 | } |
||
816 | |||
817 | /** |
||
818 | * Setting indent level of this document. |
||
819 | * |
||
820 | * @access protected |
||
821 | * |
||
822 | * @param int $level |
||
823 | */ |
||
824 | protected function setLevel( int$level ):self |
||
825 | { |
||
826 | $level-= $this->level; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
827 | |||
828 | if( $level<=0 ){ |
||
829 | $this->closeNodes(-$level); |
||
830 | }elseif( $level==1 ){ |
||
831 | $this->level+= 1; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
832 | }else{ |
||
833 | $this->throw('Indent error.'); |
||
834 | } |
||
835 | |||
836 | return $this; |
||
837 | } |
||
838 | |||
839 | /** |
||
840 | * Opening a node. |
||
841 | * |
||
842 | * @access protected |
||
843 | * |
||
844 | * @param \Htsl\Parser\Node\Contracts\ANode $node |
||
845 | * |
||
846 | * @return \Htsl\Parser\Document |
||
847 | */ |
||
848 | protected function openNode( Node$node ):self |
||
849 | { |
||
850 | array_push($this->openedNodes,$node); |
||
851 | |||
852 | $node->scope and $this->setScope($node); |
||
853 | |||
854 | return $this; |
||
855 | } |
||
856 | |||
857 | /** |
||
858 | * Closing open node or nodes. |
||
859 | * |
||
860 | * @access protected |
||
861 | * |
||
862 | * @param int $level |
||
863 | * |
||
864 | * @return \Htsl\Parser\Document |
||
865 | */ |
||
866 | protected function closeNodes( int$level=0 ):self |
||
867 | { |
||
868 | if( empty($this->openedNodes) ) return $this; |
||
869 | |||
870 | while( $level-->=0 ){ |
||
871 | $node= array_pop($this->openedNodes); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
872 | |||
873 | $node->scope and $this->removeScope($node); |
||
874 | |||
875 | $closer=$node->close($this->currentLine) and $this->appendLine($closer); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
876 | |||
877 | $this->level-= $level>=0 ?1:0; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
878 | } |
||
879 | |||
880 | return $this; |
||
881 | } |
||
882 | |||
883 | /** |
||
884 | * Pushing a scope to stack. |
||
885 | * |
||
886 | * @access protected |
||
887 | * |
||
888 | * @param \Htsl\Parser\Node\Contracts\ANode $scope |
||
889 | */ |
||
890 | protected function setScope( Node$scope ):int |
||
891 | { |
||
892 | return array_unshift($this->scopes,$scope); |
||
893 | } |
||
894 | |||
895 | /** |
||
896 | * Getting current scope on top of stack. |
||
897 | * |
||
898 | * @access public |
||
899 | * |
||
900 | * @return \Htsl\Parser\Node\Contracts\ANode | null |
||
901 | */ |
||
902 | public function getScope() |
||
903 | { |
||
904 | return $this->scopes[0]??null; |
||
905 | } |
||
906 | |||
907 | /** |
||
908 | * Pop a scope from stack. |
||
909 | * |
||
910 | * @access protected |
||
911 | * |
||
912 | * @param \Htsl\Parser\Node\Contracts\ANode $scope |
||
913 | * |
||
914 | * @return \Htsl\Parser\Document |
||
915 | */ |
||
916 | protected function removeScope( Node$scope ):self |
||
917 | { |
||
918 | if( $scope!==array_shift($this->scopes) ){ |
||
919 | $this->throw('Scope nesting error'); |
||
920 | }; |
||
921 | |||
922 | return $this; |
||
923 | } |
||
924 | |||
925 | /** |
||
926 | * Appending a line of content to parsing result. |
||
927 | * |
||
928 | * @access protected |
||
929 | * |
||
930 | * @param string $content |
||
931 | * |
||
932 | * @return \Htsl\Parser\Document |
||
0 ignored issues
–
show
|
|||
933 | */ |
||
934 | protected function appendLine( string$content ):self |
||
935 | { |
||
936 | false===$this->indentation or $content= str_repeat($this->indentation,$this->level-$this->sectionLevel).$content."\n"; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
937 | |||
938 | return $this->append($content); |
||
939 | } |
||
940 | |||
941 | /** |
||
942 | * Appending some content to parsing result. |
||
943 | * |
||
944 | * @access protected |
||
945 | * |
||
946 | * @param string $content |
||
947 | * |
||
948 | * @return \Htsl\Parser\Document |
||
949 | */ |
||
950 | protected function append( string$content ):self |
||
951 | { |
||
952 | if( $this->currentSection ){ |
||
953 | $this->currentSection->append($content); |
||
954 | }else{ |
||
955 | $this->content.=$content; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 0 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
956 | } |
||
957 | |||
958 | return $this; |
||
959 | } |
||
960 | |||
961 | /** |
||
962 | * Getting the Htsl main object. |
||
963 | * |
||
964 | * @access public |
||
965 | * |
||
966 | * @return \Htsl\Htsl |
||
967 | */ |
||
968 | public function getHtsl() |
||
969 | { |
||
970 | return $this->htsl; |
||
971 | } |
||
972 | |||
973 | /** |
||
974 | * Throw exception with document name and line number. |
||
975 | * |
||
976 | * @access public |
||
977 | * |
||
978 | * @param string $message |
||
979 | * |
||
980 | * @throw \Htsl\Parser\HtslParsingException |
||
981 | */ |
||
982 | public function throw( string$message ) |
||
983 | { |
||
984 | throw new HtslParsingException("$message at file {$this->buffer->filePath} line $this->lineNumber"); |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $message instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() As per coding-style, please use concatenation or
sprintf for the variable $this instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
985 | } |
||
986 | } |
||
0 ignored issues
–
show
|
|||
987 |
This check looks for improperly formatted assignments.
Every assignment must have exactly one space before and one space after the equals operator.
To illustrate:
will have no issues, while
will report issues in lines 1 and 2.