| Conditions | 7 |
| Paths | 5 |
| Total Lines | 25 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 7.0178 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 31 | 6 | public static function create($node_name, array $attributes = null, array $elements = null) |
|
| 32 | { |
||
| 33 | 6 | $element = ucfirst(strtolower($node_name)); |
|
| 34 | 6 | $className = "\Drone\Dom\Element\\" . $element; |
|
| 35 | 6 | $instance = new $className; |
|
| 36 | |||
| 37 | 6 | if (count($attributes)) { |
|
| 38 | 6 | foreach ($attributes as $name => $value) { |
|
| 39 | 6 | if (!is_string($name)) { |
|
| 40 | throw new \InvalidArgumentException("Attribute only accepts strings as names"); |
||
| 41 | } |
||
| 42 | |||
| 43 | 6 | $instance->setAttribute(new Attribute($name, $value)); |
|
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | 6 | if (count($elements)) { |
|
| 48 | 6 | foreach ($elements as $_node_name => $element) { |
|
| 49 | 6 | foreach ($element as $label => $_attributes) { |
|
| 50 | 6 | $instance->setChild($label, self::create($_node_name, $_attributes)); |
|
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | 6 | return $instance; |
|
| 56 | } |
||
| 58 |