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 |
||
22 | class NodeAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $locale; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $permission; |
||
33 | |||
34 | /** |
||
35 | * @var DomainConfigurationInterface |
||
36 | */ |
||
37 | protected $domainConfiguration; |
||
38 | |||
39 | /** |
||
40 | * @var bool |
||
41 | */ |
||
42 | protected $showAddHomepage; |
||
43 | |||
44 | /** |
||
45 | * @var AuthorizationCheckerInterface |
||
46 | */ |
||
47 | protected $authorizationChecker; |
||
48 | |||
49 | /** |
||
50 | * @param EntityManager $em The entity |
||
51 | * manager |
||
52 | * @param AclHelper $aclHelper The ACL helper |
||
53 | * @param string $locale The current |
||
54 | * locale |
||
55 | * @param string $permission The permission |
||
56 | */ |
||
57 | View Code Duplication | public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $permission, AuthorizationCheckerInterface $authorizationChecker) |
|
70 | |||
71 | /** |
||
72 | * @param \Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface $domainConfiguration |
||
73 | */ |
||
74 | public function setDomainConfiguration(DomainConfigurationInterface $domainConfiguration) |
||
78 | |||
79 | /** |
||
80 | * @param bool $showAddHomepage |
||
81 | */ |
||
82 | public function setShowAddHomepage($showAddHomepage) |
||
86 | |||
87 | /** |
||
88 | * Build list actions ... |
||
89 | */ |
||
90 | public function buildListActions() |
||
116 | |||
117 | /** |
||
118 | * Configure filters |
||
119 | */ |
||
120 | View Code Duplication | public function buildFilters() |
|
128 | |||
129 | /** |
||
130 | * Configure the visible columns |
||
131 | */ |
||
132 | public function buildFields() |
||
133 | { |
||
134 | $this |
||
135 | ->addField('title', 'kuma_node.admin.list.header.title', true, '@KunstmaanNode/Admin/title.html.twig') |
||
136 | ->addField('created', 'kuma_node.admin.list.header.created_at', true) |
||
137 | ->addField('updated', 'kuma_node.admin.list.header.updated_at', true) |
||
138 | ->addField('online', 'kuma_node.admin.list.header.online', true, '@KunstmaanNode/Admin/online.html.twig'); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @param mixed $item |
||
143 | * |
||
144 | * @return array |
||
145 | */ |
||
146 | View Code Duplication | public function getEditUrlFor($item) |
|
156 | |||
157 | /** |
||
158 | * @return bool |
||
159 | */ |
||
160 | public function canAdd() |
||
164 | |||
165 | public function canEdit($item) |
||
169 | |||
170 | /** |
||
171 | * Return if current user can delete the specified item |
||
172 | * |
||
173 | * @param array|object $item |
||
174 | * |
||
175 | * @return bool |
||
176 | */ |
||
177 | public function canDelete($item) |
||
181 | |||
182 | /** |
||
183 | * @param object $item |
||
184 | * |
||
185 | * @return array |
||
186 | */ |
||
187 | public function getDeleteUrlFor($item) |
||
191 | |||
192 | /** |
||
193 | * @return string |
||
194 | */ |
||
195 | public function getBundleName() |
||
199 | |||
200 | /** |
||
201 | * @return string |
||
202 | */ |
||
203 | public function getEntityName() |
||
207 | |||
208 | /** |
||
209 | * Override path convention (because settings is a virtual admin subtree) |
||
210 | * |
||
211 | * @param string $suffix |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getPathByConvention($suffix = null) |
||
223 | |||
224 | /** |
||
225 | * Override controller path (because actions for different entities are |
||
226 | * defined in a single Settings controller). |
||
227 | * |
||
228 | * @return string |
||
229 | */ |
||
230 | public function getControllerPath() |
||
234 | |||
235 | /** |
||
236 | * @param QueryBuilder $queryBuilder The query builder |
||
237 | */ |
||
238 | public function adaptQueryBuilder(QueryBuilder $queryBuilder) |
||
262 | } |
||
263 |
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.