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 |
||
18 | View Code Duplication | class Context implements ContextInterface |
|
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var string $slug |
||
23 | */ |
||
24 | private $slug; |
||
25 | |||
26 | /** |
||
27 | * @var string $description |
||
28 | */ |
||
29 | private $description; |
||
30 | |||
31 | |||
32 | /** |
||
33 | * Context constructor. |
||
34 | * |
||
35 | * @param string $slug |
||
36 | * @param string $description |
||
37 | */ |
||
38 | public function __construct($slug, $description) |
||
43 | |||
44 | |||
45 | /** |
||
46 | * @return string |
||
47 | */ |
||
48 | public function slug() |
||
52 | |||
53 | |||
54 | /** |
||
55 | * @param string $slug |
||
56 | */ |
||
57 | private function setSlug($slug) |
||
61 | |||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | public function description() |
||
70 | |||
71 | |||
72 | /** |
||
73 | * @param string $description |
||
74 | */ |
||
75 | private function setDescription($description) |
||
79 | |||
80 | } |
||
81 | // Location: Context.php |
||
82 |