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 KeyDescriptor |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * What this key can be used for. |
||
| 19 | * |
||
| 20 | * 'encryption', 'signing' or null. |
||
| 21 | * |
||
| 22 | * @var string|null |
||
| 23 | */ |
||
| 24 | public $use; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The KeyInfo for this key. |
||
| 28 | * |
||
| 29 | * @var \SAML2\XML\ds\KeyInfo |
||
| 30 | */ |
||
| 31 | public $KeyInfo; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Supported EncryptionMethods. |
||
| 35 | * |
||
| 36 | * Array of \SAML2\XML\Chunk objects. |
||
| 37 | * |
||
| 38 | * @var \SAML2\XML\Chunk[] |
||
| 39 | */ |
||
| 40 | public $EncryptionMethod = array(); |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Initialize an KeyDescriptor. |
||
| 44 | * |
||
| 45 | * @param \DOMElement|null $xml The XML element we should load. |
||
| 46 | * @throws \Exception |
||
| 47 | */ |
||
| 48 | public function __construct(\DOMElement $xml = null) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Convert this KeyDescriptor to XML. |
||
| 73 | * |
||
| 74 | * @param \DOMElement $parent The element we should append this KeyDescriptor to. |
||
| 75 | * @return \DOMElement |
||
| 76 | */ |
||
| 77 | View Code Duplication | public function toXML(\DOMElement $parent) |
|
| 100 | } |
||
| 101 |
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.