Conditions | 11 |
Paths | 11 |
Total Lines | 32 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
30 | public static function run (AST $tree, Node $parent = null): array |
||
31 | { |
||
32 | foreach ($tree->getNodes () as $id => $node) |
||
33 | { |
||
34 | if ($node->type == \VLF\STYLE_DEFINITION) |
||
35 | { |
||
36 | $name = $node->args['name']; |
||
37 | $nodes = $node->getNodes (); |
||
38 | |||
39 | if ($node->args['parents'] !== null) |
||
40 | foreach ($node->args['parents'] as $parent) |
||
41 | if (!isset (self::$styles[$parent]) && !isset (self::$default_styles[$parent])) |
||
42 | { |
||
43 | if (self::$throw_errors) |
||
44 | throw new \Exception ('Style "'. $parent .'" not founded'); |
||
45 | } |
||
46 | |||
47 | else $nodes = array_merge (self::$styles[$parent] ?? self::$default_styles[$parent], $nodes); |
||
48 | |||
49 | if ($node->args['is_default']) |
||
50 | self::$default_styles[$name] = isset (self::$objects[$name]) ? |
||
51 | array_merge (self::$default_styles[$name], $nodes) : $nodes; |
||
52 | |||
53 | else self::$styles[$name] = isset (self::$objects[$name]) ? |
||
54 | array_merge (self::$styles[$name], $nodes) : $nodes; |
||
55 | } |
||
56 | |||
57 | list (self::$styles, self::$default_styles) = self::run (new AST (array_map ( |
||
58 | fn ($node) => $node->export (), $node->getNodes ())), $node); |
||
59 | } |
||
60 | |||
61 | return [self::$styles, self::$default_styles]; |
||
62 | } |
||
70 |