| Conditions | 10 |
| Paths | 384 |
| Total Lines | 17 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 110 |
| 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 |
||
| 24 | public function generate($params) |
||
| 25 | { |
||
| 26 | // Safely build a slug from the board name; guard against null |
||
| 27 | $name = isset($params['name']) && $params['name'] !== null ? (string) $params['name'] : ''; |
||
| 28 | $name = trim($name); |
||
| 29 | $slug = $name === '' ? 'board' : preg_replace('~\s+~u', '-', $name); |
||
| 30 | $slug = trim($slug, '-'); |
||
| 31 | |||
| 32 | $board_id = isset($params['board']) ? (int) $params['board'] : 0; |
||
| 33 | $has_start = isset($params['start']) && $params['start'] !== '' && $params['start'] !== null; |
||
| 34 | $start = $has_start ? (int) $params['start'] : null; |
||
| 35 | |||
| 36 | // Semantic pagination format is dot-appended after the id (e.g., b/slug-id.10) |
||
| 37 | $url = 'b/' . rawurlencode($slug) . '-' . $board_id . ($has_start && $start !== 0 ? '.' . $start : ''); |
||
| 38 | unset($params['name'], $params['board'], $params['start']); |
||
| 39 | |||
| 40 | return $url . $this->generateQuery($params); |
||
| 41 | } |
||
| 43 |