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 |
||
| 10 | class MaterialField extends \samson\activerecord\materialfield |
||
| 11 | { |
||
| 12 | /** @var integer Primary key */ |
||
| 13 | public $FieldID; |
||
| 14 | |||
| 15 | /** @var bool Internal existence flag */ |
||
| 16 | public $Active; |
||
| 17 | |||
| 18 | /** @var integer Material identifier */ |
||
| 19 | public $MaterialID; |
||
| 20 | |||
| 21 | /** @var string Additional field value */ |
||
| 22 | public $Value; |
||
| 23 | |||
| 24 | /** @var string Additional field value */ |
||
| 25 | public $numeric_value; |
||
| 26 | |||
| 27 | /** @var string Additional field value */ |
||
| 28 | public $key_value; |
||
| 29 | |||
| 30 | /** @var string Additional field locale */ |
||
| 31 | public $locale; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Get identifiers collection by field identifier and its value. |
||
| 35 | * Method is optimized for performance. |
||
| 36 | * |
||
| 37 | * @param QueryInterface $query Database query instance |
||
| 38 | * @param string $materialID Additional field identifier |
||
| 39 | * @param string $fieldValue Additional field value for searching |
||
|
|
|||
| 40 | * @param array|null $return Variable where request result would be returned |
||
| 41 | * @param array $materialIDs Collection of material identifiers for filtering query |
||
| 42 | * @return bool|array True if material entities has been found and $return is passed |
||
| 43 | * or identifiers collection if only two parameters is passed. |
||
| 44 | */ |
||
| 45 | public static function idsByMaterialId(QueryInterface $query, $materialID, &$return = array()) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Find additional field value database record by its material and field identifiers. |
||
| 59 | * This is generic method that should be used in nested classes to find its |
||
| 60 | * records by some its primary key value. |
||
| 61 | * |
||
| 62 | * @param QueryInterface $query Query object instance |
||
| 63 | * @param string $materialID Material identifier |
||
| 64 | * @param self[]|null $return Variable to return found database record |
||
| 65 | * @param string $locale Locale identifier |
||
| 66 | * @return bool|null|self[] Field instance or null if 3rd parameter not passed |
||
| 67 | */ |
||
| 68 | View Code Duplication | public static function byMaterialID( |
|
| 83 | |||
| 84 | /** |
||
| 85 | * Find additional field value database record by its material and field identifiers. |
||
| 86 | * This is generic method that should be used in nested classes to find its |
||
| 87 | * records by some its primary key value. |
||
| 88 | * |
||
| 89 | * @param QueryInterface $query Query object instance |
||
| 90 | * @param string $materialID Material identifier |
||
| 91 | * @param string $fieldID Additional field identifier |
||
| 92 | * @param self[]|null $return Variable to return found database record |
||
| 93 | * @param string $locale Locale identifier |
||
| 94 | * @return bool|null|self[] Field instance or null if 3rd parameter not passed |
||
| 95 | */ |
||
| 96 | View Code Duplication | public static function byFieldIDAndMaterialID( |
|
| 112 | } |
||
| 113 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.