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 |
||
7 | View Code Duplication | class RequestTimeout |
|
8 | { |
||
9 | use EnsureIsIntegerTrait; |
||
10 | use EnsureIsGreaterThanTrait; |
||
11 | |||
12 | const IN_SECONDS_IS_NOT_AN_INTEGER = 1; |
||
13 | const IN_SECONDS_IS_TOO_SMALL = 2; |
||
14 | |||
15 | /** |
||
16 | * @var int |
||
17 | */ |
||
18 | private $inSeconds; |
||
19 | |||
20 | /** |
||
21 | * @param int $inSeconds |
||
22 | */ |
||
23 | public function __construct($inSeconds) |
||
29 | |||
30 | /** |
||
31 | * @return int |
||
32 | */ |
||
33 | public function inSeconds() |
||
37 | |||
38 | /** |
||
39 | * @param mixed $inSeconds |
||
40 | */ |
||
41 | private function ensureInSeconds($inSeconds) |
||
56 | } |
||
57 |