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 |
||
| 19 | class PriceGateway |
||
| 20 | { |
||
| 21 | private $db; |
||
| 22 | |||
| 23 | public function __construct(\Enlight_Components_Db_Adapter_Pdo_Mysql $db) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Returns count of product without |
||
| 30 | * configured price |
||
| 31 | * |
||
| 32 | * @param Group $group |
||
|
|
|||
| 33 | * @param $priceField |
||
| 34 | * @throws \Zend_Db_Statement_Exception |
||
| 35 | * @return array |
||
| 36 | */ |
||
| 37 | View Code Duplication | public function countProductsWithoutConfiguredPrice(Group $group = null, $priceField) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * Returns count of product with |
||
| 61 | * configured price |
||
| 62 | * |
||
| 63 | * @param Group $group |
||
| 64 | * @param $priceField |
||
| 65 | * @throws \Zend_Db_Statement_Exception |
||
| 66 | * @return array |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function countProductsWithConfiguredPrice(Group $group = null, $priceField) |
|
| 89 | |||
| 90 | /** |
||
| 91 | * Returns count of product including variants for a group |
||
| 92 | * |
||
| 93 | * @param Group $group |
||
| 94 | * @throws \Zend_Db_Statement_Exception |
||
| 95 | * @return array |
||
| 96 | */ |
||
| 97 | public function countProducts(Group $group = null) |
||
| 108 | } |
||
| 109 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.