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 |
||
20 | class BaseEvent extends Event |
||
21 | { |
||
22 | /** |
||
23 | * @var \Core\Repository\RepositoryService |
||
24 | */ |
||
25 | private $repositories; |
||
26 | |||
27 | /** |
||
28 | * @return \Core\Repository\RepositoryService |
||
29 | */ |
||
30 | public function getRepositories() |
||
34 | |||
35 | /** |
||
36 | * @param \Core\Repository\RepositoryService $repositories |
||
37 | * |
||
38 | * @return self |
||
39 | */ |
||
40 | public function setRepositories($repositories) |
||
46 | |||
47 | /** |
||
48 | * Get a entity repository from the repository service |
||
49 | * |
||
50 | * @param string $name |
||
51 | * |
||
52 | * @return \Doctrine\Common\Persistence\ObjectRepository|\Doctrine\ODM\MongoDB\DocumentRepository|\Core\Repository\RepositoryInterface |
||
53 | */ |
||
54 | public function getRepository($name) |
||
58 | |||
59 | public function setParam($name, $value) |
||
69 | |||
70 | View Code Duplication | public function setParams($params) |
|
86 | |||
87 | } |
||
88 |
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.