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 |
||
17 | class AuthChecker |
||
18 | { |
||
19 | /** @var Application */ |
||
20 | private $app; |
||
21 | |||
22 | /** @var Request */ |
||
23 | private $request; |
||
24 | |||
25 | /** @var Config */ |
||
26 | private $config; |
||
27 | |||
28 | /** |
||
29 | * AuthChecker |
||
30 | * |
||
31 | * @param Application $app |
||
32 | */ |
||
33 | public function __construct(Application $app, Request $request) |
||
39 | |||
40 | /** |
||
41 | * @param Authenticatable $user |
||
42 | * @return void |
||
43 | */ |
||
44 | public function handleLogin(Authenticatable $user) |
||
57 | |||
58 | /** |
||
59 | * @param Authenticatable $user |
||
60 | * @param Agent $agent |
||
61 | * @return Device|null |
||
62 | */ |
||
63 | public function findOrCreateUserDeviceByAgent(Authenticatable $user, Agent $agent) |
||
73 | |||
74 | /** |
||
75 | * @param Authenticatable $user |
||
76 | * @param Agent $agent |
||
77 | * @return Device|null |
||
78 | */ |
||
79 | View Code Duplication | public function findUserDeviceByAgent(Authenticatable $user, Agent $agent) |
|
91 | |||
92 | /** |
||
93 | * @param Model $user |
||
94 | * @param Agent $agent |
||
95 | * @return Device |
||
96 | */ |
||
97 | public function createUserDeviceByAgent(Model $user, Agent $agent) |
||
114 | |||
115 | /** |
||
116 | * @param Model $user |
||
117 | * @param Device $device |
||
118 | * @return Login |
||
119 | */ |
||
120 | public function createUserLoginForDevice(Model $user, Device $device) |
||
129 | |||
130 | /** |
||
131 | * @param Model $user |
||
132 | * @param Agent $agent |
||
133 | * @return false|Device |
||
134 | */ |
||
135 | View Code Duplication | public function findDeviceForUser(Model $user, Agent $agent) |
|
147 | |||
148 | /** |
||
149 | * @param Device $device |
||
150 | * @return bool |
||
151 | */ |
||
152 | public function shouldLogDeviceLogin(Device $device) |
||
173 | |||
174 | /** |
||
175 | * @param Device $device |
||
176 | * @param Agent $agent |
||
177 | * @return bool |
||
178 | */ |
||
179 | public function deviceMatch(Device $device, Agent $agent, array $attributes = null) |
||
206 | |||
207 | /** |
||
208 | * @param void |
||
209 | * @return array |
||
210 | */ |
||
211 | public function getDeviceMatchingAttributes() |
||
220 | |||
221 | /** |
||
222 | * @param void |
||
223 | * @return int |
||
224 | */ |
||
225 | public function getLoginThrottle() |
||
229 | } |
||
230 |