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 |
||
24 | class PaystackAdapter implements AdapterInterface |
||
25 | { |
||
26 | use Pluggable, Payable, VerifyHttpStatusResponseCode; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | const API_LINK = 'https://api.paystack.co'; |
||
32 | |||
33 | /** |
||
34 | * @var \GuzzleHttp\Client |
||
35 | */ |
||
36 | protected $httpClient; |
||
37 | |||
38 | /** |
||
39 | * The Api link for paystack |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $baseUrl; |
||
43 | |||
44 | /** |
||
45 | * PaystackAdapter constructor. |
||
46 | * @param \GuzzleHttp\Client|null $client |
||
47 | */ |
||
48 | 25 | public function __construct(Client $client = null) |
|
54 | |||
55 | 25 | protected function registerPlugins() |
|
60 | |||
61 | /** |
||
62 | * @param array $data |
||
63 | * @return string The authorization url to render the secure payment gateway. |
||
64 | */ |
||
65 | 2 | public function charge(array $data) |
|
73 | |||
74 | /** |
||
75 | * @param \Psr\Http\Message\ResponseInterface $response |
||
76 | * @return mixed |
||
77 | */ |
||
78 | 1 | protected function decodeResponse(ResponseInterface $response) |
|
82 | |||
83 | /** |
||
84 | * @return \GuzzleHttp\Client |
||
85 | */ |
||
86 | 16 | public function getHttpClient(): Client |
|
90 | |||
91 | /** |
||
92 | * @codeCoverageIgnore |
||
93 | * @param string $token |
||
94 | * @return \GuzzleHttp\Client |
||
95 | */ |
||
96 | View Code Duplication | protected function setHttpClient(string $token) : Client |
|
109 | } |
||
110 |
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.