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 AbstractCurlHttpAdapter extends AbstractHttpAdapter |
||
20 | { |
||
21 | /** |
||
22 | * @param ConfigurationInterface|null $configuration |
||
23 | * @param bool $checkExtension |
||
24 | * |
||
25 | * @throws HttpAdapterException |
||
26 | */ |
||
27 | 4300 | public function __construct(ConfigurationInterface $configuration = null, $checkExtension = true) |
|
35 | |||
36 | /** |
||
37 | * @param InternalRequestInterface $internalRequest |
||
38 | * |
||
39 | * @return int |
||
40 | */ |
||
41 | 1344 | protected function prepareProtocolVersion(InternalRequestInterface $internalRequest) |
|
47 | |||
48 | /** |
||
49 | * @param InternalRequestInterface $internalRequest |
||
50 | * |
||
51 | * @return array|string |
||
52 | */ |
||
53 | 3152 | protected function prepareContent(InternalRequestInterface $internalRequest) |
|
73 | |||
74 | /** |
||
75 | * @param string $file |
||
76 | * |
||
77 | * @return mixed |
||
78 | */ |
||
79 | 240 | protected function createFile($file) |
|
83 | |||
84 | /** |
||
85 | * @return bool |
||
86 | */ |
||
87 | 240 | protected function isSafeUpload() |
|
91 | |||
92 | /** |
||
93 | * @param string $name |
||
94 | * @param array|string $data |
||
95 | * @param bool $isFile |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | 400 | private function prepareRawContent($name, $data, $isFile = false) |
|
116 | } |
||
117 |
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.