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 |
||
| 20 | class SubjectConfirmationData extends AbstractSamlModel |
||
| 21 | { |
||
| 22 | /** @var int|null */ |
||
| 23 | protected $notBefore; |
||
| 24 | |||
| 25 | /** @var int|null */ |
||
| 26 | protected $notOnOrAfter; |
||
| 27 | |||
| 28 | /** @var string|null */ |
||
| 29 | protected $address; |
||
| 30 | |||
| 31 | /** @var string|null */ |
||
| 32 | protected $inResponseTo; |
||
| 33 | |||
| 34 | /** @var string|null */ |
||
| 35 | protected $recipient; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param null|string $address |
||
| 39 | * |
||
| 40 | * @return SubjectConfirmationData |
||
| 41 | */ |
||
| 42 | 2 | public function setAddress($address) |
|
| 48 | |||
| 49 | /** |
||
| 50 | * @return null|string |
||
| 51 | */ |
||
| 52 | 4 | public function getAddress() |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @param null|string $inResponseTo |
||
| 59 | * |
||
| 60 | * @return SubjectConfirmationData |
||
| 61 | */ |
||
| 62 | 9 | public function setInResponseTo($inResponseTo) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * @return null|string |
||
| 71 | */ |
||
| 72 | 8 | public function getInResponseTo() |
|
| 76 | |||
| 77 | /** |
||
| 78 | * @param int|string|\DateTime $notBefore |
||
| 79 | * |
||
| 80 | * @return SubjectConfirmationData |
||
| 81 | */ |
||
| 82 | 2 | public function setNotBefore($notBefore) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * @return int|null |
||
| 91 | */ |
||
| 92 | 5 | public function getNotBeforeTimestamp() |
|
| 96 | |||
| 97 | /** |
||
| 98 | * @return string|null |
||
| 99 | */ |
||
| 100 | 4 | public function getNotBeforeString() |
|
| 108 | |||
| 109 | /** |
||
| 110 | * @return \DateTime|null |
||
| 111 | */ |
||
| 112 | public function getNotBeforeDateTime() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param int|string|\DateTime $notOnOrAfter |
||
| 123 | * |
||
| 124 | * @return SubjectConfirmationData |
||
| 125 | */ |
||
| 126 | 11 | public function setNotOnOrAfter($notOnOrAfter) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * @return int|null |
||
| 135 | */ |
||
| 136 | 4 | public function getNotOnOrAfterTimestamp() |
|
| 140 | |||
| 141 | /** |
||
| 142 | * @return string|null |
||
| 143 | */ |
||
| 144 | 5 | public function getNotOnOrAfterString() |
|
| 152 | |||
| 153 | /** |
||
| 154 | * @return \DateTime|null |
||
| 155 | */ |
||
| 156 | 3 | public function getNotOnOrAfterDateTime() |
|
| 164 | |||
| 165 | /** |
||
| 166 | * @param null|string $recipient |
||
| 167 | * |
||
| 168 | * @return SubjectConfirmationData |
||
| 169 | */ |
||
| 170 | 10 | public function setRecipient($recipient) |
|
| 176 | |||
| 177 | /** |
||
| 178 | * @return null|string |
||
| 179 | */ |
||
| 180 | 11 | public function getRecipient() |
|
| 184 | |||
| 185 | /** |
||
| 186 | * @param \DOMNode $parent |
||
| 187 | * @param SerializationContext $context |
||
| 188 | * |
||
| 189 | * @return void |
||
| 190 | */ |
||
| 191 | 4 | public function serialize(\DOMNode $parent, SerializationContext $context) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * @param \DOMNode $node |
||
| 203 | * @param DeserializationContext $context |
||
| 204 | */ |
||
| 205 | 3 | View Code Duplication | public function deserialize(\DOMNode $node, DeserializationContext $context) |
| 213 | } |
||
| 214 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: