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 |
||
34 | class AttachmentFormGroup extends AbstractFormGroup implements |
||
|
|||
35 | ConfigurableInterface, |
||
36 | NestedWidgetContainerInterface, |
||
37 | ObjectContainerInterface |
||
38 | { |
||
39 | use ConfigurableAttachmentsTrait; |
||
40 | use NestedWidgetContainerTrait; |
||
41 | use ObjectContainerTrait { |
||
42 | ObjectContainerTrait::createOrLoadObj as createOrCloneOrLoadObj; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | private $widgetId; |
||
49 | |||
50 | /** |
||
51 | * Store the widget factory instance for the current class. |
||
52 | * |
||
53 | * @var FactoryInterface |
||
54 | */ |
||
55 | private $widgetFactory; |
||
56 | |||
57 | /** |
||
58 | * Whether notes should be display before or after the form fields. |
||
59 | * |
||
60 | * @var boolean |
||
61 | */ |
||
62 | private $showNotesAbove = false; |
||
63 | |||
64 | /** |
||
65 | * Set the widget's data. |
||
66 | * |
||
67 | * @param array $data The widget data. |
||
68 | * @return self |
||
69 | */ |
||
70 | public function setData(array $data) |
||
87 | |||
88 | /** |
||
89 | * Retrieve the default nested widget options. |
||
90 | * |
||
91 | * @return array |
||
92 | */ |
||
93 | public function defaultWidgetData() |
||
102 | |||
103 | /** |
||
104 | * Retrieve the widget's ID. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | public function widgetId() |
||
116 | |||
117 | /** |
||
118 | * Set the widget's ID. |
||
119 | * |
||
120 | * @param string $widgetId The widget identifier. |
||
121 | * @return self |
||
122 | */ |
||
123 | public function setWidgetId($widgetId) |
||
129 | |||
130 | /** |
||
131 | * @return Translation|string|null |
||
132 | */ |
||
133 | public function description() |
||
137 | |||
138 | /** |
||
139 | * @return Translation|string|null |
||
140 | */ |
||
141 | public function notes() |
||
145 | |||
146 | /** |
||
147 | * Show/hide the widget's notes. |
||
148 | * |
||
149 | * @param boolean|string $show Whether to show or hide notes. |
||
150 | * @return self Chainable |
||
151 | */ |
||
152 | public function setShowNotes($show) |
||
159 | |||
160 | /** |
||
161 | * @return boolean |
||
162 | */ |
||
163 | public function showNotesAbove() |
||
167 | |||
168 | /** |
||
169 | * @param Container $container The DI container. |
||
170 | * @return void |
||
171 | */ |
||
172 | protected function setDependencies(Container $container) |
||
188 | |||
189 | /** |
||
190 | * Set the widget factory. |
||
191 | * |
||
192 | * @param FactoryInterface $factory The factory to create widgets. |
||
193 | * @return self |
||
194 | */ |
||
195 | protected function setWidgetFactory(FactoryInterface $factory) |
||
201 | |||
202 | /** |
||
203 | * Retrieve the widget factory. |
||
204 | * |
||
205 | * @return FactoryInterface |
||
206 | * @throws RuntimeException If the widget factory was not previously set. |
||
207 | */ |
||
208 | View Code Duplication | protected function widgetFactory() |
|
219 | } |
||
220 |