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 | * map a single article to main attributes in Article Class |
||
| 11 | * @param string $singleJsonArticle JSON response |
||
| 12 | * @return Article\Exception |
||
| 13 | */ |
||
| 14 | public function article($singleJsonArticle) { |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Make sure value is integer |
||
| 51 | * @param int $int |
||
| 52 | * @return boolean |
||
| 53 | */ |
||
| 54 | private function filterInteger($int) { |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Make sure string is not null or empty |
||
| 63 | * @param null/string $str |
||
|
|
|||
| 64 | * @return string/exception |
||
| 65 | */ |
||
| 66 | private function filterString($str) { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Make Sure Date in string with correct format state |
||
| 75 | * |
||
| 76 | * @param \DateTimeInterface|string|int|null $date |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | View Code Duplication | private function filterDate($date) { |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Get value of array based on attributes(keys) |
||
| 93 | * @param supported php variables $attribute |
||
| 94 | * @param array $data |
||
| 95 | * @return supported php variables |
||
| 96 | */ |
||
| 97 | private function getValue($attribute, $data) { |
||
| 103 | |||
| 104 | /** |
||
| 105 | * format date into required format |
||
| 106 | * |
||
| 107 | * @param \DateTimeInterface $date |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | private function formatDate($date) { |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Convert JSON string to associative array |
||
| 116 | * @param string $jsonResponse |
||
| 117 | * @return array if it is valid json, null otherwise |
||
| 118 | */ |
||
| 119 | public function jsonToArray($jsonResponse) { |
||
| 126 | } |
||
| 127 |
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.