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 |
||
| 2 | class Nip_Helper_Strings extends Nip\Helpers\AbstractHelper { |
||
|
|
|||
| 3 | |||
| 4 | /** |
||
| 5 | * Limits a string to a certain number of words |
||
| 6 | * |
||
| 7 | * @param string $string |
||
| 8 | * @param int $limit |
||
| 9 | * @param string $end |
||
| 10 | * @return string |
||
| 11 | */ |
||
| 12 | public function limitWords($string, $limit = false, $end = '...') { |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * Injects GET params in links |
||
| 32 | * |
||
| 33 | * @param string $string |
||
| 34 | * @param array $params |
||
| 35 | * @return string |
||
| 36 | */ |
||
| 37 | public function injectParams($string, $params = array()) { |
||
| 62 | |||
| 63 | |||
| 64 | /** |
||
| 65 | * Converts all relative hrefs and image srcs to absolute |
||
| 66 | * |
||
| 67 | * @param string $string |
||
| 68 | * @param string $base |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | public function relativeToAbsolute($string, $base) { |
||
| 84 | |||
| 85 | public function moneyFormat($number) |
||
| 89 | |||
| 90 | public function cronoTimeInSeconds($time) |
||
| 100 | |||
| 101 | public function secondsInCronoTime($seconds) |
||
| 120 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.