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 |
||
| 15 | class GeoFixerFacade |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var KLogger\Logger |
||
| 19 | */ |
||
| 20 | private $logger; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var GeoFixer |
||
| 24 | */ |
||
| 25 | private $geo; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Инициализируем (если передан параметр) БД и логирование |
||
| 29 | * |
||
| 30 | * GeoFixerFacade constructor. |
||
| 31 | * @param bool $fias |
||
| 32 | * @param bool $logger |
||
| 33 | * @param array $config |
||
| 34 | */ |
||
| 35 | 4 | public function __construct($fias = false, $logger = false, $config = null) |
|
| 57 | |||
| 58 | /** |
||
| 59 | * Поиск похожих слов в массиве |
||
| 60 | * Логирование ошибок |
||
| 61 | * |
||
| 62 | * @param $word |
||
| 63 | * @param $search_array |
||
| 64 | * @param bool $strict_search |
||
| 65 | * |
||
| 66 | * @return string|false |
||
| 67 | */ |
||
| 68 | 3 | View Code Duplication | public function findSimilarWord($word, $search_array, $strict_search = false) |
| 82 | |||
| 83 | /** |
||
| 84 | * Поиск кода региона в базе КЛАДР |
||
| 85 | * Логирование ошибок |
||
| 86 | * |
||
| 87 | * @param $region |
||
| 88 | * @param bool $first_letters |
||
| 89 | * @param bool $strict_search |
||
| 90 | * |
||
| 91 | * @return string|false |
||
| 92 | */ |
||
| 93 | 4 | public function findKladrRegion($region, $first_letters = false, $strict_search = false) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * Поиск кода региона в базе ФИАС |
||
| 106 | * Логирование ошибок |
||
| 107 | * |
||
| 108 | * @param $region |
||
| 109 | * @param bool $first_letters |
||
| 110 | * @param bool $strict_search |
||
| 111 | * |
||
| 112 | * @return string|false |
||
| 113 | */ |
||
| 114 | 8 | View Code Duplication | public function findFiasRegion($region, $first_letters = false, $strict_search = false) |
| 129 | |||
| 130 | /** |
||
| 131 | * Поиск ID городов, или ID городов и поселений по коду региона в базе ФИАС |
||
| 132 | * Логирование ошибок |
||
| 133 | * |
||
| 134 | * @param $city |
||
| 135 | * @param $region_code |
||
| 136 | * @param bool $first_letters |
||
| 137 | * @param bool $strict_search |
||
| 138 | * |
||
| 139 | * @return string|false |
||
| 140 | */ |
||
| 141 | 4 | View Code Duplication | public function findFiasSettlement($city, $region_code, $first_letters = false, $strict_search = false, $full_settlements = false) |
| 157 | |||
| 158 | /** |
||
| 159 | * Поиск ID городов, или ID городов и поселений по коду региона в базе КЛАДР |
||
| 160 | * Логирование ошибок |
||
| 161 | * |
||
| 162 | * @param $city |
||
| 163 | * @param $region_code |
||
| 164 | * @param bool $first_letters |
||
| 165 | * @param bool $strict_search |
||
| 166 | * |
||
| 167 | * @return string|false |
||
| 168 | */ |
||
| 169 | 4 | public function findKladrSettlement($city, $region_code, $first_letters = false, $strict_search = false, $full_settlements = false) |
|
| 187 | |||
| 188 | /** |
||
| 189 | * Поиск ID улицы по ID города в базе ФИАС |
||
| 190 | * Логирование ошибок |
||
| 191 | * |
||
| 192 | * @param $street |
||
| 193 | * @param $city_id |
||
| 194 | * @param bool $first_letters |
||
| 195 | * @param bool $strict_search |
||
| 196 | * |
||
| 197 | * @return string|false |
||
| 198 | */ |
||
| 199 | 3 | View Code Duplication | public function findFiasStreet($street, $city_id, $first_letters = false, $strict_search = false) |
| 214 | |||
| 215 | /** |
||
| 216 | * Поиск кода улицы по коду города в базе КЛАДР |
||
| 217 | * Логирование ошибок |
||
| 218 | * |
||
| 219 | * @param $street |
||
| 220 | * @param $city_code |
||
| 221 | * @param bool $first_letters |
||
| 222 | * @param bool $strict_search |
||
| 223 | * |
||
| 224 | * @return string|false |
||
| 225 | */ |
||
| 226 | 4 | View Code Duplication | public function findKladrStreet($street, $city_code, $first_letters = false, $strict_search = false) |
| 241 | |||
| 242 | |||
| 243 | /** |
||
| 244 | * Поиск ID дома по ID улицы в базе ФИАС |
||
| 245 | * |
||
| 246 | * @param $house |
||
| 247 | * @param $street_id |
||
| 248 | * @param bool $building |
||
| 249 | * |
||
| 250 | * @return string|false |
||
| 251 | */ |
||
| 252 | 4 | public function findFiasHouse($house, $street_id, $building = false) |
|
| 266 | } |
||
| 267 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..