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 |
||
4 | View Code Duplication | class FolderSharingInfo extends BaseModel |
|
|
|||
5 | { |
||
6 | |||
7 | /** |
||
8 | * True if the file or folder is inside a read-only shared folder. |
||
9 | * |
||
10 | * @var bool |
||
11 | */ |
||
12 | protected $read_only; |
||
13 | |||
14 | /** |
||
15 | * ID of shared folder that holds this folder. |
||
16 | * Set if the folder is contained by a shared folder. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $parent_shared_folder_id; |
||
21 | |||
22 | /** |
||
23 | * If this folder is a shared folder mount point, |
||
24 | * the ID of the shared folder mounted at this location. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $shared_folder_id; |
||
29 | |||
30 | |||
31 | /** |
||
32 | * Create a new Folder Sharing Info instance |
||
33 | * |
||
34 | * @param array $data |
||
35 | */ |
||
36 | 1 | public function __construct(array $data) |
|
43 | |||
44 | /** |
||
45 | * True if the folder or folder is inside a read-only shared folder. |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function isReadOnly() |
||
53 | |||
54 | /** |
||
55 | * ID of shared folder that holds this folder. |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getParentSharedFolderId() |
||
63 | |||
64 | /** |
||
65 | * ID of shared folder. |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | public function getSharedFolderId() |
||
73 | } |
||
74 |
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.