Complex classes like Compiler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Compiler, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class Compiler { |
||
| 16 | const T_IF = 'x-if'; |
||
|
|
|||
| 17 | const T_EACH = 'x-each'; |
||
| 18 | const T_WITH = 'x-with'; |
||
| 19 | const T_LITERAL = 'x-literal'; |
||
| 20 | const T_AS = 'x-as'; |
||
| 21 | const T_COMPONENT = 'x-component'; |
||
| 22 | const T_CHILDREN = 'x-children'; |
||
| 23 | const T_BLOCK = 'x-block'; |
||
| 24 | const T_ELSE = 'x-else'; |
||
| 25 | const T_EMPTY = 'x-empty'; |
||
| 26 | const T_X = 'x'; |
||
| 27 | const T_INCLUDE = 'x-include'; |
||
| 28 | const T_EBI = 'ebi'; |
||
| 29 | const T_UNESCAPE = 'x-unescape'; |
||
| 30 | const T_TAG = 'x-tag'; |
||
| 31 | |||
| 32 | const IDENT_REGEX = '`^([a-z0-9-]+)$`i'; |
||
| 33 | |||
| 34 | protected static $special = [ |
||
| 35 | self::T_COMPONENT => 1, |
||
| 36 | self::T_IF => 2, |
||
| 37 | self::T_ELSE => 3, |
||
| 38 | self::T_EACH => 4, |
||
| 39 | self::T_EMPTY => 5, |
||
| 40 | self::T_CHILDREN => 6, |
||
| 41 | self::T_INCLUDE => 7, |
||
| 42 | self::T_WITH => 8, |
||
| 43 | self::T_BLOCK => 9, |
||
| 44 | self::T_LITERAL => 10, |
||
| 45 | self::T_AS => 11, |
||
| 46 | self::T_UNESCAPE => 12, |
||
| 47 | self::T_TAG => 13 |
||
| 48 | ]; |
||
| 49 | |||
| 50 | protected static $htmlTags = [ |
||
| 51 | 'a' => 'i', |
||
| 52 | 'abbr' => 'i', |
||
| 53 | 'acronym' => 'i', // deprecated |
||
| 54 | 'address' => 'b', |
||
| 55 | // 'applet' => 'i', // deprecated |
||
| 56 | 'area' => 'i', |
||
| 57 | 'article' => 'b', |
||
| 58 | 'aside' => 'b', |
||
| 59 | 'audio' => 'i', |
||
| 60 | 'b' => 'i', |
||
| 61 | 'base' => 'i', |
||
| 62 | // 'basefont' => 'i', |
||
| 63 | 'bdi' => 'i', |
||
| 64 | 'bdo' => 'i', |
||
| 65 | // 'bgsound' => 'i', |
||
| 66 | // 'big' => 'i', |
||
| 67 | 'x' => 'i', |
||
| 68 | // 'blink' => 'i', |
||
| 69 | 'blockquote' => 'b', |
||
| 70 | 'body' => 'b', |
||
| 71 | 'br' => 'i', |
||
| 72 | 'button' => 'i', |
||
| 73 | 'canvas' => 'b', |
||
| 74 | 'caption' => 'i', |
||
| 75 | // 'center' => 'b', |
||
| 76 | 'cite' => 'i', |
||
| 77 | 'code' => 'i', |
||
| 78 | 'col' => 'i', |
||
| 79 | 'colgroup' => 'i', |
||
| 80 | // 'command' => 'i', |
||
| 81 | 'content' => 'i', |
||
| 82 | 'data' => 'i', |
||
| 83 | 'datalist' => 'i', |
||
| 84 | 'dd' => 'b', |
||
| 85 | 'del' => 'i', |
||
| 86 | 'details' => 'i', |
||
| 87 | 'dfn' => 'i', |
||
| 88 | 'dialog' => 'i', |
||
| 89 | // 'dir' => 'i', |
||
| 90 | 'div' => 'i', |
||
| 91 | 'dl' => 'b', |
||
| 92 | 'dt' => 'b', |
||
| 93 | // 'element' => 'i', |
||
| 94 | 'em' => 'i', |
||
| 95 | 'embed' => 'i', |
||
| 96 | 'fieldset' => 'b', |
||
| 97 | 'figcaption' => 'b', |
||
| 98 | 'figure' => 'b', |
||
| 99 | // 'font' => 'i', |
||
| 100 | 'footer' => 'b', |
||
| 101 | 'form' => 'b', |
||
| 102 | 'frame' => 'i', |
||
| 103 | 'frameset' => 'i', |
||
| 104 | 'h1' => 'b', |
||
| 105 | 'h2' => 'b', |
||
| 106 | 'h3' => 'b', |
||
| 107 | 'h4' => 'b', |
||
| 108 | 'h5' => 'b', |
||
| 109 | 'h6' => 'b', |
||
| 110 | 'head' => 'b', |
||
| 111 | 'header' => 'b', |
||
| 112 | 'hgroup' => 'b', |
||
| 113 | 'hr' => 'b', |
||
| 114 | 'html' => 'b', |
||
| 115 | 'i' => 'i', |
||
| 116 | 'iframe' => 'i', |
||
| 117 | 'image' => 'i', |
||
| 118 | 'img' => 'i', |
||
| 119 | 'input' => 'i', |
||
| 120 | 'ins' => 'i', |
||
| 121 | 'isindex' => 'i', |
||
| 122 | 'kbd' => 'i', |
||
| 123 | 'keygen' => 'i', |
||
| 124 | 'label' => 'i', |
||
| 125 | 'legend' => 'i', |
||
| 126 | 'li' => 'i', |
||
| 127 | 'link' => 'i', |
||
| 128 | // 'listing' => 'i', |
||
| 129 | 'main' => 'b', |
||
| 130 | 'map' => 'i', |
||
| 131 | 'mark' => 'i', |
||
| 132 | // 'marquee' => 'i', |
||
| 133 | 'menu' => 'i', |
||
| 134 | 'menuitem' => 'i', |
||
| 135 | 'meta' => 'i', |
||
| 136 | 'meter' => 'i', |
||
| 137 | 'multicol' => 'i', |
||
| 138 | 'nav' => 'b', |
||
| 139 | 'nobr' => 'i', |
||
| 140 | 'noembed' => 'i', |
||
| 141 | 'noframes' => 'i', |
||
| 142 | 'noscript' => 'b', |
||
| 143 | 'object' => 'i', |
||
| 144 | 'ol' => 'b', |
||
| 145 | 'optgroup' => 'i', |
||
| 146 | 'option' => 'b', |
||
| 147 | 'output' => 'i', |
||
| 148 | 'p' => 'b', |
||
| 149 | 'param' => 'i', |
||
| 150 | 'picture' => 'i', |
||
| 151 | // 'plaintext' => 'i', |
||
| 152 | 'pre' => 'b', |
||
| 153 | 'progress' => 'i', |
||
| 154 | 'q' => 'i', |
||
| 155 | 'rp' => 'i', |
||
| 156 | 'rt' => 'i', |
||
| 157 | 'rtc' => 'i', |
||
| 158 | 'ruby' => 'i', |
||
| 159 | 's' => 'i', |
||
| 160 | 'samp' => 'i', |
||
| 161 | 'script' => 'i', |
||
| 162 | 'section' => 'b', |
||
| 163 | 'select' => 'i', |
||
| 164 | // 'shadow' => 'i', |
||
| 165 | 'slot' => 'i', |
||
| 166 | 'small' => 'i', |
||
| 167 | 'source' => 'i', |
||
| 168 | // 'spacer' => 'i', |
||
| 169 | 'span' => 'i', |
||
| 170 | // 'strike' => 'i', |
||
| 171 | 'strong' => 'i', |
||
| 172 | 'style' => 'i', |
||
| 173 | 'sub' => 'i', |
||
| 174 | 'summary' => 'i', |
||
| 175 | 'sup' => 'i', |
||
| 176 | 'table' => 'b', |
||
| 177 | 'tbody' => 'i', |
||
| 178 | 'td' => 'i', |
||
| 179 | 'template' => 'i', |
||
| 180 | 'textarea' => 'i', |
||
| 181 | 'tfoot' => 'b', |
||
| 182 | 'th' => 'i', |
||
| 183 | 'thead' => 'i', |
||
| 184 | 'time' => 'i', |
||
| 185 | 'title' => 'i', |
||
| 186 | 'tr' => 'i', |
||
| 187 | 'track' => 'i', |
||
| 188 | // 'tt' => 'i', |
||
| 189 | 'u' => 'i', |
||
| 190 | 'ul' => 'b', |
||
| 191 | 'var' => 'i', |
||
| 192 | 'video' => 'b', |
||
| 193 | 'wbr' => 'i', |
||
| 194 | |||
| 195 | /// SVG /// |
||
| 196 | 'animate' => 's', |
||
| 197 | 'animateColor' => 's', |
||
| 198 | 'animateMotion' => 's', |
||
| 199 | 'animateTransform' => 's', |
||
| 200 | // 'canvas' => 's', |
||
| 201 | 'circle' => 's', |
||
| 202 | 'desc' => 's', |
||
| 203 | 'defs' => 's', |
||
| 204 | 'discard' => 's', |
||
| 205 | 'ellipse' => 's', |
||
| 206 | 'g' => 's', |
||
| 207 | // 'image' => 's', |
||
| 208 | 'line' => 's', |
||
| 209 | 'marker' => 's', |
||
| 210 | 'mask' => 's', |
||
| 211 | 'missing-glyph' => 's', |
||
| 212 | 'mpath' => 's', |
||
| 213 | 'metadata' => 's', |
||
| 214 | 'path' => 's', |
||
| 215 | 'pattern' => 's', |
||
| 216 | 'polygon' => 's', |
||
| 217 | 'polyline' => 's', |
||
| 218 | 'rect' => 's', |
||
| 219 | 'set' => 's', |
||
| 220 | 'svg' => 's', |
||
| 221 | 'switch' => 's', |
||
| 222 | 'symbol' => 's', |
||
| 223 | 'text' => 's', |
||
| 224 | // 'unknown' => 's', |
||
| 225 | 'use' => 's', |
||
| 226 | ]; |
||
| 227 | |||
| 228 | protected static $boolAttributes = [ |
||
| 229 | 'checked' => 1, |
||
| 230 | 'itemscope' => 1, |
||
| 231 | 'required' => 1, |
||
| 232 | 'selected' => 1, |
||
| 233 | ]; |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @var ExpressionLanguage |
||
| 237 | */ |
||
| 238 | protected $expressions; |
||
| 239 | |||
| 240 | 72 | public function __construct() { |
|
| 241 | 72 | $this->expressions = new ExpressionLanguage(); |
|
| 242 | 72 | $this->expressions->setNamePattern('/[@a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'); |
|
| 243 | 72 | $this->expressions->register( |
|
| 244 | 72 | 'hasChildren', |
|
| 245 | 72 | function ($name = null) { |
|
| 246 | 1 | return empty($name) ? 'isset($children[0])' : "isset(\$children[$name ?: 0])"; |
|
| 247 | 72 | }, |
|
| 248 | 72 | function ($name = null) { |
|
| 249 | return false; |
||
| 250 | 72 | }); |
|
| 251 | 72 | } |
|
| 252 | |||
| 253 | /** |
||
| 254 | * Register a runtime function. |
||
| 255 | * |
||
| 256 | * @param string $name The name of the function. |
||
| 257 | * @param callable $function The function callback. |
||
| 258 | */ |
||
| 259 | 70 | public function defineFunction($name, $function = null) { |
|
| 260 | 70 | if ($function === null) { |
|
| 261 | 1 | $function = $name; |
|
| 262 | } |
||
| 263 | |||
| 264 | 70 | $this->expressions->register( |
|
| 265 | 70 | $name, |
|
| 266 | 70 | $this->getFunctionCompiler($name, $function), |
|
| 267 | 70 | $this->getFunctionEvaluator($function) |
|
| 268 | ); |
||
| 269 | 70 | } |
|
| 270 | |||
| 271 | 70 | private function getFunctionEvaluator($function) { |
|
| 272 | 70 | if ($function === 'empty') { |
|
| 273 | 70 | return function ($expr) { |
|
| 274 | return empty($expr); |
||
| 275 | 70 | }; |
|
| 276 | 69 | } elseif ($function === 'isset') { |
|
| 277 | return function ($expr) { |
||
| 278 | return isset($expr); |
||
| 279 | }; |
||
| 280 | } |
||
| 281 | |||
| 282 | 69 | return $function; |
|
| 283 | } |
||
| 284 | |||
| 285 | 70 | private function getFunctionCompiler($name, $function) { |
|
| 286 | 70 | $var = var_export(strtolower($name), true); |
|
| 287 | 70 | $fn = function ($expr) use ($var) { |
|
| 288 | 1 | return "\$this->call($var, $expr)"; |
|
| 289 | 70 | }; |
|
| 290 | |||
| 291 | 70 | if (is_string($function)) { |
|
| 292 | 70 | $fn = function (...$args) use ($function) { |
|
| 293 | 14 | return $function.'('.implode(', ', $args).')'; |
|
| 294 | 70 | }; |
|
| 295 | 69 | } elseif (is_array($function)) { |
|
| 296 | 69 | if (is_string($function[0])) { |
|
| 297 | $fn = function (...$args) use ($function) { |
||
| 298 | return "$function[0]::$function[1](".implode(', ', $args).')'; |
||
| 299 | }; |
||
| 300 | 69 | } elseif ($function[0] instanceof Ebi) { |
|
| 301 | 69 | $fn = function (...$args) use ($function) { |
|
| 302 | 8 | return "\$this->$function[1](".implode(', ', $args).')'; |
|
| 303 | 69 | }; |
|
| 304 | } |
||
| 305 | } |
||
| 306 | |||
| 307 | 70 | return $fn; |
|
| 308 | } |
||
| 309 | |||
| 310 | 64 | public function compile($src, array $options = []) { |
|
| 311 | 64 | $options += ['basename' => '', 'path' => '', 'runtime' => true]; |
|
| 312 | |||
| 313 | 64 | $src = trim($src); |
|
| 314 | |||
| 315 | 64 | $out = new CompilerBuffer(); |
|
| 316 | |||
| 317 | 64 | $out->setBasename($options['basename']); |
|
| 318 | 64 | $out->setSource($src); |
|
| 319 | 64 | $out->setPath($options['path']); |
|
| 320 | |||
| 321 | 64 | $dom = new \DOMDocument(); |
|
| 322 | |||
| 323 | 64 | $fragment = false; |
|
| 324 | 64 | if (strpos($src, '<html') === false) { |
|
| 325 | 62 | $src = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html><body>$src</body></html>"; |
|
| 326 | 62 | $fragment = true; |
|
| 327 | } |
||
| 328 | |||
| 329 | 64 | libxml_use_internal_errors(true); |
|
| 330 | 64 | $dom->loadHTML($src, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOCDATA | LIBXML_NOXMLDECL); |
|
| 331 | // $arr = $this->domToArray($dom); |
||
| 332 | |||
| 333 | 64 | if ($options['runtime']) { |
|
| 334 | 63 | $name = var_export($options['basename'], true); |
|
| 335 | 63 | $out->appendCode("\$this->defineComponent($name, function (\$props = [], \$children = []) {\n"); |
|
| 336 | } else { |
||
| 337 | 1 | $out->appendCode("function (\$props = [], \$children = []) {\n"); |
|
| 338 | } |
||
| 339 | |||
| 340 | 64 | $out->pushScope(['this' => 'props']); |
|
| 341 | 64 | $out->indent(+1); |
|
| 342 | |||
| 343 | 64 | $parent = $fragment ? $dom->firstChild->nextSibling->firstChild : $dom; |
|
| 344 | |||
| 345 | 64 | foreach ($parent->childNodes as $node) { |
|
| 346 | 64 | $this->compileNode($node, $out); |
|
| 347 | } |
||
| 348 | |||
| 349 | 57 | $out->indent(-1); |
|
| 350 | 57 | $out->popScope(); |
|
| 351 | |||
| 352 | 57 | if ($options['runtime']) { |
|
| 353 | 56 | $out->appendCode("});"); |
|
| 354 | } else { |
||
| 355 | 1 | $out->appendCode("};"); |
|
| 356 | } |
||
| 357 | |||
| 358 | 57 | $r = $out->flush(); |
|
| 359 | |||
| 360 | 57 | $errs = libxml_get_errors(); |
|
| 361 | |||
| 362 | 57 | return $r; |
|
| 363 | } |
||
| 364 | |||
| 365 | 49 | protected function isComponent($tag) { |
|
| 368 | |||
| 369 | 64 | protected function compileNode(DOMNode $node, CompilerBuffer $out) { |
|
| 370 | 64 | if ($out->getNodeProp($node, 'skip')) { |
|
| 371 | 4 | return; |
|
| 372 | } |
||
| 373 | |||
| 397 | |||
| 398 | protected function domToArray(DOMNode $root) { |
||
| 435 | |||
| 436 | 1 | protected function newline(DOMNode $node, CompilerBuffer $out) { |
|
| 441 | |||
| 442 | 1 | protected function compileCommentNode(\DOMComment $node, CompilerBuffer $out) { |
|
| 450 | |||
| 451 | 53 | protected function compileTextNode(DOMNode $node, CompilerBuffer $out) { |
|
| 452 | 53 | $nodeText = $node->nodeValue; |
|
| 453 | |||
| 454 | 53 | $items = $this->splitExpressions($nodeText); |
|
| 455 | 53 | foreach ($items as $i => list($text, $offset)) { |
|
| 456 | 53 | if (preg_match('`^{\S`', $text)) { |
|
| 457 | 30 | if (preg_match('`^{\s*unescape\((.+)\)\s*}$`', $text, $m)) { |
|
| 458 | 3 | $out->echoCode($this->expr($m[1], $out)); |
|
| 459 | } else { |
||
| 460 | try { |
||
| 461 | 28 | $expr = substr($text, 1, -1); |
|
| 462 | 28 | $out->echoCode($this->compileEscape($this->expr($expr, $out))); |
|
| 463 | 1 | } catch (SyntaxError $ex) { |
|
| 464 | 1 | $nodeLineCount = substr_count($nodeText, "\n"); |
|
| 465 | 1 | $offsetLineCount = substr_count($nodeText, "\n", 0, $offset); |
|
| 466 | 1 | $line = $node->getLineNo() - $nodeLineCount + $offsetLineCount; |
|
| 467 | 30 | throw $out->createCompilerException($node, $ex, ['source' => $expr, 'line' => $line]); |
|
| 468 | } |
||
| 469 | } |
||
| 470 | } else { |
||
| 471 | 53 | if ($i === 0) { |
|
| 472 | 53 | $text = $this->ltrim($text, $node, $out); |
|
| 473 | } |
||
| 474 | 53 | if ($i === count($items) - 1) { |
|
| 475 | 53 | $text = $this->rtrim($text, $node, $out); |
|
| 476 | } |
||
| 477 | |||
| 478 | 53 | $out->echoLiteral($text); |
|
| 479 | } |
||
| 480 | } |
||
| 481 | 53 | } |
|
| 482 | |||
| 483 | 61 | protected function compileElementNode(DOMElement $node, CompilerBuffer $out) { |
|
| 484 | 61 | list($attributes, $special) = $this->splitAttributes($node); |
|
| 485 | |||
| 486 | 61 | if ($node->tagName === 'script' && ((isset($attributes['type']) && $attributes['type']->value === self::T_EBI) || !empty($special[self::T_AS]) || !empty($special[self::T_UNESCAPE]))) { |
|
| 487 | 8 | $this->compileExpressionNode($node, $attributes, $special, $out); |
|
| 488 | 54 | } elseif (!empty($special) || $this->isComponent($node->tagName)) { |
|
| 489 | 38 | $this->compileSpecialNode($node, $attributes, $special, $out); |
|
| 490 | } else { |
||
| 491 | 30 | $this->compileBasicElement($node, $attributes, $special, $out); |
|
| 492 | } |
||
| 493 | 55 | } |
|
| 494 | |||
| 495 | 53 | protected function splitExpressions($value) { |
|
| 499 | |||
| 500 | /** |
||
| 501 | * Compile the PHP for an expression |
||
| 502 | * |
||
| 503 | * @param string $expr The expression to compile. |
||
| 504 | * @param CompilerBuffer $out The current output buffer. |
||
| 505 | * @param DOMAttr|null $attr The owner of the expression. |
||
| 506 | * @return string Returns a string of PHP code. |
||
| 507 | */ |
||
| 508 | 56 | protected function expr($expr, CompilerBuffer $out, DOMAttr $attr = null) { |
|
| 535 | |||
| 536 | /** |
||
| 537 | * Get the compiler function to wrap an attribute. |
||
| 538 | * |
||
| 539 | * Attribute functions are regular expression functions, but with a special naming convention. The following naming |
||
| 540 | * conventions are supported: |
||
| 541 | * |
||
| 542 | * - **@tag:attribute**: Applies to an attribute only on a specific tag. |
||
| 543 | * - **@attribute**: Applies to all attributes with a given name. |
||
| 544 | * |
||
| 545 | * @param DOMAttr $attr The attribute to look at. |
||
| 546 | * @return callable|null A function or **null** if the attribute doesn't have a function. |
||
| 547 | */ |
||
| 548 | 31 | private function getAttributeFunction(DOMAttr $attr) { |
|
| 557 | |||
| 558 | /** |
||
| 559 | * @param DOMElement $node |
||
| 560 | */ |
||
| 561 | 61 | protected function splitAttributes(DOMElement $node) { |
|
| 579 | |||
| 580 | 38 | protected function compileSpecialNode(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 627 | |||
| 628 | /** |
||
| 629 | * Compile component registering. |
||
| 630 | * |
||
| 631 | * @param DOMElement $node |
||
| 632 | * @param $attributes |
||
| 633 | * @param $special |
||
| 634 | * @param CompilerBuffer $out |
||
| 635 | */ |
||
| 636 | 9 | public function compileComponentRegister(DOMElement $node, $attributes, $special, CompilerBuffer $out) { |
|
| 656 | |||
| 657 | 2 | private function compileBlock(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 687 | |||
| 688 | /** |
||
| 689 | * Compile component inclusion and rendering. |
||
| 690 | * |
||
| 691 | * @param DOMElement $node |
||
| 692 | * @param DOMAttr[] $attributes |
||
| 693 | * @param DOMAttr[] $special |
||
| 694 | * @param CompilerBuffer $out |
||
| 695 | */ |
||
| 696 | 11 | protected function compileComponentInclude(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 736 | |||
| 737 | /** |
||
| 738 | * @param DOMElement $parent |
||
| 739 | * @return CompilerBuffer |
||
| 740 | */ |
||
| 741 | 11 | protected function compileComponentBlocks(DOMElement $parent, CompilerBuffer $out) { |
|
| 770 | |||
| 771 | 28 | protected function compileTagComment(DOMElement $node, $attributes, $special, CompilerBuffer $out) { |
|
| 788 | |||
| 789 | /** |
||
| 790 | * @param DOMElement $node |
||
| 791 | * @param DOMAttr[] $attributes |
||
| 792 | * @param DOMAttr[] $special |
||
| 793 | * @param CompilerBuffer $out |
||
| 794 | * @param bool $force |
||
| 795 | */ |
||
| 796 | 51 | protected function compileOpenTag(DOMElement $node, $attributes, $special, CompilerBuffer $out, $force = false) { |
|
| 838 | |||
| 839 | 21 | private function isExpression($value) { |
|
| 842 | |||
| 843 | 49 | protected function compileCloseTag(DOMElement $node, $special, CompilerBuffer $out, $force = false) { |
|
| 858 | |||
| 859 | 4 | protected function isEmptyText(DOMNode $node) { |
|
| 862 | |||
| 863 | 11 | protected function isEmptyNode(DOMNode $node) { |
|
| 879 | |||
| 880 | 10 | protected function compileIf(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 908 | |||
| 909 | 15 | protected function compileEach(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 941 | |||
| 942 | 2 | protected function compileWith(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 970 | |||
| 971 | 2 | protected function compileLiteral(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 984 | |||
| 985 | 20 | protected function compileElement(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 994 | |||
| 995 | /** |
||
| 996 | * Find a special node in relation to another node. |
||
| 997 | * |
||
| 998 | * This method is used to find things such as x-empty and x-else elements. |
||
| 999 | * |
||
| 1000 | * @param DOMElement $node The node to search in relation to. |
||
| 1001 | * @param string $attribute The name of the attribute to search for. |
||
| 1002 | * @param string $parentAttribute The name of the parent attribute to resolve conflicts. |
||
| 1003 | * @return DOMElement|null Returns the found element node or **null** if not found. |
||
| 1004 | */ |
||
| 1005 | 23 | protected function findSpecialNode(DOMElement $node, $attribute, $parentAttribute) { |
|
| 1034 | |||
| 1035 | /** |
||
| 1036 | * @param DOMElement $node |
||
| 1037 | * @param array $attributes |
||
| 1038 | * @param array $special |
||
| 1039 | * @param CompilerBuffer $out |
||
| 1040 | */ |
||
| 1041 | 15 | private function compileEachLoop(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 1079 | |||
| 1080 | 53 | protected function ltrim($text, \DOMNode $node, CompilerBuffer $out) { |
|
| 1100 | |||
| 1101 | 53 | protected function rtrim($text, \DOMNode $node, CompilerBuffer $out) { |
|
| 1122 | |||
| 1123 | 53 | protected function inPre(\DOMNode $node) { |
|
| 1131 | |||
| 1132 | 3 | private function compileChildBlock(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Compile an x-expr node. |
||
| 1153 | * |
||
| 1154 | * @param DOMElement $node The node to compile. |
||
| 1155 | * @param DOMAttr[] $attributes The node's attributes. |
||
| 1156 | * @param DOMAttr[] $special An array of special attributes. |
||
| 1157 | * @param CompilerBuffer $out The compiler output. |
||
| 1158 | */ |
||
| 1159 | 8 | private function compileExpressionNode(DOMElement $node, array $attributes, array $special, CompilerBuffer $out) { |
|
| 1187 | |||
| 1188 | /** |
||
| 1189 | * @param DOMElement $node |
||
| 1190 | * @param $attributes |
||
| 1191 | * @param $special |
||
| 1192 | * @param CompilerBuffer $out |
||
| 1193 | */ |
||
| 1194 | 30 | protected function compileBasicElement(DOMElement $node, $attributes, $special, CompilerBuffer $out) { |
|
| 1203 | |||
| 1204 | 28 | protected function compileEscape($php) { |
|
| 1208 | } |
||
| 1209 |
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.