| Conditions | 6 |
| Paths | 7 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 6.1979 |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | 6 | public function visit(\DOMElement $node, Compiler $context) |
|
| 16 | { |
||
| 17 | 6 | if ($node->hasAttribute("from-exp")) { |
|
| 18 | $filename = $node->getAttribute("from-exp"); |
||
| 19 | 6 | } elseif ($node->hasAttribute("from")) { |
|
| 20 | 6 | $filename = '"' . $node->getAttribute("from") . '"'; |
|
| 21 | 6 | } else { |
|
| 22 | throw new Exception("The 'from' or 'from-exp' attribute is required"); |
||
| 23 | } |
||
| 24 | |||
| 25 | 6 | if ($node->hasAttribute("as")) { |
|
| 26 | 3 | $code = "import $filename as " . $node->getAttribute("as"); |
|
| 27 | 3 | $context->createControlNode("import " . ($node->getAttribute("fro-exp") ? $node->getAttribute("name-exp") : ("'" . $node->getAttribute("name") . "'")) . " as " . $node->getAttribute("as")); |
|
| 28 | 6 | } elseif ($node->hasAttribute("aliases")) { |
|
| 29 | 3 | $code = "from $filename import " . $node->getAttribute("aliases"); |
|
| 30 | 3 | } else { |
|
| 31 | throw new Exception("As or Alias attribute is required"); |
||
| 32 | } |
||
| 33 | |||
| 34 | 6 | $pi = $context->createControlNode($code); |
|
| 35 | |||
| 36 | 6 | $node->parentNode->replaceChild($pi, $node); |
|
| 37 | 6 | } |
|
| 38 | } |
||
| 39 |