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 |
||
13 | class CategoryReader extends EntityReader |
||
14 | { |
||
15 | /** |
||
16 | * @var CategoryRepository |
||
17 | */ |
||
18 | protected $repository; |
||
19 | |||
20 | /** |
||
21 | * @param EntityManager $em |
||
22 | * @param string $className |
||
23 | * @param CategoryRepository $repository |
||
24 | */ |
||
25 | public function __construct( |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | View Code Duplication | public function read() |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function getQuery() |
||
64 | |||
65 | /** |
||
66 | * Get the custom category repository |
||
67 | * @return CategoryRepository |
||
68 | */ |
||
69 | protected function getRepository() |
||
73 | } |
||
74 |
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.