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 |
||
| 14 | class RoleDescriptor extends SignedElementHelper |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * The name of this descriptor element. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | private $elementName; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The ID of this element. |
||
| 25 | * |
||
| 26 | * @var string|null |
||
| 27 | */ |
||
| 28 | public $ID; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * How long this element is valid, as a unix timestamp. |
||
| 32 | * |
||
| 33 | * @var int|null |
||
| 34 | */ |
||
| 35 | public $validUntil; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The length of time this element can be cached, as string. |
||
| 39 | * |
||
| 40 | * @var string|null |
||
| 41 | */ |
||
| 42 | public $cacheDuration; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * List of supported protocols. |
||
| 46 | * |
||
| 47 | * @var array |
||
| 48 | */ |
||
| 49 | public $protocolSupportEnumeration = array(); |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Error URL for this role. |
||
| 53 | * |
||
| 54 | * @var string|null |
||
| 55 | */ |
||
| 56 | public $errorURL; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Extensions on this element. |
||
| 60 | * |
||
| 61 | * Array of extension elements. |
||
| 62 | * |
||
| 63 | * @var array |
||
| 64 | */ |
||
| 65 | public $Extensions = array(); |
||
| 66 | |||
| 67 | /** |
||
| 68 | * KeyDescriptor elements. |
||
| 69 | * |
||
| 70 | * Array of \SAML2\XML\md\KeyDescriptor elements. |
||
| 71 | * |
||
| 72 | * @var \SAML2\XML\md\KeyDescriptor[] |
||
| 73 | */ |
||
| 74 | public $KeyDescriptor = array(); |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Organization of this role. |
||
| 78 | * |
||
| 79 | * @var \SAML2\XML\md\Organization|null |
||
| 80 | */ |
||
| 81 | public $Organization = null; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * ContactPerson elements for this role. |
||
| 85 | * |
||
| 86 | * Array of \SAML2\XML\md\ContactPerson objects. |
||
| 87 | * |
||
| 88 | * @var \SAML2\XML\md\ContactPerson[] |
||
| 89 | */ |
||
| 90 | public $ContactPerson = array(); |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Initialize a RoleDescriptor. |
||
| 94 | * |
||
| 95 | * @param string $elementName The name of this element. |
||
| 96 | * @param \DOMElement|null $xml The XML element we should load. |
||
| 97 | * @throws \Exception |
||
| 98 | */ |
||
| 99 | protected function __construct($elementName, \DOMElement $xml = null) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Add this RoleDescriptor to an EntityDescriptor. |
||
| 149 | * |
||
| 150 | * @param \DOMElement $parent The EntityDescriptor we should append this endpoint to. |
||
| 151 | * @return \DOMElement |
||
| 152 | */ |
||
| 153 | protected function toXML(\DOMElement $parent) |
||
| 202 | } |
||
| 203 |
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.