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() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Retrieve the widget's ID. |
||
| 109 | * |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | public function widgetId() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Set the widget's ID. |
||
| 123 | * |
||
| 124 | * @param string $widgetId The widget identifier. |
||
| 125 | * @return self |
||
| 126 | */ |
||
| 127 | public function setWidgetId($widgetId) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return Translation|string|null |
||
| 136 | */ |
||
| 137 | public function description() |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @return Translation|string|null |
||
| 144 | */ |
||
| 145 | public function notes() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Show/hide the widget's notes. |
||
| 152 | * |
||
| 153 | * @param boolean|string $show Whether to show or hide notes. |
||
| 154 | * @return self Chainable |
||
| 155 | */ |
||
| 156 | public function setShowNotes($show) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return boolean |
||
| 166 | */ |
||
| 167 | public function showNotesAbove() |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @param Container $container The DI container. |
||
| 174 | * @return void |
||
| 175 | */ |
||
| 176 | protected function setDependencies(Container $container) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Set the widget factory. |
||
| 195 | * |
||
| 196 | * @param FactoryInterface $factory The factory to create widgets. |
||
| 197 | * @return self |
||
| 198 | */ |
||
| 199 | protected function setWidgetFactory(FactoryInterface $factory) |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Retrieve the widget factory. |
||
| 208 | * |
||
| 209 | * @return FactoryInterface |
||
| 210 | * @throws RuntimeException If the widget factory was not previously set. |
||
| 211 | */ |
||
| 212 | View Code Duplication | protected function widgetFactory() |
|
| 223 | } |
||
| 224 |