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 |
||
14 | class TaskTypeService extends BaseService |
||
15 | { |
||
16 | 4 | public function __construct(\linkprofit\AmoCRM\RequestHandler $requestHandler) |
|
20 | |||
21 | /** |
||
22 | * @var TaskType[] |
||
23 | */ |
||
24 | protected $entities = []; |
||
25 | |||
26 | /** |
||
27 | * @param $array |
||
28 | * |
||
29 | * @return EntityInterface |
||
30 | */ |
||
31 | 3 | public function parseArrayToEntity($array) |
|
38 | |||
39 | /** |
||
40 | * @return string |
||
41 | */ |
||
42 | 3 | protected function getLink() |
|
46 | |||
47 | /** |
||
48 | * @param \linkprofit\AmoCRM\entities\EntityInterface $taskType |
||
49 | * |
||
50 | * @return mixed |
||
51 | */ |
||
52 | 3 | public function add(EntityInterface $taskType) |
|
58 | |||
59 | /** |
||
60 | * @return bool|mixed |
||
61 | */ |
||
62 | 3 | View Code Duplication | public function save() |
74 | |||
75 | /** |
||
76 | * Fill fields for save request |
||
77 | */ |
||
78 | 3 | View Code Duplication | protected function composeFields() |
100 | |||
101 | /** |
||
102 | * @return array|bool |
||
103 | */ |
||
104 | 3 | View Code Duplication | public function parseResponseToEntities() |
117 | |||
118 | /** |
||
119 | * @return bool |
||
120 | */ |
||
121 | 3 | protected function checkResponse() |
|
129 | } |
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.