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 |
||
23 | View Code Duplication | class VenueSector extends AbstractPersonalTranslatable implements TranslatableInterface |
|
|
|||
24 | { |
||
25 | /** |
||
26 | * @var integer |
||
27 | * |
||
28 | * @ORM\Column(name="id", type="integer") |
||
29 | * @ORM\Id |
||
30 | * @ORM\GeneratedValue(strategy="AUTO") |
||
31 | */ |
||
32 | protected $id; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | * @Gedmo\Translatable |
||
37 | * @Assert\NotBlank() |
||
38 | * @ORM\Column(type="string", length=255) |
||
39 | * @Type("string") |
||
40 | * @Expose() |
||
41 | */ |
||
42 | protected $title; |
||
43 | |||
44 | /** |
||
45 | * @var ArrayCollection|Translation[] |
||
46 | * |
||
47 | * @ORM\OneToMany( |
||
48 | * targetEntity="AppBundle\Entity\Translations\VenueSectorTranslation", |
||
49 | * mappedBy="object", |
||
50 | * cascade={"persist", "remove"} |
||
51 | * ) |
||
52 | */ |
||
53 | protected $translations; |
||
54 | |||
55 | /** |
||
56 | * @var Venue |
||
57 | * |
||
58 | * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Venue", inversedBy="venueSectors") |
||
59 | * @Type("AppBundle\Entity\Venue") |
||
60 | * @Expose() |
||
61 | */ |
||
62 | protected $venue; |
||
63 | |||
64 | /** |
||
65 | * @var Collection|Seat[] |
||
66 | * |
||
67 | * @ORM\OneToMany( |
||
68 | * targetEntity="AppBundle\Entity\Seat", |
||
69 | * mappedBy="venueSector", |
||
70 | * cascade={"persist", "remove"} |
||
71 | * ) |
||
72 | */ |
||
73 | protected $seats; |
||
74 | |||
75 | /** |
||
76 | * @ORM\Column(name="slug", type="string", length=255) |
||
77 | * @Type("string") |
||
78 | * @Expose |
||
79 | */ |
||
80 | private $slug; |
||
81 | |||
82 | /** |
||
83 | * VenueSector constructor. |
||
84 | */ |
||
85 | public function __construct() |
||
90 | |||
91 | /** |
||
92 | * @return integer |
||
93 | */ |
||
94 | public function getId() |
||
98 | |||
99 | /** |
||
100 | * @return VenueSector |
||
101 | */ |
||
102 | public function unsetTranslations() |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getTitle() |
||
116 | |||
117 | /** |
||
118 | * @param string $title |
||
119 | * @return VenueSector |
||
120 | */ |
||
121 | public function setTitle($title) |
||
127 | |||
128 | /** |
||
129 | * @return Venue |
||
130 | */ |
||
131 | public function getVenue() |
||
135 | |||
136 | /** |
||
137 | * @param Seat $seat |
||
138 | * @return VenueSector |
||
139 | */ |
||
140 | public function addSeat(Seat $seat) |
||
146 | |||
147 | /** |
||
148 | * @param Seat $seat |
||
149 | */ |
||
150 | public function removeSeat(Seat $seat) |
||
154 | |||
155 | /** |
||
156 | * @return Collection |
||
157 | */ |
||
158 | public function getSeat() |
||
162 | |||
163 | /** |
||
164 | * Get slug |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getSlug() |
||
172 | |||
173 | /** |
||
174 | * Set slug |
||
175 | * |
||
176 | * @param string $slug |
||
177 | * @return VenueSector |
||
178 | */ |
||
179 | public function setSlug($slug) |
||
185 | |||
186 | /** |
||
187 | * @return string |
||
188 | */ |
||
189 | public function __toString() |
||
193 | } |
||
194 |
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.