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 |
||
| 21 | class JoinDescriptor extends AbstractDescriptor implements ValidateDescriptorInterface, WriteXmlInterface |
||
| 22 | { |
||
| 23 | use Traits\IdTrait; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var ConditionsDescriptor[]|SplObjectStorage |
||
| 27 | */ |
||
| 28 | protected $conditions; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var ResultDescriptor |
||
| 32 | */ |
||
| 33 | protected $result; |
||
| 34 | |||
| 35 | |||
| 36 | /** |
||
| 37 | * @param $element |
||
| 38 | */ |
||
| 39 | 20 | View Code Duplication | public function __construct(DOMElement $element = null) |
| 50 | |||
| 51 | /** |
||
| 52 | * @param DOMElement $join |
||
| 53 | * |
||
| 54 | * @return void |
||
| 55 | */ |
||
| 56 | 17 | protected function init(DOMElement $join) |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @return ConditionsDescriptor[]|SplObjectStorage |
||
| 77 | */ |
||
| 78 | 15 | public function getConditions() |
|
| 82 | |||
| 83 | /** |
||
| 84 | * @return ResultDescriptor |
||
| 85 | */ |
||
| 86 | 15 | public function getResult() |
|
| 90 | |||
| 91 | /** |
||
| 92 | * @param ResultDescriptor $result |
||
| 93 | * |
||
| 94 | * @return $this |
||
| 95 | */ |
||
| 96 | 16 | public function setResult(ResultDescriptor $result) |
|
| 102 | |||
| 103 | |||
| 104 | /** |
||
| 105 | * Валидация дескриптора |
||
| 106 | * |
||
| 107 | * @return void |
||
| 108 | * @throws InvalidWorkflowDescriptorException |
||
| 109 | */ |
||
| 110 | 13 | View Code Duplication | public function validate() |
| 123 | |||
| 124 | /** |
||
| 125 | * Создает DOMElement - эквивалентный состоянию дескриптора |
||
| 126 | * |
||
| 127 | * @param DOMDocument $dom |
||
| 128 | * |
||
| 129 | * @return DOMElement|null |
||
| 130 | * @throws InvalidDescriptorException |
||
| 131 | * @throws InvalidWriteWorkflowException |
||
| 132 | */ |
||
| 133 | 15 | public function writeXml(DOMDocument $dom = null) |
|
| 165 | } |
||
| 166 |
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.