| Conditions | 6 |
| Paths | 20 |
| Total Lines | 62 |
| Lines | 16 |
| Ratio | 25.81 % |
| 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 | #!/usr/bin/env php |
||
| 73 | function generate_index(array $sets) |
||
| 74 | { |
||
| 75 | $content = '================' . PHP_EOL |
||
| 76 | . 'Current Rulesets' . PHP_EOL |
||
| 77 | . '================' |
||
| 78 | . PHP_EOL . PHP_EOL |
||
| 79 | . 'List of rulesets and rules contained in each ruleset.' |
||
| 80 | . PHP_EOL . PHP_EOL; |
||
| 81 | |||
| 82 | foreach ($sets as $set) { |
||
| 83 | $content .= sprintf( |
||
| 84 | '- `%s`__: %s%s', |
||
| 85 | $set['name'], |
||
| 86 | $set['desc'], |
||
| 87 | PHP_EOL |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | |||
| 91 | $content .= PHP_EOL; |
||
| 92 | foreach ($sets as $set) { |
||
| 93 | $anchor = preg_replace('([^a-z0-9]+)i', '-', $set['name']); |
||
| 94 | $anchor = strtolower($anchor); |
||
| 95 | |||
| 96 | $content .= '__ index.html#' . $anchor . PHP_EOL; |
||
| 97 | } |
||
| 98 | $content .= PHP_EOL; |
||
| 99 | |||
| 100 | foreach ($sets as $set) { |
||
| 101 | $content .= $set['name'] . PHP_EOL; |
||
| 102 | $content .= str_repeat('=', strlen($set['name'])); |
||
| 103 | $content .= PHP_EOL . PHP_EOL; |
||
| 104 | |||
| 105 | foreach ($set['rules'] as $rule) { |
||
| 106 | $content .= sprintf( |
||
| 107 | '- `%s`__: %s%s', |
||
| 108 | $rule['name'], |
||
| 109 | $rule['desc'], |
||
| 110 | PHP_EOL |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | |||
| 114 | $content .= PHP_EOL; |
||
| 115 | foreach ($set['rules'] as $rule) { |
||
| 116 | $content .= '__ ' . $rule['href'] . PHP_EOL; |
||
| 117 | } |
||
| 118 | $content .= PHP_EOL; |
||
| 119 | } |
||
| 120 | $content .= PHP_EOL; |
||
| 121 | $content .= 'Remark' . PHP_EOL . |
||
| 122 | '======' . PHP_EOL . PHP_EOL . |
||
| 123 | ' This document is based on a ruleset xml-file, that ' . |
||
| 124 | 'was taken from the original source of the `PMD`__ ' . |
||
| 125 | 'project. This means that most parts of the content ' . |
||
| 126 | 'on this page are the intellectual work of the PMD ' . |
||
| 127 | 'community and its contributors and not of the PHPMD ' . |
||
| 128 | 'project.' . |
||
| 129 | PHP_EOL . PHP_EOL . |
||
| 130 | '__ https://pmd.sourceforge.net/' . |
||
| 131 | PHP_EOL; |
||
| 132 | |||
| 133 | return $content; |
||
| 134 | } |
||
| 135 |