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 |
||
27 | abstract class AbstractEntityQuery extends AbstractQuery |
||
28 | { |
||
29 | protected $instance; |
||
30 | |||
31 | /** |
||
32 | * Constructor |
||
33 | * |
||
34 | * @param Connection $connection |
||
35 | * @param mixed $entity |
||
36 | * @param ModelInterface $model |
||
37 | * @param RelationFactoryInterface $factory |
||
38 | * @param AccessorInterface $accessor |
||
39 | * @param EventDispatcherInterface $dispatcher |
||
40 | */ |
||
41 | public function __construct(Connection $connection, $entity, ModelInterface $model, RelationFactoryInterface $factory, AccessorInterface $accessor, EventDispatcherInterface $dispatcher) |
||
46 | |||
47 | /** |
||
48 | * Assigns entity instance |
||
49 | * Asserts if entity instance is of expected type |
||
50 | * |
||
51 | * @param array|object $entity |
||
52 | * |
||
53 | * @throws QueryException |
||
54 | */ |
||
55 | protected function assignEntity($entity) |
||
69 | |||
70 | /** |
||
71 | * Assigns primary condition |
||
72 | * |
||
73 | * @throws QueryException |
||
74 | */ |
||
75 | View Code Duplication | protected function setPrimaryKeyConditions() |
|
88 | } |
||
89 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.