| Conditions | 9 |
| Paths | 14 |
| Total Lines | 60 |
| Code Lines | 37 |
| 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 |
||
| 39 | public function enterNode(Node $node) |
||
| 40 | { |
||
| 41 | if ($node instanceof ClassLike) { |
||
| 42 | $commentNodes = []; |
||
| 43 | |||
| 44 | foreach ($this->constants as $row) { |
||
| 45 | $name = str_replace( |
||
| 46 | [' ', '-', '\'', '(', ')', '[', ']', '.', '/', '=', ',', ':', '°', '+', '&', '<>'], |
||
| 47 | ['_', '_', '', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_DEG_', '_PLUS_', '_AND_', '_TO_'], |
||
| 48 | $row['constant_name'] |
||
| 49 | ); |
||
| 50 | $name = preg_replace('/_+/', '_', $name); |
||
| 51 | $name = trim($name, '_'); |
||
| 52 | |||
| 53 | $comment = ''; |
||
| 54 | if ($row['constant_help'] || $row['deprecated']) { |
||
| 55 | $row['constant_help'] = str_replace( |
||
| 56 | [ |
||
| 57 | 'See information source for formula and example.', |
||
| 58 | 'This is a parameter-less conversion.', |
||
| 59 | ], |
||
| 60 | [ |
||
| 61 | '', |
||
| 62 | '', |
||
| 63 | ], |
||
| 64 | $row['constant_help'] |
||
| 65 | ); |
||
| 66 | |||
| 67 | $comment .= "/**\n"; |
||
| 68 | $helpLines = explode("\n", wordwrap($row['constant_help'], 112)); |
||
| 69 | foreach ($helpLines as $helpLine) { |
||
| 70 | $comment .= '* ' . trim($helpLine) . "\n"; |
||
| 71 | } |
||
| 72 | if ($row['deprecated']) { |
||
| 73 | $comment .= "* @deprecated\n"; |
||
| 74 | } |
||
| 75 | $comment .= " */\n"; |
||
| 76 | } |
||
| 77 | |||
| 78 | $constName = strtoupper('EPSG_' . $name); |
||
| 79 | $constValue = is_string($row['constant_value']) ? new Node\Scalar\String_($row['constant_value']) : new Node\Scalar\LNumber($row['constant_value']); |
||
| 80 | $constComment = new Doc($comment); |
||
| 81 | $const = new Node\Const_($constName, $constValue); |
||
| 82 | |||
| 83 | $flags = Class_::MODIFIER_PUBLIC; |
||
| 84 | if ($this->visibility === 'protected') { |
||
| 85 | $flags = Class_::MODIFIER_PROTECTED; |
||
| 86 | } |
||
| 87 | |||
| 88 | $constStmt = new ClassConst([$const], $flags); |
||
| 89 | $constStmt->setDocComment($constComment); |
||
| 90 | $commentNodes[] = $constStmt; |
||
| 91 | } |
||
| 92 | |||
| 93 | $node->stmts = array_merge($commentNodes, $node->stmts); |
||
| 94 | |||
| 95 | return NodeTraverser::STOP_TRAVERSAL; |
||
| 96 | } |
||
| 97 | |||
| 98 | return null; |
||
| 99 | } |
||
| 101 |