Complex classes like HighchartsSeries 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 HighchartsSeries, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | final class HighchartsSeries implements JsonSerializable { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Data. |
||
| 29 | * |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | private $data; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Data parser. |
||
| 36 | * |
||
| 37 | * @var string |
||
| 38 | * @deprecated |
||
| 39 | */ |
||
| 40 | private $dataParser; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Data URL. |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | * @deprecated |
||
| 47 | */ |
||
| 48 | private $dataURL; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Id. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | * @since 1.2.0 |
||
| 55 | */ |
||
| 56 | private $id; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Index. |
||
| 60 | * |
||
| 61 | * @var integer |
||
| 62 | * @since 2.3.0 |
||
| 63 | */ |
||
| 64 | private $index; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Legend index. |
||
| 68 | * |
||
| 69 | * @var integer |
||
| 70 | */ |
||
| 71 | private $legendIndex; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Name. |
||
| 75 | * |
||
| 76 | * @var string |
||
| 77 | */ |
||
| 78 | private $name; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Stack. |
||
| 82 | * |
||
| 83 | * @var string |
||
| 84 | * @since 2.1 |
||
| 85 | */ |
||
| 86 | private $stack; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Type. |
||
| 90 | * |
||
| 91 | * @var string |
||
| 92 | */ |
||
| 93 | private $type; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * X axis. |
||
| 97 | * |
||
| 98 | * @var integer|string |
||
| 99 | */ |
||
| 100 | private $xAxis = "0"; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Y axis. |
||
| 104 | * |
||
| 105 | * @var integer|string |
||
| 106 | */ |
||
| 107 | private $yAxis = "0"; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Z index. |
||
| 111 | * |
||
| 112 | * @var integer |
||
| 113 | */ |
||
| 114 | private $zIndex; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Constructor. |
||
| 118 | * |
||
| 119 | * @param boolean $ignoreDefaultValues Ignore the default values. |
||
| 120 | */ |
||
| 121 | public function __construct($ignoreDefaultValues = true) { |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Clear. |
||
| 129 | * |
||
| 130 | * @return void |
||
| 131 | */ |
||
| 132 | public function clear() { |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Get the data. |
||
| 173 | * |
||
| 174 | * @return array Returns the data. |
||
| 175 | */ |
||
| 176 | public function getData() { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Get the data parser. |
||
| 182 | * |
||
| 183 | * @return string Returns the data parser. |
||
| 184 | * @deprecated |
||
| 185 | */ |
||
| 186 | public function getDataParser() { |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Get the data URL. |
||
| 192 | * |
||
| 193 | * @return string Returns the data URL. |
||
| 194 | * @deprecated |
||
| 195 | */ |
||
| 196 | public function getDataURL() { |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Get the id. |
||
| 202 | * |
||
| 203 | * @return string Returns the id. |
||
| 204 | */ |
||
| 205 | public function getId() { |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Get the index. |
||
| 211 | * |
||
| 212 | * @return integer Returns the index. |
||
| 213 | */ |
||
| 214 | public function getIndex() { |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Get the legend index. |
||
| 220 | * |
||
| 221 | * @return integer Returns the legend index. |
||
| 222 | */ |
||
| 223 | public function getLegendIndex() { |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Get the name. |
||
| 229 | * |
||
| 230 | * @return string Returns the name. |
||
| 231 | */ |
||
| 232 | public function getName() { |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Get the stack. |
||
| 238 | * |
||
| 239 | * @return string Returns the stack. |
||
| 240 | */ |
||
| 241 | public function getStack() { |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Get the type. |
||
| 247 | * |
||
| 248 | * @return string Returns the type. |
||
| 249 | */ |
||
| 250 | public function getType() { |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Get the x axis. |
||
| 256 | * |
||
| 257 | * @return integer|string Returns the x axis. |
||
| 258 | */ |
||
| 259 | public function getXAxis() { |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Get the y axis. |
||
| 265 | * |
||
| 266 | * @return integer|string Returns the y axis. |
||
| 267 | */ |
||
| 268 | public function getYAxis() { |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Get the z index. |
||
| 274 | * |
||
| 275 | * @return integer Returns the z index. |
||
| 276 | */ |
||
| 277 | public function getZIndex() { |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Serialize this instance. |
||
| 283 | * |
||
| 284 | * @return array Returns an array representing this instance. |
||
| 285 | */ |
||
| 286 | public function jsonSerialize() { |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Set the data. |
||
| 292 | * |
||
| 293 | * @param array $data The data. |
||
| 294 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 295 | */ |
||
| 296 | public function setData(array $data = null) { |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Set the data parser. |
||
| 303 | * |
||
| 304 | * @param string $dataParser The data parser. |
||
| 305 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 306 | * @deprecated |
||
| 307 | */ |
||
| 308 | public function setDataParser($dataParser) { |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Set the data URL. |
||
| 315 | * |
||
| 316 | * @param string $dataURL The data URL. |
||
| 317 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 318 | * @deprecated |
||
| 319 | */ |
||
| 320 | public function setDataURL($dataURL) { |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Set the id. |
||
| 327 | * |
||
| 328 | * @param string $id The id. |
||
| 329 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 330 | */ |
||
| 331 | public function setId($id) { |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Set the index. |
||
| 338 | * |
||
| 339 | * @param integer $index The index. |
||
| 340 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 341 | */ |
||
| 342 | public function setIndex($index) { |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Set the legend index. |
||
| 349 | * |
||
| 350 | * @param integer $legendIndex The legend index. |
||
| 351 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 352 | */ |
||
| 353 | public function setLegendIndex($legendIndex) { |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Set the name. |
||
| 360 | * |
||
| 361 | * @param string $name The name. |
||
| 362 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 363 | */ |
||
| 364 | public function setName($name) { |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Set the stack. |
||
| 371 | * |
||
| 372 | * @param string $stack The stack. |
||
| 373 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 374 | */ |
||
| 375 | public function setStack($stack) { |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Set the type. |
||
| 382 | * |
||
| 383 | * @param string $type The type. |
||
| 384 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 385 | */ |
||
| 386 | public function setType($type) { |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Set the x axis. |
||
| 413 | * |
||
| 414 | * @param integer|string $xAxis The x axis. |
||
| 415 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 416 | */ |
||
| 417 | public function setXAxis($xAxis) { |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Set the y axis. |
||
| 424 | * |
||
| 425 | * @param integer|string $yAxis The y axis. |
||
| 426 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 427 | */ |
||
| 428 | public function setYAxis($yAxis) { |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Set the z index. |
||
| 435 | * |
||
| 436 | * @param integer $zIndex The z index. |
||
| 437 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSeries Returns the highcharts series. |
||
| 438 | */ |
||
| 439 | public function setZIndex($zIndex) { |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Convert into an array representing this instance. |
||
| 446 | * |
||
| 447 | * @return array Returns an array representing this instance. |
||
| 448 | */ |
||
| 449 | public function toArray() { |
||
| 493 | |||
| 494 | } |
||
| 495 |
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..