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 |
||
9 | View Code Duplication | class RefreshTokenController |
|
|
|||
10 | { |
||
11 | /** |
||
12 | * The server manager. |
||
13 | * |
||
14 | * @var \CodexShaper\OAuth2\Server\Manager |
||
15 | */ |
||
16 | protected $manager; |
||
17 | |||
18 | /** |
||
19 | * The authorization server. |
||
20 | * |
||
21 | * @var \League\OAuth2\Server\AuthorizationServer |
||
22 | */ |
||
23 | protected $server; |
||
24 | |||
25 | /** |
||
26 | * The psr7 server request. |
||
27 | * |
||
28 | * @var \CodexShaper\OAuth2\Server\Http\Requests\ServerRequest |
||
29 | */ |
||
30 | protected $request; |
||
31 | |||
32 | /** |
||
33 | * The psr7 server response. |
||
34 | * |
||
35 | * @var \CodexShaper\OAuth2\Server\Http\Responses\ServerResponse |
||
36 | */ |
||
37 | protected $response; |
||
38 | |||
39 | /** |
||
40 | * Create a new refresh token controller instance. |
||
41 | * |
||
42 | * @return void |
||
43 | */ |
||
44 | public function __construct() |
||
51 | |||
52 | /** |
||
53 | * Make access token. |
||
54 | * |
||
55 | * @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface |
||
56 | */ |
||
57 | public function issueAccessToken() |
||
69 | } |
||
70 |
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.