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 |
||
11 | View Code Duplication | class FetchPlan extends AbstractFetchPlan |
|
|
|||
12 | { |
||
13 | |||
14 | use VerifyHttpStatusResponseCode; |
||
15 | |||
16 | /** |
||
17 | * @var string The relative link for fetching a certain plan |
||
18 | */ |
||
19 | const FETCH_PLAN_LINK = '/plan/:identifier'; |
||
20 | |||
21 | protected $baseUrl; |
||
22 | |||
23 | 2 | public function __construct(string $baseUrl) |
|
27 | |||
28 | /** |
||
29 | * @param string|int $identifier |
||
30 | * @return mixed |
||
31 | * @throws \Gbowo\Exception\InvalidHttpResponseException if ann http response of 200 isn't returned |
||
32 | */ |
||
33 | 2 | public function handle($identifier) |
|
47 | } |
||
48 |
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.