| Conditions | 10 |
| Paths | 22 |
| Total Lines | 34 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 71 | public function build(&$parent = null) |
||
| 72 | { |
||
| 73 | if (is_null($this->identifier)) { |
||
| 74 | throw new \ParseError(sprintf(self::ERROR_NO_KEYNAME, $this->line)); |
||
| 75 | } else { |
||
| 76 | if (is_null($this->value)) { |
||
| 77 | $result = null; |
||
| 78 | } elseif ($this->value instanceof Node) { |
||
| 79 | $value = $this->value; |
||
| 80 | switch (get_class($this->value)) { |
||
| 81 | case 'NodeItem':$mother = new NodeSequence(); |
||
| 82 | $mother->add($this->value); |
||
| 83 | $value = $mother; |
||
| 84 | break; |
||
| 85 | case 'NodeKey': $mother = new NodeMapping(); |
||
| 86 | $mother->add($this->value); |
||
| 87 | $value = $mother; |
||
| 88 | break; |
||
| 89 | case 'NodeSetKey':$mother = new NodeSet(); |
||
| 90 | $mother->add($this->value); |
||
| 91 | $value = $mother; |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | $result = $value->build($parent); |
||
| 95 | } elseif ($this->value instanceof NodeList) { |
||
| 96 | $result = Builder::buildNodeList($this->value); |
||
| 97 | } |
||
| 98 | if (is_null($parent)) { |
||
| 99 | return $result; |
||
|
|
|||
| 100 | } else { |
||
| 101 | if (is_array($parent)) { |
||
| 102 | $parent[$this->identifier] = $result; |
||
| 103 | } else { |
||
| 104 | $parent->{$this->identifier} = $result; |
||
| 105 | } |
||
| 110 | } |