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 | class SessionLifetimeGuard |
||
26 | { |
||
27 | /** |
||
28 | * @var TimeFrame |
||
29 | */ |
||
30 | private $relativeTimeoutLimit; |
||
31 | /** |
||
32 | * @var TimeFrame |
||
33 | */ |
||
34 | private $absoluteTimeoutLimit; |
||
35 | |||
36 | public function __construct(TimeFrame $absoluteTimeoutLimit, TimeFrame $relativeTimeoutLimit) |
||
41 | |||
42 | /** |
||
43 | * @param AuthenticatedSessionStateHandler $sessionStateHandler |
||
44 | * @return bool |
||
45 | */ |
||
46 | public function sessionLifetimeWithinLimits(AuthenticatedSessionStateHandler $sessionStateHandler) |
||
51 | |||
52 | /** |
||
53 | * @param AuthenticatedSessionStateHandler $sessionStateHandler |
||
54 | * @return bool |
||
55 | */ |
||
56 | View Code Duplication | public function sessionLifetimeWithinAbsoluteLimit(AuthenticatedSessionStateHandler $sessionStateHandler) |
|
72 | |||
73 | /** |
||
74 | * @param AuthenticatedSessionStateHandler $sessionStateHandler |
||
75 | * @return bool |
||
76 | */ |
||
77 | View Code Duplication | public function sessionLifetimeWithinRelativeLimit(AuthenticatedSessionStateHandler $sessionStateHandler) |
|
93 | } |
||
94 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.