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 | class AuthenticateAction extends AbstractRestAction |
||
17 | { |
||
18 | /** |
||
19 | * @var TranslatorInterface |
||
20 | */ |
||
21 | private $translator; |
||
22 | /** |
||
23 | * @var ApiKeyService|ApiKeyServiceInterface |
||
24 | */ |
||
25 | private $apiKeyService; |
||
26 | /** |
||
27 | * @var JWTServiceInterface |
||
28 | */ |
||
29 | private $jwtService; |
||
30 | |||
31 | /** |
||
32 | * AuthenticateAction constructor. |
||
33 | * @param ApiKeyServiceInterface|ApiKeyService $apiKeyService |
||
34 | * @param JWTServiceInterface|JWTService $jwtService |
||
35 | * @param TranslatorInterface $translator |
||
36 | * |
||
37 | * @Inject({ApiKeyService::class, JWTService::class, "translator"}) |
||
38 | */ |
||
39 | 3 | public function __construct( |
|
48 | |||
49 | /** |
||
50 | * @param Request $request |
||
51 | * @param Response $response |
||
52 | * @param callable|null $out |
||
53 | * @return null|Response |
||
54 | */ |
||
55 | 3 | public function dispatch(Request $request, Response $response, callable $out = null) |
|
80 | } |
||
81 |
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.