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 |
||
19 | abstract class AbstractNode implements NodeInterface |
||
20 | { |
||
21 | /** |
||
22 | * json content type |
||
23 | * @const array JSON_CONTENT_TYPE |
||
24 | */ |
||
25 | const JSON_CONTENT_TYPE = [ |
||
26 | 'Content-Type' => 'application/json', |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * client |
||
31 | * @var \Unikorp\KongAdminApi\Client $client |
||
32 | */ |
||
33 | private $client = null; |
||
34 | |||
35 | /** |
||
36 | * Constructor |
||
37 | * |
||
38 | * @param \Unikorp\KongAdminApi\Client $client |
||
39 | */ |
||
40 | 5 | public function __construct(Client $client) |
|
44 | |||
45 | /** |
||
46 | * get |
||
47 | * |
||
48 | * @param string $endpoint |
||
49 | * |
||
50 | * @return \Psr\Http\Message\ResponseInterface |
||
51 | */ |
||
52 | 12 | protected function get($endpoint) |
|
56 | |||
57 | /** |
||
58 | * post |
||
59 | * |
||
60 | * @param string $endpoint |
||
61 | * @param DocumentInterface $document |
||
62 | * |
||
63 | * @return \Psr\Http\Message\ResponseInterface |
||
64 | */ |
||
65 | 3 | View Code Duplication | protected function post($endpoint, DocumentInterface $document = null) |
73 | |||
74 | /** |
||
75 | * put |
||
76 | * |
||
77 | * @param string $endpoint |
||
78 | * @param DocumentInterface $document |
||
79 | * |
||
80 | * @return \Psr\Http\Message\ResponseInterface |
||
81 | */ |
||
82 | 3 | View Code Duplication | protected function put($endpoint, DocumentInterface $document = null) |
90 | |||
91 | /** |
||
92 | * patch |
||
93 | * |
||
94 | * @param string $endpoint |
||
95 | * @param DocumentInterface $document |
||
96 | * |
||
97 | * @return \Psr\Http\Message\ResponseInterface |
||
98 | */ |
||
99 | 3 | View Code Duplication | protected function patch($endpoint, DocumentInterface $document = null) |
107 | |||
108 | /** |
||
109 | * delete |
||
110 | * |
||
111 | * @param string $endpoint |
||
112 | * @param DocumentInterface $document |
||
113 | * |
||
114 | * @return \Psr\Http\Message\ResponseInterface |
||
115 | */ |
||
116 | 4 | View Code Duplication | protected function delete($endpoint, DocumentInterface $document = null) |
124 | } |
||
125 |
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.