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 |
||
| 16 | class Credential extends DataObject |
||
| 17 | { |
||
| 18 | /** @var int */ |
||
| 19 | private $user; |
||
| 20 | /** @var int */ |
||
| 21 | private $factor; |
||
| 22 | /** @var string */ |
||
| 23 | private $type; |
||
| 24 | /** @var string */ |
||
| 25 | private $data; |
||
| 26 | /** @var int */ |
||
| 27 | private $version; |
||
| 28 | private $timeout; |
||
| 29 | /** @var int */ |
||
| 30 | private $disabled = 0; |
||
| 31 | /** @var int */ |
||
| 32 | private $priority; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return int |
||
| 36 | */ |
||
| 37 | public function getUserId() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param int $user |
||
| 44 | */ |
||
| 45 | public function setUserId($user) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return int |
||
| 52 | */ |
||
| 53 | public function getFactor() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param int $factor |
||
| 60 | */ |
||
| 61 | public function setFactor($factor) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | public function getType() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param string $type |
||
| 76 | */ |
||
| 77 | public function setType($type) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | public function getData() |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param string $data |
||
| 92 | */ |
||
| 93 | public function setData($data) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return int |
||
| 100 | */ |
||
| 101 | public function getVersion() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @param int $version |
||
| 108 | */ |
||
| 109 | public function setVersion($version) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @return mixed |
||
|
|
|||
| 116 | */ |
||
| 117 | public function getTimeout() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param mixed $timeout |
||
| 128 | */ |
||
| 129 | public function setTimeout(DateTimeImmutable $timeout = null) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return int |
||
| 141 | */ |
||
| 142 | public function getDisabled() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param int $disabled |
||
| 149 | */ |
||
| 150 | public function setDisabled($disabled) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @return int |
||
| 157 | */ |
||
| 158 | public function getPriority() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @param int $priority |
||
| 165 | */ |
||
| 166 | public function setPriority($priority) |
||
| 170 | |||
| 171 | View Code Duplication | public function save() |
|
| 232 | } |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.