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 |
||
| 29 | View Code Duplication | class MountPoint implements \JsonSerializable { |
|
|
|
|||
| 30 | |||
| 31 | |||
| 32 | /** @var int */ |
||
| 33 | private $id; |
||
| 34 | |||
| 35 | /** @var string */ |
||
| 36 | private $path; |
||
| 37 | |||
| 38 | /** @var bool */ |
||
| 39 | private $global; |
||
| 40 | |||
| 41 | /** @var array */ |
||
| 42 | private $groups; |
||
| 43 | |||
| 44 | /** @var array */ |
||
| 45 | private $users; |
||
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * @return int |
||
| 50 | */ |
||
| 51 | public function getId() { |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param int $id |
||
| 57 | * |
||
| 58 | * @return $this |
||
| 59 | */ |
||
| 60 | public function setId($id) { |
||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public function getPath() { |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param string $path |
||
| 76 | * |
||
| 77 | * @return $this |
||
| 78 | */ |
||
| 79 | public function setPath($path) { |
||
| 84 | |||
| 85 | |||
| 86 | /** |
||
| 87 | * @return bool |
||
| 88 | */ |
||
| 89 | public function isGlobal() { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param bool $global |
||
| 95 | * |
||
| 96 | * @return $this |
||
| 97 | */ |
||
| 98 | public function setGlobal($global) { |
||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * @return array |
||
| 107 | */ |
||
| 108 | public function getGroups() { |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @param array $groups |
||
| 114 | * |
||
| 115 | * @return $this |
||
| 116 | */ |
||
| 117 | public function setGroups($groups) { |
||
| 122 | |||
| 123 | |||
| 124 | /** |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | public function getUsers() { |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param array $users |
||
| 133 | * |
||
| 134 | * @return $this |
||
| 135 | */ |
||
| 136 | public function setUsers($users) { |
||
| 141 | |||
| 142 | |||
| 143 | public function __destruct() { |
||
| 150 | |||
| 151 | public function jsonSerialize() { |
||
| 160 | |||
| 161 | } |
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.