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 |
||
| 12 | class DigestMethod |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * An URI identifying an algorithm supported for digest operations. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | public $Algorithm; |
||
| 20 | |||
| 21 | |||
| 22 | /** |
||
| 23 | * Create/parse an alg:DigestMethod element. |
||
| 24 | * |
||
| 25 | * @param \DOMElement|null $xml The XML element we should load or null to create a new one from scratch. |
||
| 26 | * |
||
| 27 | * @throws \Exception |
||
| 28 | */ |
||
| 29 | public function __construct(\DOMElement $xml = null) |
||
| 40 | |||
| 41 | |||
| 42 | /** |
||
| 43 | * Convert this element to XML. |
||
| 44 | * |
||
| 45 | * @param \DOMElement $parent The element we should append to. |
||
| 46 | * @return \DOMElement |
||
| 47 | */ |
||
| 48 | View Code Duplication | public function toXML(\DOMElement $parent) |
|
| 59 | } |
||
| 60 |
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.