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