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 |
||
| 15 | class HorizontalFormRenderer implements FormRendererInterface |
||
|
|
|||
| 16 | { |
||
| 17 | /** @var DOMDocument $dom */ |
||
| 18 | private $dom; |
||
| 19 | |||
| 20 | /** @var \DomElement $form */ |
||
| 21 | private $form; |
||
| 22 | |||
| 23 | /** @var bool $displayErrors */ |
||
| 24 | private $displayErrors; |
||
| 25 | |||
| 26 | public function __construct($name) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param FormInterface $form |
||
| 36 | * @param bool $displayErrors |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | View Code Duplication | public function render(FormInterface $form, $displayErrors = true) |
|
| 50 | |||
| 51 | /** |
||
| 52 | * @param FormInterface $form |
||
| 53 | */ |
||
| 54 | View Code Duplication | private function setFormAttributes(FormInterface $form) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * @param FormInterface $form |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | private function getMethod(FormInterface $form) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param FormInterface $form |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | private function getId(FormInterface $form) |
||
| 86 | |||
| 87 | private function processFields(FieldCollection $fields) |
||
| 98 | |||
| 99 | } |