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 |
||
18 | class BusinessTemplate extends Template implements VictoireQueryInterface |
||
19 | { |
||
20 | //This trait add the query and business_entity_id columns |
||
21 | use QueryTrait; |
||
22 | |||
23 | const TYPE = 'business_template'; |
||
24 | |||
25 | /** |
||
26 | * @ORM\OneToOne(targetEntity="\Victoire\Bundle\SeoBundle\Entity\PageSeo", cascade={"persist", "remove"}) |
||
27 | * @ORM\JoinColumn(name="seo_id", referencedColumnName="id", onDelete="SET NULL") |
||
28 | */ |
||
29 | protected $seo; |
||
30 | |||
31 | /** |
||
32 | * @ORM\OneToMany(targetEntity="\Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage", mappedBy="template", cascade={"remove"}) |
||
33 | */ |
||
34 | protected $inheritors; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | * |
||
39 | * @deprecated author restriction is handled by the "BUSINESS_ENTITY_OWNER" role since 1.7.7 and will be removed in the 1.8 |
||
40 | * |
||
41 | * @ORM\Column(name="author_restricted", type="boolean") |
||
42 | */ |
||
43 | protected $authorRestricted; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | * |
||
48 | * @ORM\Column(name="backendName", type="string", length=255) |
||
49 | */ |
||
50 | protected $backendName; |
||
51 | |||
52 | /** |
||
53 | * contruct. |
||
54 | **/ |
||
55 | public function __construct() |
||
61 | |||
62 | /** |
||
63 | * @return [BusinessPage] |
||
64 | */ |
||
65 | public function getInstances() |
||
69 | |||
70 | public function setInstances($inheritors) |
||
76 | |||
77 | /** |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getLayout() |
||
84 | |||
85 | /** |
||
86 | * Set seo. |
||
87 | * |
||
88 | * @param PageSeo $seo |
||
89 | * |
||
90 | * @return BusinessTemplate |
||
91 | */ |
||
92 | public function setSeo(PageSeo $seo) |
||
98 | |||
99 | /** |
||
100 | * Get seo. |
||
101 | * |
||
102 | * @return PageSeo |
||
103 | */ |
||
104 | public function getSeo() |
||
108 | |||
109 | /** |
||
110 | * @return bool |
||
111 | */ |
||
112 | public function isAuthorRestricted() |
||
116 | |||
117 | /** |
||
118 | * @param bool $authorRestricted |
||
119 | */ |
||
120 | public function setAuthorRestricted($authorRestricted) |
||
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | public function getBackendName() |
||
132 | |||
133 | /** |
||
134 | * @param string $backendName |
||
135 | * |
||
136 | * @return $this |
||
137 | */ |
||
138 | public function setBackendName($backendName) |
||
144 | |||
145 | /** |
||
146 | * Get inheritors (all Templates having this object as Template). |
||
147 | * |
||
148 | * @return [Template] |
||
149 | */ |
||
150 | View Code Duplication | public function getTemplateInheritors() |
|
161 | } |
||
162 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: