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) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param Authenticatable $user |
||
| 55 | * @return void |
||
| 56 | */ |
||
| 57 | public function handleFailed(Authenticatable $user) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param array $payload |
||
| 65 | * @return void |
||
| 66 | */ |
||
| 67 | public function handleLockout(array $payload = []) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param Authenticatable $user |
||
| 81 | * @param Agent|null $agent |
||
| 82 | * @return Device |
||
| 83 | */ |
||
| 84 | public function findOrCreateUserDeviceByAgent(Authenticatable $user, Agent $agent = null) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @param Authenticatable $user |
||
| 98 | * @param Agent $agent |
||
| 99 | * @return Device|null |
||
| 100 | */ |
||
| 101 | View Code Duplication | public function findUserDeviceByAgent(Authenticatable $user, Agent $agent) |
|
| 113 | |||
| 114 | /** |
||
| 115 | * @param Authenticatable $user |
||
| 116 | * @param Agent $agent |
||
| 117 | * @return Device |
||
| 118 | */ |
||
| 119 | public function createUserDeviceByAgent(Authenticatable $user, Agent $agent) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @param Collection|null $request |
||
| 141 | * @return Authenticatable|null |
||
| 142 | */ |
||
| 143 | public function findUserFromPayload(Collection $payload = null) |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param Authenticatable $user |
||
| 160 | * @param Device $device |
||
| 161 | * @param string $type |
||
| 162 | * @return Login |
||
| 163 | */ |
||
| 164 | public function createUserLoginForDevice(Authenticatable $user, Device $device, $type = Login::TYPE_LOGIN) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @param Authenticatable $user |
||
| 184 | * @param Agent $agent |
||
| 185 | * @return false|Device |
||
| 186 | */ |
||
| 187 | View Code Duplication | public function findDeviceForUser(Authenticatable $user, Agent $agent) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * @param Device $device |
||
| 202 | * @return bool |
||
| 203 | */ |
||
| 204 | public function shouldLogDeviceLogin(Device $device) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @param Device $device |
||
| 224 | * @param Agent $agent |
||
| 225 | * @return bool |
||
| 226 | */ |
||
| 227 | public function deviceMatch(Device $device, Agent $agent, array $attributes = null) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @param void |
||
| 257 | * @return array |
||
| 258 | */ |
||
| 259 | public function getDeviceMatchingAttributesConfig() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param void |
||
| 271 | * @return int |
||
| 272 | */ |
||
| 273 | public function getLoginThrottleConfig() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return string |
||
| 280 | */ |
||
| 281 | public function getLoginColumnConfig() |
||
| 285 | } |
||
| 286 |