| Conditions | 22 |
| Paths | 30 |
| Total Lines | 53 |
| Code Lines | 45 |
| 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 |
||
| 56 | private static function buildNode(Node $node, &$parent) |
||
| 57 | { |
||
| 58 | extract((array) $node, EXTR_REFS); |
||
| 59 | switch ($type) { |
||
| 60 | case Y\COMMENT: self::$_root->addComment($line, $value); return; |
||
|
1 ignored issue
–
show
|
|||
| 61 | case Y\DIRECTIVE: return; //TODO |
||
|
1 ignored issue
–
show
|
|||
| 62 | case Y\ITEM: self::buildItem($value, $parent); return; |
||
|
1 ignored issue
–
show
|
|||
| 63 | case Y\KEY: self::buildKey($node, $parent); return; |
||
|
1 ignored issue
–
show
|
|||
| 64 | case Y\REF_DEF: //fall through |
||
|
1 ignored issue
–
show
|
|||
| 65 | case Y\REF_CALL://TODO: self::build returns what ? |
||
|
1 ignored issue
–
show
|
|||
| 66 | if (is_object($value)) { |
||
|
1 ignored issue
–
show
|
|||
| 67 | $result = self::build($value, $parent); |
||
| 68 | if (is_null($result)) { |
||
|
1 ignored issue
–
show
|
|||
| 69 | $tmp = $parent; |
||
| 70 | } else { |
||
|
1 ignored issue
–
show
|
|||
| 71 | $tmp = $result; |
||
| 72 | } |
||
|
1 ignored issue
–
show
|
|||
| 73 | } else { |
||
|
1 ignored issue
–
show
|
|||
| 74 | $tmp = $node->getPhpValue(); |
||
| 75 | } |
||
|
1 ignored issue
–
show
|
|||
| 76 | // $tmp = is_object($value) ? self::build($value, $parent) : $node->getPhpValue(); |
||
| 77 | if ($type === Y\REF_DEF) self::$_root->addReference($identifier, $tmp); |
||
| 78 | return self::$_root->getReference($identifier); |
||
| 79 | case Y\SET_KEY: |
||
|
1 ignored issue
–
show
|
|||
| 80 | $key = json_encode(self::build($value, $parent), JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_UNESCAPED_SLASHES); |
||
| 81 | if (empty($key)) |
||
| 82 | throw new \Exception("Cant serialize complex key: ".var_export($value, true), 1); |
||
| 83 | $parent->{$key} = null; |
||
| 84 | return; |
||
| 85 | case Y\SET_VALUE: |
||
|
1 ignored issue
–
show
|
|||
| 86 | $prop = array_keys(get_object_vars($parent)); |
||
| 87 | $key = end($prop); |
||
| 88 | if (property_exists($value, "type") && ($value->type & (Y\ITEM|Y\MAPPING))) { |
||
|
1 ignored issue
–
show
|
|||
| 89 | $p = $value->type === Y\ITEM ? [] : new \StdClass; |
||
| 90 | self::build($value, $p); |
||
| 91 | } else { |
||
|
1 ignored issue
–
show
|
|||
| 92 | $p = self::build($value, $parent->{$key}); |
||
| 93 | } |
||
|
1 ignored issue
–
show
|
|||
| 94 | $parent->{$key} = $p; |
||
| 95 | return; |
||
| 96 | case Y\TAG: |
||
|
1 ignored issue
–
show
|
|||
| 97 | if ($parent === self::$_root) { |
||
|
1 ignored issue
–
show
|
|||
| 98 | $parent->addTag($identifier); return; |
||
| 99 | } else {//TODO: have somewhere a list of common tags and their treatment |
||
|
1 ignored issue
–
show
|
|||
| 100 | if (in_array($identifier, ['!binary', '!str'])) { |
||
|
1 ignored issue
–
show
|
|||
| 101 | if ($value->value instanceof NodeList) $value->value->type = Y\RAW; |
||
| 102 | else $value->type = Y\RAW; |
||
|
1 ignored issue
–
show
|
|||
| 103 | } |
||
|
1 ignored issue
–
show
|
|||
| 104 | $val = is_null($value) ? null : self::build(/** @scrutinizer ignore-type */ $value, $node); |
||
|
2 ignored issues
–
show
|
|||
| 105 | return new Tag($identifier, $val); |
||
| 106 | } |
||
|
1 ignored issue
–
show
|
|||
| 107 | default: |
||
|
1 ignored issue
–
show
|
|||
| 108 | return is_object($value) ? self::build($value, $parent) : $node->getPhpValue(); |
||
| 109 | } |
||
| 230 |