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 |
||
12 | View Code Duplication | class CompanyService extends BaseService |
|
13 | { |
||
14 | /** |
||
15 | * @var Company[] |
||
16 | */ |
||
17 | protected $entities = []; |
||
18 | |||
19 | /** |
||
20 | * @param Company $company |
||
21 | */ |
||
22 | 4 | public function add(EntityInterface $company) |
|
23 | { |
||
24 | 4 | if ($company instanceof Company) { |
|
25 | 4 | $this->entities[] = $company; |
|
26 | 4 | } |
|
27 | 4 | } |
|
28 | |||
29 | /** |
||
30 | * @param $array |
||
31 | * @return Company |
||
32 | */ |
||
33 | 4 | public function parseArrayToEntity($array) |
|
40 | |||
41 | /** |
||
42 | * @return string |
||
43 | */ |
||
44 | 4 | protected function getLink() |
|
48 | } |