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 |
||
7 | View Code Duplication | class YourMembershipRequestException extends YourMembershipException |
|
|
|||
8 | { |
||
9 | |||
10 | /** |
||
11 | * Arguments used for the Request |
||
12 | * @var array |
||
13 | */ |
||
14 | private $arguments; |
||
15 | |||
16 | /** |
||
17 | * Api Method That is related to this exception |
||
18 | * @var string |
||
19 | */ |
||
20 | private $apiMethod; |
||
21 | |||
22 | 3 | public function __construct(string $message, int $code = 0, string $apiMethod, array $arguments, \Exception $e = null) |
|
28 | |||
29 | /** |
||
30 | * Returns the arguments for API Request |
||
31 | * @method getArguments |
||
32 | * @author PA |
||
33 | * @date 2017-01-12 |
||
34 | * @return array |
||
35 | */ |
||
36 | |||
37 | 1 | public function getArguments() : array |
|
41 | |||
42 | /** |
||
43 | * Returns the arguments for API Request |
||
44 | * @method getArguments |
||
45 | * @author PA |
||
46 | * @date 2017-01-12 |
||
47 | * @return array |
||
48 | */ |
||
49 | |||
50 | 1 | public function getApiMethodName() : string |
|
54 | |||
55 | } |
||
56 |
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.