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 | View Code Duplication | class OrcRepository extends EntityRepository |
|
|
|||
13 | { |
||
14 | /** |
||
15 | * @param int $id |
||
16 | * @param int|null $lockMode |
||
17 | * @param int|null $lockVersion |
||
18 | * @return Orc |
||
19 | * @throws \Doctrine\ORM\ORMException |
||
20 | */ |
||
21 | public function find($id, $lockMode = null, $lockVersion = null): Orc |
||
31 | |||
32 | /** |
||
33 | * @param Orc $orc |
||
34 | * @return $orc |
||
35 | * @throws \Doctrine\ORM\ORMException |
||
36 | * @throws \Doctrine\ORM\OptimisticLockException |
||
37 | */ |
||
38 | public function save(Orc $orc): Orc |
||
47 | |||
48 | /** |
||
49 | * @param Orc $orc |
||
50 | * @throws \Doctrine\ORM\OptimisticLockException |
||
51 | * @throws \Doctrine\ORM\ORMException |
||
52 | */ |
||
53 | public function delete(Orc $orc): void |
||
58 | |||
59 | /** |
||
60 | * @return int |
||
61 | * @throws \Doctrine\ORM\NoResultException |
||
62 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
63 | */ |
||
64 | public function getTotalOrcCount(): int |
||
72 | } |
||
73 |
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.