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 |
||
30 | class Webhook extends HttpApi |
||
31 | { |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $apiKey; |
||
36 | |||
37 | 8 | public function __construct(ClientInterface $httpClient, RequestBuilder $requestBuilder, Hydrator $hydrator, string $apiKey) |
|
42 | |||
43 | /** |
||
44 | * This function verifies the webhook signature with your API key to to see if it is authentic. |
||
45 | * |
||
46 | * If this function returns FALSE, you must not process the request. |
||
47 | * You should reject the request with status code 403 Forbidden. |
||
48 | */ |
||
49 | 3 | public function verifyWebhookSignature(int $timestamp, string $token, string $signature): bool |
|
64 | |||
65 | /** |
||
66 | * @return IndexResponse|ResponseInterface |
||
67 | */ |
||
68 | 1 | public function index(string $domain) |
|
75 | |||
76 | /** |
||
77 | * @return ShowResponse|ResponseInterface |
||
78 | */ |
||
79 | 1 | View Code Duplication | public function show(string $domain, string $webhook) |
87 | |||
88 | /** |
||
89 | * @return CreateResponse|ResponseInterface |
||
90 | */ |
||
91 | 1 | View Code Duplication | public function create(string $domain, string $id, array $url) |
106 | |||
107 | /** |
||
108 | * @return UpdateResponse|ResponseInterface |
||
109 | */ |
||
110 | 1 | View Code Duplication | public function update(string $domain, string $id, array $url) |
124 | |||
125 | /** |
||
126 | * @return DeleteResponse|ResponseInterface |
||
127 | */ |
||
128 | 1 | View Code Duplication | public function delete(string $domain, string $id) |
137 | } |
||
138 |
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.