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 |
||
| 24 | class driverStatistic implements ArrayAccess |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $info = ''; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $size = ''; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $data = ''; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var mixed |
||
| 43 | */ |
||
| 44 | protected $rawData; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return string|bool Return infos or false if no information available |
||
| 48 | */ |
||
| 49 | public function getInfo() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return int|bool Return size in octet or false if no information available |
||
| 56 | */ |
||
| 57 | public function getSize() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return mixed |
||
| 64 | */ |
||
| 65 | public function getData() |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @param $info |
||
| 72 | * @return $this |
||
| 73 | */ |
||
| 74 | public function setInfo($info) |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * @param int $size |
||
| 84 | * @return $this |
||
| 85 | */ |
||
| 86 | public function setSize($size) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param mixed $data |
||
| 95 | * @return $this |
||
| 96 | */ |
||
| 97 | public function setData($data) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @return mixed |
||
| 106 | */ |
||
| 107 | public function getRawData() |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @param mixed $raw |
||
| 114 | * @return $this |
||
| 115 | */ |
||
| 116 | public function setRawData($raw) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @return array |
||
| 125 | */ |
||
| 126 | public function getPublicDesc() |
||
| 135 | |||
| 136 | /***************** |
||
| 137 | * ArrayAccess |
||
| 138 | *****************/ |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @param string $offset |
||
| 142 | * @param string $value |
||
| 143 | * @throws InvalidArgumentException |
||
| 144 | * @throws LogicException |
||
| 145 | */ |
||
| 146 | View Code Duplication | public function offsetSet($offset, $value) |
|
| 159 | |||
| 160 | /** |
||
| 161 | * @param string $offset |
||
| 162 | * @return bool |
||
| 163 | * @throws InvalidArgumentException |
||
| 164 | * @throws LogicException |
||
| 165 | */ |
||
| 166 | View Code Duplication | public function offsetExists($offset) |
|
| 179 | |||
| 180 | /** |
||
| 181 | * @param string $offset |
||
| 182 | * @throws InvalidArgumentException |
||
| 183 | * @throws LogicException |
||
| 184 | */ |
||
| 185 | View Code Duplication | public function offsetUnset($offset) |
|
| 198 | |||
| 199 | /** |
||
| 200 | * @param string $offset |
||
| 201 | * @return string |
||
| 202 | * @throws InvalidArgumentException |
||
| 203 | * @throws LogicException |
||
| 204 | */ |
||
| 205 | View Code Duplication | public function offsetGet($offset) |
|
| 218 | |||
| 219 | /** |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | private function getDeprecatedMsg() |
||
| 227 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..