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 |
||
| 16 | View Code Duplication | class Auth |
|
|
1 ignored issue
–
show
|
|||
| 17 | { |
||
| 18 | /** @var TwitchRequest */ |
||
| 19 | protected $request; |
||
| 20 | |||
| 21 | const URI_AUTH = 'oauth2/authorize'; |
||
| 22 | const URI_AUTH_TOKEN = 'oauth2/token'; |
||
| 23 | |||
| 24 | public function __construct(TwitchRequest $request) |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Get login URL for authentication |
||
| 31 | * @param string $queryString |
||
| 32 | * @return string |
||
| 33 | * @throws TwitchException |
||
| 34 | */ |
||
| 35 | public function getLoginURL($queryString) |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Get authentication access token |
||
| 42 | * @param string $queryString |
||
| 43 | * @return \stdClass |
||
| 44 | * @throws TwitchException |
||
| 45 | */ |
||
| 46 | public function getAccessToken($queryString) |
||
| 50 | } |
||
| 51 |
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.