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 |
||
10 | View Code Duplication | class Section |
|
|
|||
11 | { |
||
12 | /** |
||
13 | * @Rest\Id |
||
14 | * @Rest\Attribute(name="@id", type="string") |
||
15 | */ |
||
16 | private $iri; |
||
17 | |||
18 | /** |
||
19 | * @Rest\Attribute(name="id", type="string") |
||
20 | */ |
||
21 | private $id; |
||
22 | |||
23 | /** |
||
24 | * @Rest\Attribute(name="title", type="string") |
||
25 | */ |
||
26 | private $title; |
||
27 | |||
28 | /** |
||
29 | * @Rest\OneToMany(name="articleList", targetEntity="Article") |
||
30 | */ |
||
31 | private $articleList = []; |
||
32 | |||
33 | public function setId($id) |
||
37 | |||
38 | public function getId() |
||
42 | |||
43 | /** |
||
44 | * Getter for iri |
||
45 | * |
||
46 | * @return string |
||
47 | */ |
||
48 | public function getIri() |
||
52 | |||
53 | /** |
||
54 | * Setter for iri |
||
55 | * |
||
56 | * @param string $iri |
||
57 | * @return Section |
||
58 | */ |
||
59 | public function setIri($iri) |
||
65 | |||
66 | public function setTitle($title) |
||
70 | |||
71 | public function getTitle() |
||
75 | |||
76 | public function addArticle(Article $article) |
||
80 | |||
81 | public function getArticleList() |
||
85 | } |
||
86 |
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.