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 | abstract class BaseEntity implements BaseEntityInterface, EntityTimestampInterface |
||
|
|||
21 | { |
||
22 | use SetPropertiesEntityTrait; |
||
23 | |||
24 | /** |
||
25 | * @ORM\Id |
||
26 | * @ORM\Column(type="integer", name="id") |
||
27 | * @ORM\GeneratedValue |
||
28 | */ |
||
29 | protected $id; |
||
30 | |||
31 | /** |
||
32 | * @var \DateTime |
||
33 | * |
||
34 | * @Gedmo\Timestampable(on="create") |
||
35 | * @ORM\Column(type="datetime", name="createdAt") |
||
36 | */ |
||
37 | private $createdAt; |
||
38 | |||
39 | /** |
||
40 | * @var \DateTime |
||
41 | * |
||
42 | * @Gedmo\Timestampable(on="update") |
||
43 | * @ORM\Column(type="datetime", name="updatedAt") |
||
44 | */ |
||
45 | private $updatedAt; |
||
46 | |||
47 | /** |
||
48 | * @ORM\Column(type="datetime", nullable=true, name="deletedAt") |
||
49 | */ |
||
50 | private $deletedAt; |
||
51 | |||
52 | public function getCreatedAt() |
||
56 | |||
57 | public function getUpdatedAt() |
||
61 | |||
62 | public function getDeletedAt() |
||
66 | |||
67 | public function setDeletedAt($deletedAt) |
||
71 | |||
72 | public function getDiscr() |
||
76 | |||
77 | public function getDiscrName() |
||
81 | |||
82 | /** |
||
83 | * Altera o campo updatedAt para forçar o persist da entity. |
||
84 | */ |
||
85 | public function forcePersist() |
||
91 | |||
92 | /** |
||
93 | * @ORM\PrePersist |
||
94 | */ |
||
95 | public function prePersist() |
||
101 | |||
102 | /** |
||
103 | * @ORM\PreUpdate |
||
104 | */ |
||
105 | public function preUpdate() |
||
111 | |||
112 | public function getRepository() |
||
116 | |||
117 | public function remove() |
||
123 | |||
124 | public function save($flush = false) |
||
130 | |||
131 | public function flush($all = true) |
||
137 | |||
138 | public function getId() |
||
142 | |||
143 | protected function getFillable() |
||
147 | |||
148 | /** |
||
149 | * Retona um array com o nome das propriedade que o cliente pode setar para realizar o store |
||
150 | * É usado principalmente em $this->setPropertiesEntity e nos Controllers. |
||
151 | * Este método não evita que uma propriedade seja alterada caso tenha seu método set(). |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | abstract public function getOnlyStore(); |
||
156 | |||
157 | /** |
||
158 | * Retona um array com o nome das propriedade que o cliente pode setar para realizar o update. |
||
159 | * Por padrão retorna os mesmos valores de $this->getOnlyStore(). |
||
160 | * Este método pode ser sobrescrito nas classes filhas. |
||
161 | * É usado principalmente em $this->setPropertiesEntity e nos Controllers. |
||
162 | * Este método não evita que uma propriedade seja alterada caso tenha seu método set(). |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | public function getOnlyUpdate() |
||
170 | |||
171 | View Code Duplication | final protected function checkOnyExceptInArray($key, array $options = null) |
|
187 | |||
188 | public function toArray(array $options = null) |
||
239 | } |
||
240 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.