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 |
||
22 | class ContentCategory extends ActiveModel |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * Get all table rows as object |
||
27 | * @param array $columns |
||
28 | * @return \Illuminate\Database\Eloquent\Collection|mixed|static[] |
||
29 | */ |
||
30 | View Code Duplication | public static function all($columns = ['*']) |
|
41 | /** |
||
42 | * Get record via category path address |
||
43 | * @param string $path |
||
44 | * @return self|object|null |
||
45 | */ |
||
46 | public static function getByPath($path = '') |
||
56 | |||
57 | /** |
||
58 | * Find category by id |
||
59 | * @param int $id |
||
60 | * @return self|object|null |
||
61 | */ |
||
62 | public static function getById($id) |
||
72 | |||
73 | /** |
||
74 | * @deprecated |
||
75 | * @return \Illuminate\Database\Eloquent\Collection|mixed|static[] |
||
76 | */ |
||
77 | public static function getAll() |
||
81 | |||
82 | /** |
||
83 | * Build id-title array of sorted by nesting level categories |
||
84 | * @return array |
||
85 | */ |
||
86 | public static function getSortedCategories() |
||
109 | |||
110 | /** |
||
111 | * Get all categories sorted by pathway |
||
112 | * @return array |
||
113 | */ |
||
114 | public static function getSortedAll() |
||
124 | |||
125 | /** |
||
126 | * Get property by key of current category |
||
127 | * @param string $key |
||
128 | * @return bool|string|null |
||
129 | */ |
||
130 | public function getProperty($key) |
||
141 | |||
142 | } |
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.