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 |
||
| 18 | View Code Duplication | class ValidatorDescriptor extends AbstractDescriptor |
|
|
|
|||
| 19 | implements Traits\ArgsInterface, |
||
| 20 | Traits\TypeInterface, |
||
| 21 | Traits\NameInterface, |
||
| 22 | Traits\CustomArgInterface, |
||
| 23 | WriteXmlInterface |
||
| 24 | { |
||
| 25 | use Traits\ArgsTrait, Traits\TypeTrait, Traits\IdTrait, Traits\NameTrait; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param $element |
||
| 29 | */ |
||
| 30 | 15 | public function __construct(DOMElement $element = null) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @param DOMElement $element |
||
| 41 | * |
||
| 42 | * @return void |
||
| 43 | */ |
||
| 44 | 12 | protected function init(DOMElement $element) |
|
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * Создает DOMElement - эквивалентный состоянию дескриптора |
||
| 56 | * |
||
| 57 | * @param DOMDocument $dom |
||
| 58 | * |
||
| 59 | * @return DOMElement |
||
| 60 | * @throws InvalidDescriptorException |
||
| 61 | * @throws \OldTown\Workflow\Exception\InvalidWriteWorkflowException |
||
| 62 | */ |
||
| 63 | 7 | public function writeXml(DOMDocument $dom = null) |
|
| 95 | |||
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $key |
||
| 99 | * @param string $value |
||
| 100 | * |
||
| 101 | * @return boolean |
||
| 102 | */ |
||
| 103 | 5 | public function flagUseCustomArgWriter($key, $value) |
|
| 109 | |||
| 110 | /** |
||
| 111 | * Генерирует значение аргумента |
||
| 112 | * |
||
| 113 | * @param $key |
||
| 114 | * @param $value |
||
| 115 | * |
||
| 116 | * @param DOMElement $argElement |
||
| 117 | * |
||
| 118 | * @return string |
||
| 119 | */ |
||
| 120 | 4 | public function buildArgValue($key, $value, DOMElement $argElement) |
|
| 126 | } |
||
| 127 |
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.