@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * |
| 15 | 15 | * @param \Htsl\ReadingBuffer\Line $line |
| 16 | 16 | * |
| 17 | - * @return \Htsl\Embedment\Contracts |
|
| 17 | + * @return CodeEmbedment |
|
| 18 | 18 | */ |
| 19 | 19 | public function parseLine( Line$line ):parent |
| 20 | 20 | { |
@@ -18,13 +18,13 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | public function parseLine( Line$line ):parent |
| 20 | 20 | { |
| 21 | - $content= '<code>'.htmlentities($line->fullContent).'</code>'; |
|
| 21 | + $content='<code>'.htmlentities($line->fullContent).'</code>'; |
|
| 22 | 22 | |
| 23 | - $indentation= $this->document->indentation; |
|
| 23 | + $indentation=$this->document->indentation; |
|
| 24 | 24 | |
| 25 | - false!==$indentation and $content= str_repeat($indentation,$this->document->indentLevel).$content."\n"; |
|
| 25 | + false!==$indentation and $content=str_repeat($indentation, $this->document->indentLevel).$content."\n"; |
|
| 26 | 26 | |
| 27 | - $this->content.= $content; |
|
| 27 | + $this->content.=$content; |
|
| 28 | 28 | |
| 29 | 29 | return $this; |
| 30 | 30 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * |
| 15 | 15 | * @param \Htsl\ReadingBuffer\Line $line |
| 16 | 16 | * |
| 17 | - * @return \Htsl\Embedment\Contracts |
|
| 17 | + * @return CssEmbedment |
|
| 18 | 18 | */ |
| 19 | 19 | public function parseLine( Line$line ):parent |
| 20 | 20 | { |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | public function parseLine( Line$line ):parent |
| 20 | 20 | { |
| 21 | - $this->content.= $line->content; |
|
| 21 | + $this->content.=$line->content; |
|
| 22 | 22 | return $this; |
| 23 | 23 | } |
| 24 | 24 | } |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | * |
| 23 | 23 | * @param \Htsl\ReadingBuffer\Line $line |
| 24 | 24 | * |
| 25 | - * @return \Htsl\Embedment\Contracts |
|
| 25 | + * @return JsEmbedment |
|
| 26 | 26 | */ |
| 27 | 27 | public function parseLine( Line$line ):parent |
| 28 | 28 | { |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | public function parseLine( Line$line ):parent |
| 28 | 28 | { |
| 29 | - $this->content.= $line->fullContent."\n"; |
|
| 29 | + $this->content.=$line->fullContent."\n"; |
|
| 30 | 30 | return $this; |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * |
| 15 | 15 | * @param \Htsl\ReadingBuffer\Line $line |
| 16 | 16 | * |
| 17 | - * @return \Htsl\Embedment\Contracts |
|
| 17 | + * @return PhpEmbedment |
|
| 18 | 18 | */ |
| 19 | 19 | public function parseLine( Line$line ):parent |
| 20 | 20 | { |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | public function parseLine( Line$line ):parent |
| 20 | 20 | { |
| 21 | - $this->content.= $line->content; |
|
| 21 | + $this->content.=$line->content; |
|
| 22 | 22 | return $this; |
| 23 | 23 | } |
| 24 | 24 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * |
| 15 | 15 | * @param \Htsl\ReadingBuffer\Line $line |
| 16 | 16 | * |
| 17 | - * @return \Htsl\Embedment\Contracts |
|
| 17 | + * @return TextEmbedment |
|
| 18 | 18 | */ |
| 19 | 19 | public function parseLine( Line$line ):parent |
| 20 | 20 | { |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | public function parseLine( Line$line ):parent |
| 28 | 28 | { |
| 29 | - $this->content.= $line->fullContent."\n"; |
|
| 29 | + $this->content.=$line->fullContent."\n"; |
|
| 30 | 30 | return $this; |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | if( $toFile ){ |
| 69 | 69 | return file_put_contents($toFile,$result); |
| 70 | - }else{ |
|
| 70 | + } else{ |
|
| 71 | 71 | return $result; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -159,15 +159,12 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | if( '/'===$filePath{0} ){ |
| 161 | 161 | if( is_null($path) ) |
| 162 | - { return $filePath; } |
|
| 163 | - else |
|
| 162 | + { return $filePath; } else |
|
| 164 | 163 | { return $this->basePath.$filePath; } |
| 165 | - }else{ |
|
| 164 | + } else{ |
|
| 166 | 165 | if( !strlen($path) ) |
| 167 | - { return $this->basePath.'/'.$filePath; } |
|
| 168 | - elseif( '/'===substr($path,-1) ) |
|
| 169 | - { return $path.$filePath; } |
|
| 170 | - else |
|
| 166 | + { return $this->basePath.'/'.$filePath; } elseif( '/'===substr($path,-1) ) |
|
| 167 | + { return $path.$filePath; } else |
|
| 171 | 168 | { return $path.'/'.$filePath; } |
| 172 | 169 | } |
| 173 | 170 | |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param array $config |
| 36 | 36 | */ |
| 37 | - public function __construct( array$config=[] ) |
|
| 37 | + public function __construct( array$config=[ ] ) |
|
| 38 | 38 | { |
| 39 | - $this->config= array_replace_recursive($this->getDefaultConfigs(),$config); |
|
| 39 | + $this->config=array_replace_recursive($this->getDefaultConfigs(), $config); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function parse( string$content ):string |
| 50 | 50 | { |
| 51 | - return $this->execute(new StringBuffer($this,$content)); |
|
| 51 | + return $this->execute(new StringBuffer($this, $content)); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -61,12 +61,12 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function compile( string$fromFile, string$toFile=null ) |
| 63 | 63 | { |
| 64 | - $fromFile= $this->getFilePath($fromFile); |
|
| 64 | + $fromFile=$this->getFilePath($fromFile); |
|
| 65 | 65 | |
| 66 | - $result= $this->execute(new FileBuffer($this,$fromFile)); |
|
| 66 | + $result=$this->execute(new FileBuffer($this, $fromFile)); |
|
| 67 | 67 | |
| 68 | 68 | if( $toFile ){ |
| 69 | - return file_put_contents($toFile,$result); |
|
| 69 | + return file_put_contents($toFile, $result); |
|
| 70 | 70 | }else{ |
| 71 | 71 | return $result; |
| 72 | 72 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function setBasePath( string$basePath ):self |
| 95 | 95 | { |
| 96 | - $this->basePath= '/'===substr($basePath,-1) ? substr($basePath,0,-1) : $basePath; |
|
| 96 | + $this->basePath='/'===substr($basePath, -1)? substr($basePath, 0, -1) : $basePath; |
|
| 97 | 97 | |
| 98 | 98 | return $this; |
| 99 | 99 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | protected function execute( ABuffer$buffer ):string |
| 119 | 119 | { |
| 120 | - return (new Document($this,$buffer))->content; |
|
| 120 | + return (new Document($this, $buffer))->content; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function getConfig( string...$keys ) |
| 131 | 131 | { |
| 132 | - $result= $this->config; |
|
| 132 | + $result=$this->config; |
|
| 133 | 133 | |
| 134 | 134 | foreach( $keys as $key ){ |
| 135 | - if( !isset($result[$key]) ) |
|
| 135 | + if( !isset($result[ $key ]) ) |
|
| 136 | 136 | { return null; } |
| 137 | 137 | |
| 138 | - $result= $result[$key]; |
|
| 138 | + $result=$result[ $key ]; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | return $result; |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | }else{ |
| 166 | 166 | if( !strlen($path) ) |
| 167 | 167 | { return $this->basePath.'/'.$filePath; } |
| 168 | - elseif( '/'===substr($path,-1) ) |
|
| 168 | + elseif( '/'===substr($path, -1) ) |
|
| 169 | 169 | { return $path.$filePath; } |
| 170 | 170 | else |
| 171 | 171 | { return $path.'/'.$filePath; } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | public function getFileContent( string$filePath ):string |
| 183 | 183 | { |
| 184 | - return isset($this->fileGetter) ? $this->fileGetter($filePath) : file_get_contents($filePath); |
|
| 184 | + return isset($this->fileGetter)? $this->fileGetter($filePath) : file_get_contents($filePath); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -123,7 +123,7 @@ |
||
| 123 | 123 | /** |
| 124 | 124 | * Getting the config of Htsl. |
| 125 | 125 | * |
| 126 | - * @param string $keys |
|
| 126 | + * @param string[] $keys |
|
| 127 | 127 | * |
| 128 | 128 | * @return mixed |
| 129 | 129 | */ |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | { |
| 17 | 17 | if( is_callable([static::class, $setter= 'set'.implode('',array_map('ucfirst',explode('_',$attribute))),]) ){ |
| 18 | 18 | return static::$setter($value); |
| 19 | - }else{ |
|
| 19 | + } else{ |
|
| 20 | 20 | throw new \Exception(static::class.' has no attribute named '.$attribute); |
| 21 | 21 | } |
| 22 | 22 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | public function __set( $attribute, $value ) |
| 16 | 16 | { |
| 17 | - if( is_callable([static::class, $setter= 'set'.implode('',array_map('ucfirst',explode('_',$attribute))),]) ){ |
|
| 17 | + if( is_callable([ static::class, $setter='set'.implode('', array_map('ucfirst', explode('_', $attribute))), ]) ){ |
|
| 18 | 18 | return static::$setter($value); |
| 19 | 19 | }else{ |
| 20 | 20 | throw new \Exception(static::class.' has no attribute named '.$attribute); |
@@ -165,7 +165,7 @@ |
||
| 165 | 165 | return $this; |
| 166 | 166 | } |
| 167 | 167 | return $this->lineByLine() |
| 168 | - ->bubbleSections() |
|
| 168 | + ->bubbleSections() |
|
| 169 | 169 | ; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $this->parent= $parent; |
| 150 | 150 | $this->docType= $parent->docType; |
| 151 | 151 | $this->indentation= $parent->indentation; |
| 152 | - }else{ |
|
| 152 | + } else{ |
|
| 153 | 153 | $this->parseFirstLine(); |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | { |
| 189 | 189 | if( $this->parent ){ |
| 190 | 190 | return $this->execute()->parent->getContent(); |
| 191 | - }else{ |
|
| 191 | + } else{ |
|
| 192 | 192 | return $this->execute()->content; |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | if( $this->embedment ){ |
| 309 | 309 | $this->embeddingParse($line); |
| 310 | - }else{ |
|
| 310 | + } else{ |
|
| 311 | 311 | $this->parseLine($line); |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | { |
| 333 | 333 | if( $line->content==='<}' ){ |
| 334 | 334 | $this->breakEmbedding(); |
| 335 | - }else{ |
|
| 335 | + } else{ |
|
| 336 | 336 | $this->embedment->parseLine($line->getSubIndentLine()); |
| 337 | 337 | } |
| 338 | 338 | return $this; |
@@ -386,8 +386,7 @@ discard block |
||
| 386 | 386 | }break; |
| 387 | 387 | case '`':{ |
| 388 | 388 | if( '='===$line->getChar(1) ) |
| 389 | - { $this->parseExpressionHtmlLine($line); } |
|
| 390 | - else |
|
| 389 | + { $this->parseExpressionHtmlLine($line); } else |
|
| 391 | 390 | { $this->parseHtmlLine($line); } |
| 392 | 391 | }break; |
| 393 | 392 | case '=':{ |
@@ -738,9 +737,9 @@ discard block |
||
| 738 | 737 | |
| 739 | 738 | if( $level<=0 ){ |
| 740 | 739 | $this->closeNodes(-$level); |
| 741 | - }elseif( $level==1 ){ |
|
| 740 | + } elseif( $level==1 ){ |
|
| 742 | 741 | $this->level+= 1; |
| 743 | - }else{ |
|
| 742 | + } else{ |
|
| 744 | 743 | $this->throw('Indent error.'); |
| 745 | 744 | } |
| 746 | 745 | |
@@ -772,7 +771,9 @@ discard block |
||
| 772 | 771 | */ |
| 773 | 772 | protected function closeNodes( int$level=0 ):self |
| 774 | 773 | { |
| 775 | - if( empty($this->openedNodes) ) return $this; |
|
| 774 | + if( empty($this->openedNodes) ){ |
|
| 775 | + return $this; |
|
| 776 | + } |
|
| 776 | 777 | |
| 777 | 778 | while( $level-->=0 ){ |
| 778 | 779 | $node= array_pop($this->openedNodes); |
@@ -850,7 +851,7 @@ discard block |
||
| 850 | 851 | { |
| 851 | 852 | if( $this->currentSection ){ |
| 852 | 853 | $this->currentSection->append($content); |
| 853 | - }else{ |
|
| 854 | + } else{ |
|
| 854 | 855 | $this->content.=$content; |
| 855 | 856 | } |
| 856 | 857 | |
@@ -212,7 +212,7 @@ |
||
| 212 | 212 | * |
| 213 | 213 | * @param [ string, ] ...$keys |
| 214 | 214 | * |
| 215 | - * @return mixed |
|
| 215 | + * @return string |
|
| 216 | 216 | */ |
| 217 | 217 | public function getConfig( string...$keys ) |
| 218 | 218 | { |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @var int |
| 92 | 92 | */ |
| 93 | - private $level= 0; |
|
| 93 | + private $level=0; |
|
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * Section indent level. |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @var int |
| 101 | 101 | */ |
| 102 | - private $sectionLevel= 0; |
|
| 102 | + private $sectionLevel=0; |
|
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | 105 | * Opened nodes. |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @var [ Htsl\Parser\Node\Contracts\ANode, ] |
| 110 | 110 | */ |
| 111 | - private $openedNodes= []; |
|
| 111 | + private $openedNodes=[ ]; |
|
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Current scopes. |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @var [ Htsl\Parser\Node\Contracts\ANode, ] |
| 119 | 119 | */ |
| 120 | - private $scopes= []; |
|
| 120 | + private $scopes=[ ]; |
|
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * Current line number. |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @var int |
| 128 | 128 | */ |
| 129 | - private $lineNumber= 0; |
|
| 129 | + private $lineNumber=0; |
|
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * Current line. |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @var [ Htsl\Parser\Section, ] |
| 146 | 146 | */ |
| 147 | - private $sections=[]; |
|
| 147 | + private $sections=[ ]; |
|
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | 150 | * Whether the document is executed. |
@@ -184,13 +184,13 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function __construct( Htsl$htsl, Buffer$buffer, self$parent=null ) |
| 186 | 186 | { |
| 187 | - $this->htsl= $htsl; |
|
| 188 | - $this->buffer= $buffer; |
|
| 187 | + $this->htsl=$htsl; |
|
| 188 | + $this->buffer=$buffer; |
|
| 189 | 189 | |
| 190 | 190 | if( $parent ){ |
| 191 | - $this->parent= $parent; |
|
| 192 | - $this->docType= $parent->docType; |
|
| 193 | - $this->indentation= $parent->indentation; |
|
| 191 | + $this->parent=$parent; |
|
| 192 | + $this->docType=$parent->docType; |
|
| 193 | + $this->indentation=$parent->indentation; |
|
| 194 | 194 | }else{ |
| 195 | 195 | $this->parseFirstLine(); |
| 196 | 196 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | protected function getLine():Line |
| 252 | 252 | { |
| 253 | 253 | do{ |
| 254 | - $line= $this->buffer->getLine(); |
|
| 254 | + $line=$this->buffer->getLine(); |
|
| 255 | 255 | }while( $line->isEmpty() && $line->hasMore() ); |
| 256 | 256 | |
| 257 | 257 | return $line; |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | */ |
| 269 | 269 | public function getConfig( string...$keys ) |
| 270 | 270 | { |
| 271 | - return $this->htsl->getConfig(array_shift($keys),$this->docType,...$keys); |
|
| 271 | + return $this->htsl->getConfig(array_shift($keys), $this->docType, ...$keys); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -316,16 +316,16 @@ discard block |
||
| 316 | 316 | */ |
| 317 | 317 | protected function parseFirstLine():self |
| 318 | 318 | { |
| 319 | - $line= $this->getLine(); |
|
| 319 | + $line=$this->getLine(); |
|
| 320 | 320 | |
| 321 | 321 | if( '@'===$line->getChar(0) ){ |
| 322 | 322 | return $this->setExtending($line); |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - $this->docType= $line->content; |
|
| 326 | - $docTypeContent= $this->getConfig('doc_types') or $this->throw("DocType $this->docType is not supported"); |
|
| 325 | + $this->docType=$line->content; |
|
| 326 | + $docTypeContent=$this->getConfig('doc_types') or $this->throw("DocType $this->docType is not supported"); |
|
| 327 | 327 | |
| 328 | - $this->indentation= $this->htsl->getConfig('indentation',$this->docType) ?? ( function( $scalarOrFalse ){ return is_scalar($scalarOrFalse)?$scalarOrFalse:false; } )($this->htsl->getConfig('indentation')); |
|
| 328 | + $this->indentation=$this->htsl->getConfig('indentation', $this->docType) ?? (function( $scalarOrFalse ){ return is_scalar($scalarOrFalse)? $scalarOrFalse : false; } )($this->htsl->getConfig('indentation')); |
|
| 329 | 329 | |
| 330 | 330 | $this->appendLine($docTypeContent); |
| 331 | 331 | |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | */ |
| 344 | 344 | protected function setExtending( Line$firstLine ):self |
| 345 | 345 | { |
| 346 | - switch( $name= $firstLine->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
| 346 | + switch( $name=$firstLine->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
| 347 | 347 | default:{ |
| 348 | 348 | $this->throw("The @$name is not supported."); |
| 349 | 349 | }break; |
@@ -369,8 +369,8 @@ discard block |
||
| 369 | 369 | */ |
| 370 | 370 | protected function lineByLine():self |
| 371 | 371 | { |
| 372 | - while( ($line= $this->getLine())->hasMore() ){ |
|
| 373 | - $this->lineNumber+= 1; |
|
| 372 | + while( ($line=$this->getLine())->hasMore() ){ |
|
| 373 | + $this->lineNumber+=1; |
|
| 374 | 374 | |
| 375 | 375 | if( $this->embedment ){ |
| 376 | 376 | $this->embeddingParse($line); |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | |
| 384 | 384 | $this->closeNodes($this->level); |
| 385 | 385 | |
| 386 | - $this->isExecuted= true; |
|
| 386 | + $this->isExecuted=true; |
|
| 387 | 387 | |
| 388 | 388 | return $this; |
| 389 | 389 | } |
@@ -418,10 +418,10 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | protected function startEmbedding( string$embedType ):self |
| 420 | 420 | { |
| 421 | - $embedmentClass= '\\Htsl\\Embedment\\'.ucfirst($embedType).'Embedment'; |
|
| 421 | + $embedmentClass='\\Htsl\\Embedment\\'.ucfirst($embedType).'Embedment'; |
|
| 422 | 422 | class_exists($embedmentClass) or $this->throw("Embed type $embedType not exists."); |
| 423 | 423 | |
| 424 | - $this->embedment= new $embedmentClass($this); |
|
| 424 | + $this->embedment=new $embedmentClass($this); |
|
| 425 | 425 | |
| 426 | 426 | return $this; |
| 427 | 427 | } |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | public function breakEmbedding():self |
| 437 | 437 | { |
| 438 | 438 | $this->append($this->embedment->getContent()); |
| 439 | - $this->embedment= null; |
|
| 439 | + $this->embedment=null; |
|
| 440 | 440 | |
| 441 | 441 | return $this; |
| 442 | 442 | } |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | */ |
| 453 | 453 | protected function parseLine( Line$line ):self |
| 454 | 454 | { |
| 455 | - $this->currentLine= $line; |
|
| 455 | + $this->currentLine=$line; |
|
| 456 | 456 | $this->setLevel($line->getIndentLevel()); |
| 457 | 457 | |
| 458 | 458 | switch( $line->getChar(0) ){ |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | */ |
| 496 | 496 | protected function parseHtmlLine( Line$line ):self |
| 497 | 497 | { |
| 498 | - $node= new StringNode($this,$line); |
|
| 498 | + $node=new StringNode($this, $line); |
|
| 499 | 499 | |
| 500 | 500 | $this->openNode($node); |
| 501 | 501 | |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | */ |
| 516 | 516 | protected function parseStringLine( Line$line ):self |
| 517 | 517 | { |
| 518 | - $node= new StringNode($this,$line); |
|
| 518 | + $node=new StringNode($this, $line); |
|
| 519 | 519 | |
| 520 | 520 | $this->openNode($node); |
| 521 | 521 | |
@@ -535,13 +535,13 @@ discard block |
||
| 535 | 535 | */ |
| 536 | 536 | protected function parseExpressionLine( Line$line ):self |
| 537 | 537 | { |
| 538 | - $node= new StringNode($this,$line); |
|
| 538 | + $node=new StringNode($this, $line); |
|
| 539 | 539 | |
| 540 | 540 | $this->openNode($node); |
| 541 | 541 | |
| 542 | - $content= $line->slice(1); |
|
| 543 | - $ent_flag= var_export($this->htsl->getConfig('ENT_flags',$this->docType),true); |
|
| 544 | - $charset= var_export($this->htsl->getConfig('charset'),true); |
|
| 542 | + $content=$line->slice(1); |
|
| 543 | + $ent_flag=var_export($this->htsl->getConfig('ENT_flags', $this->docType), true); |
|
| 544 | + $charset=var_export($this->htsl->getConfig('charset'), true); |
|
| 545 | 545 | |
| 546 | 546 | $this->appendLine("<?=htmlentities($content,$ent_flag,$charset,false)?>"); |
| 547 | 547 | |
@@ -559,11 +559,11 @@ discard block |
||
| 559 | 559 | */ |
| 560 | 560 | protected function parseExpressionHtmlLine( Line$line ):self |
| 561 | 561 | { |
| 562 | - $node= new StringNode($this,$line); |
|
| 562 | + $node=new StringNode($this, $line); |
|
| 563 | 563 | |
| 564 | 564 | $this->openNode($node); |
| 565 | 565 | |
| 566 | - $content= $line->slice(1); |
|
| 566 | + $content=$line->slice(1); |
|
| 567 | 567 | |
| 568 | 568 | $this->appendLine("<?$content?>"); |
| 569 | 569 | |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | */ |
| 582 | 582 | protected function parseCommentLine( Line$line ):self |
| 583 | 583 | { |
| 584 | - $node= new CommentNode($this,$line); |
|
| 584 | + $node=new CommentNode($this, $line); |
|
| 585 | 585 | |
| 586 | 586 | $this->openNode($node); |
| 587 | 587 | |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | */ |
| 602 | 602 | protected function parseTagLine( Line$line ):self |
| 603 | 603 | { |
| 604 | - $tag= new TagNode($this,$line); |
|
| 604 | + $tag=new TagNode($this, $line); |
|
| 605 | 605 | |
| 606 | 606 | $this->appendLine($tag->open()); |
| 607 | 607 | |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | */ |
| 624 | 624 | protected function parseControlLine( Line$line ):self |
| 625 | 625 | { |
| 626 | - $controlStructure= new ControlNode($this,$line); |
|
| 626 | + $controlStructure=new ControlNode($this, $line); |
|
| 627 | 627 | |
| 628 | 628 | $this->appendLine($controlStructure->open()); |
| 629 | 629 | |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | */ |
| 644 | 644 | protected function parseDocControlLine( Line$line ):self |
| 645 | 645 | { |
| 646 | - switch( $name= $line->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
| 646 | + switch( $name=$line->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
| 647 | 647 | default:{ |
| 648 | 648 | $this->throw("The @$name is not supported."); |
| 649 | 649 | }break; |
@@ -675,10 +675,10 @@ discard block |
||
| 675 | 675 | */ |
| 676 | 676 | protected function extend( string$fileName ):self |
| 677 | 677 | { |
| 678 | - $this->parent= new static($this->htsl,$this->buffer->goSide($fileName)); |
|
| 678 | + $this->parent=new static($this->htsl, $this->buffer->goSide($fileName)); |
|
| 679 | 679 | |
| 680 | - $this->docType= $this->parent->docType; |
|
| 681 | - $this->indentation= $this->parent->indentation; |
|
| 680 | + $this->docType=$this->parent->docType; |
|
| 681 | + $this->indentation=$this->parent->indentation; |
|
| 682 | 682 | |
| 683 | 683 | return $this; |
| 684 | 684 | } |
@@ -692,15 +692,15 @@ discard block |
||
| 692 | 692 | * |
| 693 | 693 | * @return \Htsl\Parser\Document |
| 694 | 694 | */ |
| 695 | - protected function include( Line$line ):self |
|
| 695 | + protected function include(Line$line):self |
|
| 696 | 696 | { |
| 697 | - $inclued= (new static($this->htsl,$this->buffer->goSide($line->pregGet('/(?<=\( ).*(?= \))/')),$this))->execute()->content; |
|
| 697 | + $inclued=(new static($this->htsl, $this->buffer->goSide($line->pregGet('/(?<=\( ).*(?= \))/')), $this))->execute()->content; |
|
| 698 | 698 | |
| 699 | 699 | if( false!==$this->indentation ){ |
| 700 | - $inclued= preg_replace('/(?<=^|\\n)(?!$)/',str_repeat($this->indentation,$this->level-$this->sectionLevel),$inclued); |
|
| 700 | + $inclued=preg_replace('/(?<=^|\\n)(?!$)/', str_repeat($this->indentation, $this->level-$this->sectionLevel), $inclued); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | - $node= new StringNode($this,$line); |
|
| 703 | + $node=new StringNode($this, $line); |
|
| 704 | 704 | |
| 705 | 705 | $this->openNode($node); |
| 706 | 706 | |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | */ |
| 721 | 721 | protected function defineSection( Line$line ):self |
| 722 | 722 | { |
| 723 | - $node= new SectionNode($this,$line); |
|
| 723 | + $node=new SectionNode($this, $line); |
|
| 724 | 724 | |
| 725 | 725 | $node->open(); |
| 726 | 726 | |
@@ -740,22 +740,22 @@ discard block |
||
| 740 | 740 | */ |
| 741 | 741 | protected function showSection( Line$line ):self |
| 742 | 742 | { |
| 743 | - $sectionName= $line->pregGet('/(?<=\( ).*(?= \))/'); |
|
| 743 | + $sectionName=$line->pregGet('/(?<=\( ).*(?= \))/'); |
|
| 744 | 744 | |
| 745 | - if( !isset($this->sections[$sectionName]) ){ |
|
| 746 | - $this->openNode(new StringNode($this,$line)); |
|
| 745 | + if( !isset($this->sections[ $sectionName ]) ){ |
|
| 746 | + $this->openNode(new StringNode($this, $line)); |
|
| 747 | 747 | |
| 748 | 748 | return $this; |
| 749 | 749 | } |
| 750 | - $content= $this->sections[$sectionName]->content; |
|
| 750 | + $content=$this->sections[ $sectionName ]->content; |
|
| 751 | 751 | |
| 752 | 752 | if( false!==$this->indentation ){ |
| 753 | - $content= preg_replace('/(?<=^|\\n)(?!$)/',str_repeat($this->indentation,$this->level),$content); |
|
| 753 | + $content=preg_replace('/(?<=^|\\n)(?!$)/', str_repeat($this->indentation, $this->level), $content); |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | $this->append($content); |
| 757 | 757 | |
| 758 | - $node= new NamelessSectionNode($this,$line); |
|
| 758 | + $node=new NamelessSectionNode($this, $line); |
|
| 759 | 759 | |
| 760 | 760 | $node->open(); |
| 761 | 761 | |
@@ -774,8 +774,8 @@ discard block |
||
| 774 | 774 | public function setSection( Section$section=null ):self |
| 775 | 775 | { |
| 776 | 776 | if( !$section ){ |
| 777 | - $this->sectionLevel= 0; |
|
| 778 | - $this->currentSection= null; |
|
| 777 | + $this->sectionLevel=0; |
|
| 778 | + $this->currentSection=null; |
|
| 779 | 779 | |
| 780 | 780 | return $this; |
| 781 | 781 | } |
@@ -784,17 +784,17 @@ discard block |
||
| 784 | 784 | $this->throw('Nesting definition of section is forbidden.'); |
| 785 | 785 | } |
| 786 | 786 | |
| 787 | - if( isset($this->parent->sections[$section->name]) ){ |
|
| 787 | + if( isset($this->parent->sections[ $section->name ]) ){ |
|
| 788 | 788 | $this->throw("Section {$section->name} already defined."); |
| 789 | 789 | } |
| 790 | 790 | |
| 791 | - $this->currentSection= $section; |
|
| 791 | + $this->currentSection=$section; |
|
| 792 | 792 | |
| 793 | 793 | if( $section->name ){ |
| 794 | - $this->parent->sections[$section->name]=$section; |
|
| 794 | + $this->parent->sections[ $section->name ]=$section; |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | - $this->sectionLevel= $this->level+1; |
|
| 797 | + $this->sectionLevel=$this->level+1; |
|
| 798 | 798 | |
| 799 | 799 | return $this; |
| 800 | 800 | } |
@@ -810,8 +810,8 @@ discard block |
||
| 810 | 810 | { |
| 811 | 811 | if( $this->parent ){ |
| 812 | 812 | foreach( $this->sections as $name=>$section ){ |
| 813 | - if( !isset($this->parent->sections[$name]) ){ |
|
| 814 | - $this->parent->sections[$name]=$section; |
|
| 813 | + if( !isset($this->parent->sections[ $name ]) ){ |
|
| 814 | + $this->parent->sections[ $name ]=$section; |
|
| 815 | 815 | }; |
| 816 | 816 | } |
| 817 | 817 | } |
@@ -830,7 +830,7 @@ discard block |
||
| 830 | 830 | */ |
| 831 | 831 | public function htmlEntities( string$input ):string |
| 832 | 832 | { |
| 833 | - return htmlentities($input,$this->htsl->getConfig('ENT_flags',$this->docType),$this->htsl->getConfig('charset'),false); |
|
| 833 | + return htmlentities($input, $this->htsl->getConfig('ENT_flags', $this->docType), $this->htsl->getConfig('charset'), false); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | /** |
@@ -842,12 +842,12 @@ discard block |
||
| 842 | 842 | */ |
| 843 | 843 | protected function setLevel( int$level ):self |
| 844 | 844 | { |
| 845 | - $level-= $this->level; |
|
| 845 | + $level-=$this->level; |
|
| 846 | 846 | |
| 847 | 847 | if( $level<=0 ){ |
| 848 | 848 | $this->closeNodes(-$level); |
| 849 | 849 | }elseif( $level==1 ){ |
| 850 | - $this->level+= 1; |
|
| 850 | + $this->level+=1; |
|
| 851 | 851 | }else{ |
| 852 | 852 | $this->throw('Indent error.'); |
| 853 | 853 | } |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | */ |
| 867 | 867 | protected function openNode( Node$node ):self |
| 868 | 868 | { |
| 869 | - array_push($this->openedNodes,$node); |
|
| 869 | + array_push($this->openedNodes, $node); |
|
| 870 | 870 | |
| 871 | 871 | $node->scope and $this->setScope($node); |
| 872 | 872 | |
@@ -887,13 +887,13 @@ discard block |
||
| 887 | 887 | if( empty($this->openedNodes) ) return $this; |
| 888 | 888 | |
| 889 | 889 | while( $level-->=0 ){ |
| 890 | - $node= array_pop($this->openedNodes); |
|
| 890 | + $node=array_pop($this->openedNodes); |
|
| 891 | 891 | |
| 892 | 892 | $node->scope and $this->removeScope($node); |
| 893 | 893 | |
| 894 | 894 | $closer=$node->close($this->currentLine) and $this->appendLine($closer); |
| 895 | 895 | |
| 896 | - $this->level-= $level>=0 ?1:0; |
|
| 896 | + $this->level-=$level>=0? 1 : 0; |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | return $this; |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | */ |
| 909 | 909 | protected function setScope( Node$scope ):int |
| 910 | 910 | { |
| 911 | - return array_unshift($this->scopes,$scope); |
|
| 911 | + return array_unshift($this->scopes, $scope); |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | /** |
@@ -920,7 +920,7 @@ discard block |
||
| 920 | 920 | */ |
| 921 | 921 | public function getScope() |
| 922 | 922 | { |
| 923 | - return $this->scopes[0]??null; |
|
| 923 | + return $this->scopes[ 0 ]??null; |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | /** |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | protected function appendLine( string$content ):self |
| 954 | 954 | { |
| 955 | 955 | if( false!==$this->indentation ){ |
| 956 | - $content= str_repeat($this->indentation,$this->level-$this->sectionLevel).$content."\n"; |
|
| 956 | + $content=str_repeat($this->indentation, $this->level-$this->sectionLevel).$content."\n"; |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | return $this->append($content); |
@@ -1000,7 +1000,7 @@ discard block |
||
| 1000 | 1000 | * |
| 1001 | 1001 | * @throw \Htsl\Parser\HtslParsingException |
| 1002 | 1002 | */ |
| 1003 | - public function throw( string$message ) |
|
| 1003 | + public function throw(string$message) |
|
| 1004 | 1004 | { |
| 1005 | 1005 | throw new HtslParsingException("$message at file {$this->buffer->fileName} line $this->lineNumber"); |
| 1006 | 1006 | } |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | $this->docType= $line->content; |
| 326 | - $docTypeContent= $this->getConfig('doc_types') or $this->throw("DocType $this->docType is not supported"); |
|
| 326 | + $docTypeContent= $this->getConfig('doc_types') or $this->throw("doctype $this->docType is not supported"); |
|
| 327 | 327 | |
| 328 | 328 | $this->indentation= $this->htsl->getConfig('indentation',$this->docType) ?? ( function( $scalarOrFalse ){ return is_scalar($scalarOrFalse)?$scalarOrFalse:false; } )($this->htsl->getConfig('indentation')); |
| 329 | 329 | |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | if( isset($this->parent->sections[$section->name]) ){ |
| 788 | - $this->throw("Section {$section->name} already defined."); |
|
| 788 | + $this->throw("section {$section->name} already defined."); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | $this->currentSection= $section; |
@@ -36,8 +36,8 @@ |
||
| 36 | 36 | public function open():string |
| 37 | 37 | { |
| 38 | 38 | return $this->htmlComment ? |
| 39 | - '<!--'.str_replace('-->','--'.chr(0xC).'>',substr($this->line->getContent(),1)): |
|
| 40 | - '<?php /* '.substr($this->line->getContent(),2); |
|
| 39 | + '<!--'.str_replace('-->','--'.chr(0xC).'>',substr($this->line->getContent(),1)): |
|
| 40 | + '<?php /* '.substr($this->line->getContent(),2); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | protected function construct():parent |
| 26 | 26 | { |
| 27 | - $this->htmlComment= '!'!==$this->line->getChar(1); |
|
| 27 | + $this->htmlComment='!'!==$this->line->getChar(1); |
|
| 28 | 28 | return $this; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -35,9 +35,8 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function open():string |
| 37 | 37 | { |
| 38 | - return $this->htmlComment ? |
|
| 39 | - '<!--'.str_replace('-->','--'.chr(0xC).'>',substr($this->line->getContent(),1)): |
|
| 40 | - '<?php /* '.substr($this->line->getContent(),2); |
|
| 38 | + return $this->htmlComment? |
|
| 39 | + '<!--'.str_replace('-->', '--'.chr(0xC).'>', substr($this->line->getContent(), 1)) : '<?php /* '.substr($this->line->getContent(), 2); |
|
| 41 | 40 | } |
| 42 | 41 | |
| 43 | 42 | /** |
@@ -49,6 +48,6 @@ discard block |
||
| 49 | 48 | */ |
| 50 | 49 | public function close( Line$closerLine ):string |
| 51 | 50 | { |
| 52 | - return $this->htmlComment ? '-->' : ' */ ?>'; |
|
| 51 | + return $this->htmlComment? '-->' : ' */ ?>'; |
|
| 53 | 52 | } |
| 54 | 53 | } |