Complex classes like Connection 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 Connection, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class Connection extends ClientConnection |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @TODO DESCR |
||
|
|
|||
| 17 | */ |
||
| 18 | const STATE_PACKET = 1; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string Database name |
||
| 22 | */ |
||
| 23 | public $dbname; |
||
| 24 | /** |
||
| 25 | * @var array Active cursors |
||
| 26 | */ |
||
| 27 | public $cursors = []; |
||
| 28 | /** |
||
| 29 | * @var array Pending requests |
||
| 30 | */ |
||
| 31 | public $requests = []; |
||
| 32 | /** |
||
| 33 | * @var integer ID of the last request |
||
| 34 | */ |
||
| 35 | public $lastReqId = 0; |
||
| 36 | /** |
||
| 37 | * @var integer Initial value of the minimal amout of bytes in buffer |
||
| 38 | */ |
||
| 39 | protected $lowMark = 16; |
||
| 40 | /** |
||
| 41 | * @var integer Initial value of the maximum amout of bytes in buffer |
||
| 42 | */ |
||
| 43 | protected $highMark = 0xFFFFFF; |
||
| 44 | /** |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | protected $hdr; |
||
| 48 | protected $maxQueue = 10; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @TODO DESCR |
||
| 52 | * @return void |
||
| 53 | */ |
||
| 54 | public function onReady() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Called when new data received |
||
| 86 | * @return void |
||
| 87 | */ |
||
| 88 | public function onRead() |
||
| 184 | |||
| 185 | /** |
||
| 186 | * onFinish |
||
| 187 | * @return void |
||
| 188 | */ |
||
| 189 | public function onFinish() |
||
| 200 | } |
||
| 201 |
This check looks
TODOcomments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.