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 |
||
13 | class BaseWidgetContentResolver |
||
|
|||
14 | { |
||
15 | /** |
||
16 | * @var QueryHelper |
||
17 | */ |
||
18 | protected $queryHelper; |
||
19 | |||
20 | /** |
||
21 | * @var EntityManager |
||
22 | */ |
||
23 | protected $entityManager; |
||
24 | |||
25 | /** |
||
26 | * @var APIBusinessEntityResolver |
||
27 | */ |
||
28 | protected $apiResolver; |
||
29 | |||
30 | /** |
||
31 | * Get the static content of the widget. |
||
32 | * |
||
33 | * @param Widget $widget |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | public function getWidgetStaticContent(Widget $widget) |
||
53 | |||
54 | /** |
||
55 | * Get the business entity content. |
||
56 | * |
||
57 | * @param Widget $widget |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | View Code Duplication | public function getWidgetBusinessEntityContent(Widget $widget) |
|
70 | |||
71 | /** |
||
72 | * Get the content of the widget by the entity linked to it. |
||
73 | * |
||
74 | * @param Widget $widget |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | View Code Duplication | public function getWidgetEntityContent(Widget $widget) |
|
88 | |||
89 | /** |
||
90 | * Get the content of the widget for the query mode. |
||
91 | * |
||
92 | * @param Widget $widget |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getWidgetQueryContent(Widget $widget) |
||
113 | |||
114 | /** |
||
115 | * Get the widget query result. |
||
116 | * |
||
117 | * @param Widget $widget The widget |
||
118 | * |
||
119 | * @return \Doctrine\ORM\QueryBuilder The list of entities |
||
120 | */ |
||
121 | public function getWidgetQueryBuilder(Widget $widget) |
||
132 | |||
133 | protected function populateParametersWithWidgetFields(Widget $widget, $entity, &$parameters) |
||
151 | |||
152 | /** |
||
153 | * @param QueryHelper $queryHelper |
||
154 | */ |
||
155 | public function setQueryHelper(QueryHelper $queryHelper) |
||
159 | |||
160 | /** |
||
161 | * @param EntityManager $entityManager |
||
162 | */ |
||
163 | public function setEntityManager(EntityManager $entityManager) |
||
167 | |||
168 | /** |
||
169 | * @param APIBusinessEntityResolver $resolver |
||
170 | */ |
||
171 | public function setApiBusinessEntityResolver(APIBusinessEntityResolver $resolver) |
||
175 | } |
||
176 |