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 |
||
13 | View Code Duplication | class SandboxStrategy implements AuthStrategyInterface |
|
|
|||
14 | { |
||
15 | |||
16 | const NAME = 'adnx_auth_strategy'; |
||
17 | |||
18 | const BASE_URL = 'https://api-beta.demdex.com/oauth/token'; |
||
19 | |||
20 | const CACHE_NAMESPACE = 'adnx_auth_token'; |
||
21 | const TOKEN_EXPIRATION = 110; |
||
22 | |||
23 | /** @var Cache */ |
||
24 | protected $cache; |
||
25 | |||
26 | /** |
||
27 | * AdnxStrategy constructor. |
||
28 | * |
||
29 | * @param ClientInterface $clientInterface |
||
30 | * @param Cache|null $cache |
||
31 | */ |
||
32 | public function __construct(ClientInterface $clientInterface, Cache $cache) |
||
37 | |||
38 | /** |
||
39 | * @param string $clientId |
||
40 | * @param string $secretKey |
||
41 | * @param string $username |
||
42 | * @param $password |
||
43 | * @param bool $cache |
||
44 | * @param bool $refresh |
||
45 | * @return mixed |
||
46 | * @throws AuthException |
||
47 | */ |
||
48 | public function authenticate($clientId, $secretKey, $username, $password, $cache = true, $refresh = false) |
||
101 | |||
102 | /** |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getSlug() |
||
109 | |||
110 | public function authenticateJwtToken($clientId, $clientSecret, $jwtToken, $cache = true) |
||
114 | } |
||
115 |
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.