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 |
||
13 | class MultiPartLocation extends AbstractLocation |
||
14 | { |
||
15 | /** @var string $contentType */ |
||
16 | protected $contentType = 'multipart/form-data; boundary='; |
||
17 | |||
18 | /** @var array $formParamsData */ |
||
19 | protected $multipartData = []; |
||
20 | |||
21 | /** |
||
22 | * Set the name of the location |
||
23 | * |
||
24 | * @param string $locationName |
||
25 | */ |
||
26 | 1 | public function __construct($locationName = 'multipart') |
|
30 | |||
31 | /** |
||
32 | * @param CommandInterface $command |
||
33 | * @param RequestInterface $request |
||
34 | * @param Parameter $param |
||
35 | * @return RequestInterface |
||
36 | */ |
||
37 | 1 | View Code Duplication | public function visit( |
49 | |||
50 | |||
51 | /** |
||
52 | * @param CommandInterface $command |
||
53 | * @param RequestInterface $request |
||
54 | * @param Operation $operation |
||
55 | * @return RequestInterface |
||
56 | */ |
||
57 | 1 | public function after( |
|
76 | } |
||
77 |
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.