Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 13 | class NotificationParser |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Regex-search-rule. |
||
| 17 | */ |
||
| 18 | const RULE = '/\{([a-zA-Z0-9_\.]+)\}/m'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Parse a notification and return the body text. |
||
| 22 | * |
||
| 23 | * @param ModelNotification $notification |
||
| 24 | * @param int $categoryId |
||
| 25 | * @return string |
||
| 26 | * @throws ExtraParamsException |
||
| 27 | */ |
||
| 28 | public function parse($notification, $categoryId) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Get an array of all placehodlers. |
||
| 58 | * |
||
| 59 | * @param string $body |
||
| 60 | * @return array |
||
| 61 | */ |
||
| 62 | protected function getValues($body) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Replace a single placeholder. |
||
| 72 | * |
||
| 73 | * @param string $body |
||
| 74 | * @param string $valueMatch |
||
| 75 | * @param string $replacer |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | protected function replace($body, $valueMatch, $replacer) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param array|object $object |
||
| 87 | * @param string $key |
||
| 88 | * @param null|mixed $default |
||
| 89 | * @return mixed |
||
| 90 | */ |
||
| 91 | protected function mixedGet($object, $key, $default = null) |
||
| 119 | } |
||
| 120 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.