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 |
||
14 | View Code Duplication | class SubscriptionDeleteByTokenAction |
|
|
|||
15 | { |
||
16 | /** |
||
17 | * @var ResponseFactory |
||
18 | */ |
||
19 | private $responseFactory; |
||
20 | |||
21 | /** |
||
22 | * @var SubscriptionManager |
||
23 | */ |
||
24 | private $subscriptionManager; |
||
25 | |||
26 | /** |
||
27 | * SubscriptionDeleteByTokenAction constructor. |
||
28 | * |
||
29 | * @param ResponseFactory $responseFactory |
||
30 | * @param SubscriptionManager $subscriptionManager |
||
31 | */ |
||
32 | public function __construct(ResponseFactory $responseFactory, SubscriptionManager $subscriptionManager) |
||
37 | |||
38 | /** |
||
39 | * @apiVersion 1.0.0 |
||
40 | * @api {delete} /v1/subscriptions/:token Delete |
||
41 | * @apiName Delete |
||
42 | * @apiGroup Subscriptions |
||
43 | * @apiHeader {String} Accept application/json |
||
44 | * @apiParam {String{1..255}} :token Subscription token. |
||
45 | * @apiSuccessExample {json} Success-Response: |
||
46 | * HTTP/1.1 204 No Content |
||
47 | */ |
||
48 | |||
49 | /** |
||
50 | * Delete a subscription. |
||
51 | * |
||
52 | * @param string $token |
||
53 | * @return JsonResponse |
||
54 | */ |
||
55 | public function __invoke(string $token): JsonResponse |
||
61 | } |
||
62 |
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.