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 |
||
| 25 | final class RaSecondFactorExportQuery implements HttpQuery |
||
| 26 | { |
||
| 27 | const STATUS_UNVERIFIED = 'unverified'; |
||
| 28 | const STATUS_VERIFIED = 'verified'; |
||
| 29 | const STATUS_VETTED = 'vetted'; |
||
| 30 | const STATUS_REVOKED = 'revoked'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | private $institution; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string|null |
||
| 39 | */ |
||
| 40 | private $name; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string|null |
||
| 44 | */ |
||
| 45 | private $type; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string|null The second factor type's ID (eg. Yubikey public ID) |
||
| 49 | */ |
||
| 50 | private $secondFactorId; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string|null |
||
| 54 | */ |
||
| 55 | private $email; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var string|null One of the STATUS_* constants. |
||
| 59 | */ |
||
| 60 | private $status; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var string|null |
||
| 64 | */ |
||
| 65 | private $orderBy; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var string|null |
||
| 69 | */ |
||
| 70 | private $orderDirection; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param string $institution |
||
| 74 | */ |
||
| 75 | public function __construct($institution) |
||
| 80 | |||
| 81 | public function getFileName() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @return null|string |
||
| 101 | */ |
||
| 102 | public function getName() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param null|string $name |
||
| 109 | */ |
||
| 110 | public function setName($name) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return null|string |
||
| 119 | */ |
||
| 120 | public function getType() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param null|string $type |
||
| 127 | */ |
||
| 128 | public function setType($type) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @return null|string |
||
| 137 | */ |
||
| 138 | public function getSecondFactorId() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @param null|string $secondFactorId |
||
| 145 | */ |
||
| 146 | public function setSecondFactorId($secondFactorId) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @return null|string |
||
| 155 | */ |
||
| 156 | public function getEmail() |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @param null|string $email |
||
| 163 | */ |
||
| 164 | public function setEmail($email) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @return null|string |
||
| 173 | */ |
||
| 174 | public function getInstitution() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param null|string $institution |
||
| 181 | */ |
||
| 182 | public function setInstitution($institution) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @return null|string |
||
| 189 | */ |
||
| 190 | public function getStatus() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @param string $status |
||
| 197 | */ |
||
| 198 | View Code Duplication | public function setStatus($status) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * @param string $orderBy |
||
| 210 | */ |
||
| 211 | public function setOrderBy($orderBy) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param string|null $orderDirection |
||
| 220 | */ |
||
| 221 | View Code Duplication | public function setOrderDirection($orderDirection) |
|
| 230 | |||
| 231 | private function assertNonEmptyString($value, $name) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Return the Http Query string as should be used, MUST include the '?' prefix. |
||
| 244 | * |
||
| 245 | * @return string |
||
| 246 | */ |
||
| 247 | public function toHttpQuery() |
||
| 267 | } |
||
| 268 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.