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 namespace GameScan\WoW\Entity; |
||
7 | abstract class Base |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * @type WowApiRequest |
||
12 | */ |
||
13 | protected $apiRequest = null; |
||
14 | protected $entityInformation = null; |
||
15 | protected $parameters = null; |
||
16 | |||
17 | |||
18 | 2 | View Code Duplication | public function __construct(WowApiRequest $api, $locale = null) |
26 | |||
27 | public function setApiRequest(WowApiRequest $apiRequest) |
||
31 | |||
32 | abstract public function getRessource(); |
||
33 | |||
34 | 2 | public function getParametters() |
|
38 | |||
39 | 2 | public function loadInformation() |
|
43 | |||
44 | 2 | protected function getEntityInformations() |
|
55 | |||
56 | public function __toString() |
||
60 | |||
61 | public function retreiveField($fieldName) |
||
68 | |||
69 | protected function checkIfFieldExist($fieldName) |
||
79 | |||
80 | protected function addField($fieldName) |
||
90 | |||
91 | protected function getHost() |
||
95 | |||
96 | protected function getRegion() |
||
100 | |||
101 | protected function getApiRequest() |
||
105 | } |
||
106 |
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.