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 | class Organisations extends StarCitizenAbstract |
||
13 | { |
||
14 | |||
15 | const ORG = 'single_organization'; |
||
16 | const MEMBERS = 'members'; |
||
17 | |||
18 | /** |
||
19 | * Model map |
||
20 | */ |
||
21 | const MODELS = [ |
||
22 | Organisations::ORG => '\Organisation', |
||
23 | Organisations::MEMBERS => '\Members' |
||
24 | ]; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected static $system = "organizations"; |
||
30 | |||
31 | /** |
||
32 | * @param $id |
||
33 | * @param string $action |
||
34 | * @param bool $cache |
||
35 | * @param bool $raw |
||
36 | * |
||
37 | * @return bool|mixed |
||
38 | */ |
||
39 | protected static function find($id, $action = Organisations::ORG, $cache = false, $raw = false) |
||
61 | |||
62 | /** |
||
63 | * @param $id |
||
64 | * @param bool $cache |
||
65 | * @param bool $raw |
||
66 | * |
||
67 | * @return bool|Organisation |
||
68 | */ |
||
69 | protected static function findOrg($id, $cache = false, $raw = false) |
||
73 | } |
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.