Complex classes like Kohana_Jam_Query_Builder_Select 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 Kohana_Jam_Query_Builder_Select, and based on these observations, apply Extract Interface, too.
| 1 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
| 12 | abstract class Kohana_Jam_Query_Builder_Select extends Database_Query_Builder_Select { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Create object of class Jam_Query_Builder_Select |
||
| 16 | * @param string $model |
||
| 17 | * @return Jam_Query_Builder_Select |
||
| 18 | */ |
||
| 19 | 1 | public static function factory($model) |
|
| 23 | |||
| 24 | /** |
||
| 25 | * @var Jam_Meta The meta object (if found) that is attached to this builder |
||
| 26 | */ |
||
| 27 | protected $_meta = NULL; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * A store for user defined values for the builder |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | protected $_params = array(); |
||
| 34 | |||
| 35 | protected static $_modifiable = array('select', 'from', 'join', 'where', 'group_by', 'having', 'order_by', 'union', 'distinct', 'limit', 'offset', 'parameters'); |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Constructs a new Jam_Builder instance. |
||
| 39 | * |
||
| 40 | * $model is not actually allowed to be NULL. It has |
||
| 41 | * a default because PHP throws strict errors otherwise. |
||
| 42 | * |
||
| 43 | * @throws Kohana_Exception |
||
| 44 | * @param string|null $model |
||
| 45 | * @param mixed|null $key |
||
|
|
|||
| 46 | */ |
||
| 47 | 140 | public function __construct($model) |
|
| 58 | |||
| 59 | 22 | public function where_key($unique_key) |
|
| 65 | |||
| 66 | 91 | public function compile($db = NULL) |
|
| 107 | |||
| 108 | 52 | public function execute($db = NULL, $as_object = NULL, $object_params = NULL) |
|
| 117 | |||
| 118 | 19 | protected function _join($association, $type, $resolve_table_model = TRUE) |
|
| 135 | |||
| 136 | 8 | public function join($association, $type = NULL) |
|
| 142 | |||
| 143 | 1 | public function on($c1, $op, $c2) |
|
| 150 | |||
| 151 | |||
| 152 | 1 | public function join_nested($association, $type = NULL) |
|
| 156 | |||
| 157 | 10 | public function join_table($table, $type = NULL) |
|
| 161 | |||
| 162 | 32 | protected function _compile_order_by(Database $db, array $order_by) |
|
| 171 | |||
| 172 | 1 | protected function _compile_group_by(Database $db, array $group_by) |
|
| 181 | |||
| 182 | 74 | protected function _compile_conditions(Database $db, array $conditions) |
|
| 197 | |||
| 198 | 16 | public function aggregate_query($function, $column = NULL) |
|
| 214 | |||
| 215 | public function aggregate($function, $column = NULL) |
||
| 219 | |||
| 220 | 10 | public function count_all($without_grouping = FALSE) |
|
| 233 | |||
| 234 | public function count_with_subquery() |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Passes unknown methods along to the behaviors. |
||
| 243 | * |
||
| 244 | * @param string $method |
||
| 245 | * @param array $args |
||
| 246 | * @return mixed |
||
| 247 | **/ |
||
| 248 | 40 | public function __call($method, $args) |
|
| 253 | |||
| 254 | /** |
||
| 255 | * Getter/setter for the params array used to store arbitrary values by the behaviors |
||
| 256 | * |
||
| 257 | * @param array|string $params |
||
| 258 | * @param mixed $param |
||
| 259 | * @return Jam_Builder $this |
||
| 260 | */ |
||
| 261 | 29 | public function params($params = NULL, $param = NULL) |
|
| 282 | |||
| 283 | 140 | public function meta() |
|
| 287 | |||
| 288 | /** |
||
| 289 | * You can get some of the parameters of the jam query builder. |
||
| 290 | * |
||
| 291 | * @param string $name one of select, from, join, where, group_by, having, order_by, union, distinct, limit, offset, parameters |
||
| 292 | * @return mixed |
||
| 293 | */ |
||
| 294 | 30 | public function __get($name) |
|
| 301 | |||
| 302 | 43 | public function __toString() |
|
| 314 | |||
| 315 | 14 | public function except($name) |
|
| 331 | } |
||
| 332 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.