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 | abstract class BaseIDType |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * The security or administrative domain that qualifies the identifier. |
||
| 19 | * This attribute provides a means to federate identifiers from disparate user stores without collision. |
||
| 20 | * |
||
| 21 | * @see saml-core-2.0-os |
||
| 22 | * |
||
| 23 | * @var string|null |
||
| 24 | */ |
||
| 25 | public $NameQualifier = null; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Further qualifies an identifier with the name of a service provider or affiliation of providers. |
||
| 29 | * This attribute provides an additional means to federate identifiers on the basis of the relying party or parties. |
||
| 30 | * |
||
| 31 | * @see saml-core-2.0-os |
||
| 32 | * |
||
| 33 | * @var string|null |
||
| 34 | */ |
||
| 35 | public $SPNameQualifier = null; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The name for this BaseID. |
||
| 39 | * |
||
| 40 | * Override in classes extending this class to get the desired name. |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | protected $nodeName; |
||
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * Initialize a saml:BaseID, either from scratch or from an existing \DOMElement. |
||
| 49 | * |
||
| 50 | * @param \DOMElement|null $xml The XML element we should load, if any. |
||
| 51 | */ |
||
| 52 | public function __construct(\DOMElement $xml = null) |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * Convert this BaseID to XML. |
||
| 72 | * |
||
| 73 | * @param \DOMElement $element The element we are converting to XML. |
||
| 74 | * @return \DOMElement The XML element after adding the data corresponding to this BaseID. |
||
| 75 | */ |
||
| 76 | public function toXML(\DOMElement $parent = null) |
||
| 100 | |||
| 101 | |||
| 102 | /** |
||
| 103 | * Get a string representation of this BaseIDType object. |
||
| 104 | * |
||
| 105 | * @return string The resulting XML, as a string. |
||
| 106 | */ |
||
| 107 | public function __toString() |
||
| 117 | } |
||
| 118 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: