Complex classes like Import often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Import, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class Import extends AbstractEntity |
||
| 14 | { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var \HDNET\Importr\Domain\Model\Strategy |
||
| 18 | */ |
||
| 19 | protected $strategy; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $filepath; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var \DateTime |
||
| 28 | */ |
||
| 29 | protected $starttime; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var \DateTime |
||
| 33 | */ |
||
| 34 | protected $endtime; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var integer |
||
| 38 | */ |
||
| 39 | protected $pointer; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var integer |
||
| 43 | */ |
||
| 44 | protected $amount; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var integer |
||
| 48 | */ |
||
| 49 | protected $inserted; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var integer |
||
| 53 | */ |
||
| 54 | protected $updated; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var integer |
||
| 58 | */ |
||
| 59 | protected $ignored; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var integer |
||
| 63 | */ |
||
| 64 | protected $unknowns; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var integer |
||
| 68 | */ |
||
| 69 | protected $errors; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return \HDNET\Importr\Domain\Model\Strategy |
||
| 73 | */ |
||
| 74 | public function getStrategy() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | public function getFilepath() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @return \DateTime |
||
| 89 | */ |
||
| 90 | public function getStarttime() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @return \DateTime |
||
| 97 | */ |
||
| 98 | public function getEndtime() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @return integer |
||
| 105 | */ |
||
| 106 | public function getPointer() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @return integer |
||
| 113 | */ |
||
| 114 | public function getAmount() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @param \HDNET\Importr\Domain\Model\Strategy $strategy |
||
| 121 | */ |
||
| 122 | public function setStrategy(Strategy $strategy) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param string $filepath |
||
| 129 | */ |
||
| 130 | public function setFilepath($filepath) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param \DateTime $starttime |
||
| 137 | */ |
||
| 138 | public function setStarttime($starttime) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @param \DateTime $endtime |
||
| 145 | */ |
||
| 146 | public function setEndtime($endtime) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @param integer $pointer |
||
| 153 | */ |
||
| 154 | public function setPointer($pointer) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @param integer $amount |
||
| 161 | */ |
||
| 162 | public function setAmount($amount) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @return float|int |
||
| 169 | */ |
||
| 170 | public function getPercentage() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @param int $errors |
||
| 180 | */ |
||
| 181 | 1 | public function setErrors($errors) |
|
| 185 | |||
| 186 | /** |
||
| 187 | * @return int |
||
| 188 | */ |
||
| 189 | 1 | public function getErrors() |
|
| 193 | |||
| 194 | /** |
||
| 195 | * @return float|int |
||
| 196 | */ |
||
| 197 | public function getErrorsPercentage() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param int $ignored |
||
| 207 | */ |
||
| 208 | 1 | public function setIgnored($ignored) |
|
| 212 | |||
| 213 | /** |
||
| 214 | * @return int |
||
| 215 | */ |
||
| 216 | 1 | public function getIgnored() |
|
| 220 | |||
| 221 | /** |
||
| 222 | * @return float|int |
||
| 223 | */ |
||
| 224 | public function getIgnoredPercentage() |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @param int $inserted |
||
| 234 | */ |
||
| 235 | 1 | public function setInserted($inserted) |
|
| 239 | |||
| 240 | /** |
||
| 241 | * @return int |
||
| 242 | */ |
||
| 243 | 1 | public function getInserted() |
|
| 247 | |||
| 248 | /** |
||
| 249 | * @param int $unknowns |
||
| 250 | */ |
||
| 251 | 1 | public function setUnknowns($unknowns) |
|
| 255 | |||
| 256 | /** |
||
| 257 | * @return int |
||
| 258 | */ |
||
| 259 | 1 | public function getUnknowns() |
|
| 263 | |||
| 264 | /** |
||
| 265 | * @return float|int |
||
| 266 | */ |
||
| 267 | public function getUnknownsPercentage() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @return float|int |
||
| 277 | */ |
||
| 278 | public function getInsertedPercentage() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param int $updated |
||
| 288 | */ |
||
| 289 | 1 | public function setUpdated($updated) |
|
| 293 | |||
| 294 | /** |
||
| 295 | * @return int |
||
| 296 | */ |
||
| 297 | 1 | public function getUpdated() |
|
| 301 | |||
| 302 | /** |
||
| 303 | * @return float|int |
||
| 304 | */ |
||
| 305 | public function getUpdatedPercentage() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @param int $type |
||
| 315 | */ |
||
| 316 | 1 | public function increaseCount($type) |
|
| 336 | |||
| 337 | public function reset() |
||
| 348 | } |
||
| 349 |
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..