Complex classes like Parser 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 Parser, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class Parser extends ParserBase |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var integer Position of the cursor while parsing tables or adding tags |
||
| 16 | */ |
||
| 17 | protected $pos; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var array Current table being parsed |
||
| 21 | */ |
||
| 22 | protected $table; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var \s9e\TextFormatter\Configurator\Items\Tag |
||
| 26 | */ |
||
| 27 | protected $tableTag; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var array[] List of tables |
||
| 31 | */ |
||
| 32 | protected $tables; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string Text being parsed |
||
| 36 | */ |
||
| 37 | protected $text; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritdoc} |
||
| 41 | */ |
||
| 42 | 22 | public function parse($text, array $matches) |
|
| 60 | |||
| 61 | /** |
||
| 62 | * Add current line to a table |
||
| 63 | * |
||
| 64 | * @param string $line Line of text |
||
| 65 | * @return void |
||
| 66 | */ |
||
| 67 | 21 | protected function addLine($line) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Process current table's body |
||
| 90 | * |
||
| 91 | * @return void |
||
| 92 | */ |
||
| 93 | 19 | protected function addTableBody() |
|
| 104 | |||
| 105 | /** |
||
| 106 | * Add a cell's tags for current table at current position |
||
| 107 | * |
||
| 108 | * @param string $tagName Either TD or TH |
||
| 109 | * @param string $align Either "left", "center", "right" or "" |
||
| 110 | * @return void |
||
| 111 | */ |
||
| 112 | 19 | protected function addTableCell($tagName, $align, $text) |
|
| 134 | |||
| 135 | /** |
||
| 136 | * Process current table's head |
||
| 137 | * |
||
| 138 | * @return void |
||
| 139 | */ |
||
| 140 | 19 | protected function addTableHead() |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Process given table row |
||
| 148 | * |
||
| 149 | * @param string $tagName Either TD or TH |
||
| 150 | * @param array $row |
||
| 151 | * @return void |
||
| 152 | */ |
||
| 153 | 19 | protected function addTableRow($tagName, $row) |
|
| 170 | |||
| 171 | /** |
||
| 172 | * Capture all pipe tables in current text |
||
| 173 | * |
||
| 174 | * @return void |
||
| 175 | */ |
||
| 176 | 22 | protected function captureTables() |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Create a pair of TBODY tags for given text span |
||
| 199 | * |
||
| 200 | * @param integer $startPos |
||
| 201 | * @param integer $endPos |
||
| 202 | * @return void |
||
| 203 | */ |
||
| 204 | 19 | protected function createBodyTags($startPos, $endPos) |
|
| 208 | |||
| 209 | /** |
||
| 210 | * Create a pair of TD or TH tags for given text span |
||
| 211 | * |
||
| 212 | * @param string $tagName Either TD or TH |
||
| 213 | * @param integer $startPos |
||
| 214 | * @param integer $endPos |
||
| 215 | * @param string $align Either "left", "center", "right" or "" |
||
| 216 | * @return void |
||
| 217 | */ |
||
| 218 | 19 | protected function createCellTags($tagName, $startPos, $endPos, $align) |
|
| 226 | |||
| 227 | /** |
||
| 228 | * Create a pair of THEAD tags for given text span |
||
| 229 | * |
||
| 230 | * @param integer $startPos |
||
| 231 | * @param integer $endPos |
||
| 232 | * @return void |
||
| 233 | */ |
||
| 234 | 19 | protected function createHeadTags($startPos, $endPos) |
|
| 238 | |||
| 239 | /** |
||
| 240 | * Create an ignore tag for given text span |
||
| 241 | * |
||
| 242 | * @param integer $pos |
||
| 243 | * @param integer $len |
||
| 244 | * @return void |
||
| 245 | */ |
||
| 246 | 19 | protected function createIgnoreTag($pos, $len) |
|
| 250 | |||
| 251 | /** |
||
| 252 | * Create a pair of TR tags for given text span |
||
| 253 | * |
||
| 254 | * @param integer $startPos |
||
| 255 | * @param integer $endPos |
||
| 256 | * @return void |
||
| 257 | */ |
||
| 258 | 19 | protected function createRowTags($startPos, $endPos) |
|
| 262 | |||
| 263 | /** |
||
| 264 | * Create an ignore tag for given separator row |
||
| 265 | * |
||
| 266 | * @param array $row |
||
| 267 | * @return void |
||
| 268 | */ |
||
| 269 | 19 | protected function createSeparatorTag(array $row) |
|
| 273 | |||
| 274 | /** |
||
| 275 | * Create a pair of TABLE tags for given text span |
||
| 276 | * |
||
| 277 | * @param integer $startPos |
||
| 278 | * @param integer $endPos |
||
| 279 | * @return void |
||
| 280 | */ |
||
| 281 | 19 | protected function createTableTags($startPos, $endPos) |
|
| 285 | |||
| 286 | /** |
||
| 287 | * End current buffered table |
||
| 288 | * |
||
| 289 | * @return void |
||
| 290 | */ |
||
| 291 | 22 | protected function endTable() |
|
| 300 | |||
| 301 | /** |
||
| 302 | * Test whether a valid table is currently buffered |
||
| 303 | * |
||
| 304 | * @return bool |
||
| 305 | */ |
||
| 306 | 22 | protected function hasValidTable() |
|
| 310 | |||
| 311 | /** |
||
| 312 | * Test whether given line is a valid separator |
||
| 313 | * |
||
| 314 | * @param string $line |
||
| 315 | * @return bool |
||
| 316 | */ |
||
| 317 | 20 | protected function isValidSeparator($line) |
|
| 321 | |||
| 322 | /** |
||
| 323 | * Overwrite right angle brackets in given match |
||
| 324 | * |
||
| 325 | * @param string[] $m |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | 4 | protected function overwriteBlockquoteCallback(array $m) |
|
| 332 | |||
| 333 | /** |
||
| 334 | * Overwrite escape sequences in current text |
||
| 335 | * |
||
| 336 | * @return void |
||
| 337 | */ |
||
| 338 | 1 | protected function overwriteEscapes() |
|
| 345 | |||
| 346 | /** |
||
| 347 | * Overwrite backticks in given match |
||
| 348 | * |
||
| 349 | * @param string[] $m |
||
| 350 | * @return string |
||
| 351 | */ |
||
| 352 | 2 | protected function overwriteInlineCodeCallback(array $m) |
|
| 356 | |||
| 357 | /** |
||
| 358 | * Overwrite Markdown-style markup in current text |
||
| 359 | * |
||
| 360 | * @return void |
||
| 361 | */ |
||
| 362 | 7 | protected function overwriteMarkdown() |
|
| 376 | |||
| 377 | /** |
||
| 378 | * Parse and return column alignments in given separator line |
||
| 379 | * |
||
| 380 | * @param string $line |
||
| 381 | * @return string[] |
||
| 382 | */ |
||
| 383 | 19 | protected function parseColumnAlignments($line) |
|
| 403 | |||
| 404 | /** |
||
| 405 | * Process current table declaration |
||
| 406 | * |
||
| 407 | * @return void |
||
| 408 | */ |
||
| 409 | 19 | protected function processCurrentTable() |
|
| 419 | |||
| 420 | /** |
||
| 421 | * Process all the captured tables |
||
| 422 | * |
||
| 423 | * @return void |
||
| 424 | */ |
||
| 425 | 22 | protected function processTables() |
|
| 433 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.