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 |
||
| 7 | class FormatMapping |
||
| 8 | { |
||
| 9 | |||
| 10 | /** |
||
| 11 | * map a single article to main attributes in Article Class |
||
| 12 | * @param string $singleJsonArticle JSON response |
||
| 13 | * @return Article\Exception |
||
| 14 | */ |
||
| 15 | public function article($singleJsonArticle) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Make sure value is integer |
||
| 53 | * @param int $int |
||
| 54 | * @return boolean |
||
| 55 | */ |
||
| 56 | private function filterInteger($int) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Make sure string is not null or empty |
||
| 66 | * @param null/string $str |
||
|
|
|||
| 67 | * @return string/exception |
||
| 68 | */ |
||
| 69 | private function filterString($str) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Make Sure Date in string with correct format state |
||
| 79 | * |
||
| 80 | * @param \DateTimeInterface|string|int|null $date |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | View Code Duplication | private function filterDate($date) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Get value of array based on attributes(keys) |
||
| 98 | * @param supported php variables $attribute |
||
| 99 | * @param array $data |
||
| 100 | * @return supported php variables |
||
| 101 | */ |
||
| 102 | private function getValue($attribute, $data) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * format date into required format |
||
| 112 | * |
||
| 113 | * @param \DateTimeInterface $date |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | private function formatDate($date) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Convert JSON string to associative array |
||
| 123 | * @param string $jsonResponse |
||
| 124 | * @return array if it is valid json, null otherwise |
||
| 125 | */ |
||
| 126 | public function jsonToArray($jsonResponse) |
||
| 134 | } |
||
| 135 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.