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 |
||
| 15 | class Import extends AbstractEntity |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var \HDNET\Importr\Domain\Model\Strategy |
||
| 20 | */ |
||
| 21 | protected $strategy; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $filepath; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var \DateTime |
||
| 30 | */ |
||
| 31 | protected $starttime; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var \DateTime |
||
| 35 | */ |
||
| 36 | protected $endtime; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var int |
||
| 40 | */ |
||
| 41 | protected $pointer; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var int |
||
| 45 | */ |
||
| 46 | protected $amount; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var int |
||
| 50 | */ |
||
| 51 | protected $inserted; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var int |
||
| 55 | */ |
||
| 56 | protected $updated; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var int |
||
| 60 | */ |
||
| 61 | protected $ignored; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var int |
||
| 65 | */ |
||
| 66 | protected $unknowns; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var int |
||
| 70 | */ |
||
| 71 | protected $errors; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return \HDNET\Importr\Domain\Model\Strategy |
||
| 75 | */ |
||
| 76 | public function getStrategy() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function getFilepath() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return \DateTime |
||
| 91 | */ |
||
| 92 | public function getStarttime() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @return \DateTime |
||
| 99 | */ |
||
| 100 | public function getEndtime() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return int |
||
| 107 | */ |
||
| 108 | public function getPointer() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return int |
||
| 115 | */ |
||
| 116 | public function getAmount() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param \HDNET\Importr\Domain\Model\Strategy $strategy |
||
| 123 | */ |
||
| 124 | public function setStrategy(Strategy $strategy) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param string $filepath |
||
| 131 | */ |
||
| 132 | public function setFilepath($filepath) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @param \DateTime $starttime |
||
| 139 | */ |
||
| 140 | public function setStarttime($starttime) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param \DateTime $endtime |
||
| 147 | */ |
||
| 148 | public function setEndtime($endtime) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @param int $pointer |
||
| 155 | */ |
||
| 156 | public function setPointer($pointer) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @param int $amount |
||
| 163 | */ |
||
| 164 | public function setAmount($amount) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @return float|int |
||
| 171 | */ |
||
| 172 | public function getPercentage() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param int $errors |
||
| 182 | */ |
||
| 183 | 1 | public function setErrors($errors) |
|
| 187 | |||
| 188 | /** |
||
| 189 | * @return int |
||
| 190 | */ |
||
| 191 | 1 | public function getErrors() |
|
| 195 | |||
| 196 | /** |
||
| 197 | * @return float|int |
||
| 198 | */ |
||
| 199 | public function getErrorsPercentage() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param int $ignored |
||
| 209 | */ |
||
| 210 | 1 | public function setIgnored($ignored) |
|
| 214 | |||
| 215 | /** |
||
| 216 | * @return int |
||
| 217 | */ |
||
| 218 | 1 | public function getIgnored() |
|
| 222 | |||
| 223 | /** |
||
| 224 | * @return float|int |
||
| 225 | */ |
||
| 226 | public function getIgnoredPercentage() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param int $inserted |
||
| 236 | */ |
||
| 237 | 1 | public function setInserted($inserted) |
|
| 241 | |||
| 242 | /** |
||
| 243 | * @return int |
||
| 244 | */ |
||
| 245 | 1 | public function getInserted() |
|
| 249 | |||
| 250 | /** |
||
| 251 | * @param int $unknowns |
||
| 252 | */ |
||
| 253 | 1 | public function setUnknowns($unknowns) |
|
| 257 | |||
| 258 | /** |
||
| 259 | * @return int |
||
| 260 | */ |
||
| 261 | 1 | public function getUnknowns() |
|
| 265 | |||
| 266 | /** |
||
| 267 | * @return float|int |
||
| 268 | */ |
||
| 269 | public function getUnknownsPercentage() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @return float|int |
||
| 279 | */ |
||
| 280 | public function getInsertedPercentage() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param int $updated |
||
| 290 | */ |
||
| 291 | 1 | public function setUpdated($updated) |
|
| 295 | |||
| 296 | /** |
||
| 297 | * @return int |
||
| 298 | */ |
||
| 299 | 1 | public function getUpdated() |
|
| 303 | |||
| 304 | /** |
||
| 305 | * @return float|int |
||
| 306 | */ |
||
| 307 | public function getUpdatedPercentage() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @param int $type |
||
| 317 | */ |
||
| 318 | 1 | public function increaseCount($type) |
|
| 338 | |||
| 339 | public function reset() |
||
| 350 | } |
||
| 351 |
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..