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 |
||
| 12 | class SortableGroup implements Buildable |
||
| 13 | { |
||
| 14 | const MACRO_METHOD = 'sortableGroup'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var ExtensibleClassMetadata |
||
| 18 | */ |
||
| 19 | protected $classMetadata; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $fieldName; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param ExtensibleClassMetadata $classMetadata |
||
| 28 | * @param string $fieldName |
||
| 29 | */ |
||
| 30 | 4 | public function __construct(ExtensibleClassMetadata $classMetadata, $fieldName) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * Return the name of the actual extension. |
||
| 38 | * |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | 1 | public function getExtensionName() |
|
| 45 | |||
| 46 | /** |
||
| 47 | * @return void |
||
| 48 | */ |
||
| 49 | 4 | public static function enable() |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Execute the build process |
||
| 66 | */ |
||
| 67 | 1 | View Code Duplication | public function build() |
| 75 | } |
||
| 76 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.