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 |
||
| 9 | View Code Duplication | class RequestOptions |
|
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var Url |
||
| 13 | */ |
||
| 14 | private $url; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var RequestTimeout |
||
| 18 | */ |
||
| 19 | private $requestTimeout; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var FollowRedirect |
||
| 23 | */ |
||
| 24 | private $followRedirect; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var BasicAuth|null |
||
| 28 | */ |
||
| 29 | private $basicAuth; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param $url |
||
| 33 | * @param RequestTimeout $requestTimeout |
||
| 34 | * @param FollowRedirect $followRedirect |
||
| 35 | * @param BasicAuth|null $basicAuth |
||
| 36 | */ |
||
| 37 | public function __construct( |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @return Url |
||
| 51 | */ |
||
| 52 | public function getUrl() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return RequestTimeout |
||
| 59 | */ |
||
| 60 | public function getRequestTimeout() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return FollowRedirect |
||
| 67 | */ |
||
| 68 | public function getFollowRedirect() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return BasicAuth|null |
||
| 75 | */ |
||
| 76 | public function getBasicAuth() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return bool |
||
| 83 | */ |
||
| 84 | public function needsBasicAuth() |
||
| 88 | } |
||
| 89 |