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 CountryLoader |
||
| 8 | { |
||
| 9 | const ALL_COUNTRIES_FILE = 'countries.json'; |
||
| 10 | const COUNTRY_FILE = 'countries/%s.json'; |
||
| 11 | const COUNTRY_POLYGON_FILE = 'countries/%s/polygon.json'; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var Storage |
||
| 15 | */ |
||
| 16 | private $path; |
||
| 17 | |||
| 18 | 3 | public function __construct() |
|
| 22 | |||
| 23 | /** |
||
| 24 | * @return array |
||
| 25 | */ |
||
| 26 | 3 | public function loadAllCountries() |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @param string $country |
||
| 36 | * |
||
| 37 | * @return array |
||
| 38 | */ |
||
| 39 | 1 | View Code Duplication | public function loadCountry($country) |
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $country |
||
| 57 | * |
||
| 58 | * @return array |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function loadCountryPolygon($country) |
|
| 75 | } |
||
| 76 |
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..