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 |
||
9 | View Code Duplication | class RestSystemException extends \Exception { |
|
|
|||
10 | /* |
||
11 | * @var int - override the default http status code if needed |
||
12 | */ |
||
13 | protected $httpStatusCode; |
||
14 | |||
15 | /** |
||
16 | * RestSystemException constructor. |
||
17 | * @param string $message the error message |
||
18 | * @param int $errorCode the error code of the api |
||
19 | * @param int $httpStatusCode the http status code in the response; Default=500 |
||
20 | */ |
||
21 | public function __construct($message, $errorCode, $httpStatusCode = 500) { |
||
25 | |||
26 | |||
27 | /** |
||
28 | * @return int |
||
29 | */ |
||
30 | public function getHttpStatusCode() { |
||
33 | |||
34 | /** |
||
35 | * @param int $httpStatusCode |
||
36 | * @return $this |
||
37 | */ |
||
38 | public function setHttpStatusCode($httpStatusCode) { |
||
42 | |||
43 | } |
||
44 |
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.