Complex classes like OciPdoStubStatement 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 OciPdoStubStatement, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 29 | class OciPdoStubStatement extends \PDOStatement |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * @var PDO |
||
| 33 | */ |
||
| 34 | private $_pdooci = null; |
||
| 35 | /** |
||
| 36 | * @var resource |
||
| 37 | */ |
||
| 38 | private $_con = null; |
||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | private $_statement = null; |
||
| 43 | /** |
||
| 44 | * @var resource |
||
| 45 | */ |
||
| 46 | private $_stmt = null; |
||
| 47 | /** |
||
| 48 | * @var int |
||
| 49 | */ |
||
| 50 | private $_fetch_sty = null; |
||
| 51 | /** |
||
| 52 | * @var mixed |
||
| 53 | */ |
||
| 54 | private $_current = null; |
||
| 55 | /** |
||
| 56 | * @var int |
||
| 57 | */ |
||
| 58 | private $_pos = 0; |
||
| 59 | /** |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | private $_binds = []; |
||
| 63 | /** |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | protected $_queryString = ''; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Constructor |
||
| 70 | * |
||
| 71 | * @param OciStubPdo $pdooci PDOOCI connection |
||
| 72 | * @param string $statement sql statement |
||
| 73 | * |
||
| 74 | * @throws \PDOException |
||
| 75 | */ |
||
| 76 | public function __construct(OciStubPdo $pdooci, $statement) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Binds a value |
||
| 93 | * |
||
| 94 | * @param mixed $param param (column) |
||
| 95 | * @param mixed $value value for param |
||
| 96 | * @param mixed $type optional data type |
||
| 97 | * |
||
| 98 | * @return bool bound |
||
| 99 | * @throws \PDOException |
||
| 100 | */ |
||
| 101 | public function bindValue($param, $value, $type = null) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Binds a param |
||
| 115 | * |
||
| 116 | * @param mixed $paramno |
||
| 117 | * @param mixed $param |
||
| 118 | * @param null $type |
||
| 119 | * @param null $maxlen |
||
| 120 | * @param null $driverdata |
||
| 121 | * |
||
| 122 | * @return bool |
||
| 123 | */ |
||
| 124 | public function bindParam($paramno, &$param, $type = null, $maxlen = null, $driverdata = null) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Get the variable name for binding |
||
| 138 | * |
||
| 139 | * @param mixed $val variable value |
||
| 140 | * |
||
| 141 | * @return string correct name for binding |
||
| 142 | */ |
||
| 143 | private function _getBindVar($val) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Execute statement |
||
| 159 | * |
||
| 160 | * @param mixed $values optional values |
||
| 161 | * |
||
| 162 | * @return boolean |
||
| 163 | * @throws \PDOException |
||
| 164 | */ |
||
| 165 | public function execute($values = null) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Get the number of affected rows |
||
| 200 | * |
||
| 201 | * @return int number of rows |
||
| 202 | * @throws \PDOException |
||
| 203 | */ |
||
| 204 | public function rowCount() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Close the current cursor |
||
| 219 | * |
||
| 220 | * @return null |
||
| 221 | * @throws \PDOException |
||
| 222 | */ |
||
| 223 | public function closeCursor() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Fetch a value |
||
| 237 | * |
||
| 238 | * @param null $how |
||
| 239 | * @param null $orientation |
||
| 240 | * @param null $offset |
||
| 241 | * |
||
| 242 | * @return array|mixed|null|object |
||
| 243 | */ |
||
| 244 | public function fetch($how = null, $orientation = null, $offset = null) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Fetch all |
||
| 278 | * |
||
| 279 | * @param null $how |
||
| 280 | * @param null $class_name |
||
| 281 | * @param null $ctor_args |
||
| 282 | * |
||
| 283 | * @return array|null |
||
| 284 | */ |
||
| 285 | public function fetchAll($how = null, $class_name = null, $ctor_args = null) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Fetch column |
||
| 354 | * |
||
| 355 | * @param int $colnum optional column number |
||
| 356 | * |
||
| 357 | * @return mixed column value |
||
| 358 | */ |
||
| 359 | public function fetchColumn($colnum = 0) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Fetch data and create an object |
||
| 367 | * |
||
| 368 | * @param string $class_name |
||
| 369 | * @param null $ctor_args |
||
| 370 | * |
||
| 371 | * @return \stdClass|null |
||
| 372 | */ |
||
| 373 | public function fetchObject($class_name = 'stdClass', $ctor_args = null) |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Create a new object from data |
||
| 385 | * |
||
| 386 | * @param string $name class name |
||
| 387 | * @param mixed $data data to use on class |
||
| 388 | * |
||
| 389 | * @return \stdClass |
||
| 390 | */ |
||
| 391 | private function _createObjectFromData($name, $data) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Convert a query to use bind marks |
||
| 410 | * |
||
| 411 | * @param string $query to insert bind marks |
||
| 412 | * |
||
| 413 | * @return string query with bind marks |
||
| 414 | */ |
||
| 415 | public static function insertMarks($query) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Return the current statement |
||
| 429 | * |
||
| 430 | * @return string statement |
||
| 431 | */ |
||
| 432 | public function getStatement() |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Return the current value |
||
| 439 | * |
||
| 440 | * @return null |
||
| 441 | */ |
||
| 442 | public function current() |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Return the current key/position |
||
| 456 | * |
||
| 457 | * @return integer |
||
| 458 | */ |
||
| 459 | public function key() |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Return the next value |
||
| 466 | * |
||
| 467 | * @return null |
||
| 468 | */ |
||
| 469 | public function next() |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Rewind |
||
| 480 | * |
||
| 481 | * @return null |
||
| 482 | */ |
||
| 483 | public function rewind() |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Check if the current value is valid |
||
| 490 | * |
||
| 491 | * @return boolean |
||
| 492 | */ |
||
| 493 | public function valid() |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Set the fetch mode |
||
| 501 | * |
||
| 502 | * @param int $mode fetch mode |
||
| 503 | * @param mixed $p1 first optional parameter |
||
| 504 | * @param mixed $p2 second optional parameter |
||
| 505 | * |
||
| 506 | * @return null |
||
| 507 | */ |
||
| 508 | public function setFetchMode($mode, $p1 = null, $p2 = null) |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Return the fetch mode |
||
| 516 | * |
||
| 517 | * @return int mode |
||
| 518 | */ |
||
| 519 | public function getFetchMode() |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Bind column |
||
| 526 | * |
||
| 527 | * @param mixed $column as index (1-based) or name |
||
| 528 | * @param mixed &$param variable |
||
| 529 | * @param int $type type |
||
| 530 | * @param int $maxlen max length |
||
| 531 | * @param mixed $driver data |
||
| 532 | * |
||
| 533 | * @return boolean|null if was bound |
||
| 534 | */ |
||
| 535 | public function bindColumn($column, &$param, $type = null, $maxlen = null, $driver = null) |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Check what binds are needed |
||
| 543 | * |
||
| 544 | * @return null |
||
| 545 | */ |
||
| 546 | private function _checkBinds() |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Column count |
||
| 566 | * |
||
| 567 | * @return int column count or zero if not executed |
||
| 568 | * @throws \PDOException |
||
| 569 | */ |
||
| 570 | public function columnCount() |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Debug dump params |
||
| 584 | * |
||
| 585 | * @return string params |
||
| 586 | */ |
||
| 587 | public function debugDumpParams() |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Return error code |
||
| 601 | * |
||
| 602 | * @return mixed error code |
||
| 603 | */ |
||
| 604 | public function errorCode() |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Return error info |
||
| 611 | * |
||
| 612 | * @return mixed error info |
||
| 613 | */ |
||
| 614 | public function errorInfo() |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Set an attribute |
||
| 621 | * |
||
| 622 | * @param int $attr attribute |
||
| 623 | * @param mixed $value value |
||
| 624 | * |
||
| 625 | * @return true if setted |
||
| 626 | */ |
||
| 627 | public function setAttribute($attr, $value) |
||
| 631 | |||
| 632 | /** |
||
| 633 | * Get an attribute |
||
| 634 | * |
||
| 635 | * @param int $attr attribute |
||
| 636 | * |
||
| 637 | * @return mixed value |
||
| 638 | */ |
||
| 639 | public function getAttribute($attr) |
||
| 643 | |||
| 644 | /** |
||
| 645 | * Get column meta data |
||
| 646 | * |
||
| 647 | * @param int $colnum column number |
||
| 648 | * |
||
| 649 | * @return mixed column meta data |
||
| 650 | */ |
||
| 651 | public function getColumnMeta($colnum = 0) |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Dummy method for nextRowSet |
||
| 665 | * |
||
| 666 | * @return boolean|null |
||
| 667 | */ |
||
| 668 | public function nextRowSet() |
||
| 672 | } |
||
| 673 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.