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