Complex classes like BasicObject 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 BasicObject, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class BasicObject |
||
| 8 | { |
||
| 9 | const ACCESS_NONE = null; |
||
| 10 | const ACCESS_PUBLIC = 1; |
||
| 11 | const ACCESS_PROTECTED = 2; |
||
| 12 | const ACCESS_PRIVATE = 3; |
||
| 13 | |||
| 14 | const OPERATOR_NONE = null; |
||
| 15 | const OPERATOR_ARRAY = 1; |
||
| 16 | const OPERATOR_OBJECT = 2; |
||
| 17 | const OPERATOR_STATIC = 3; |
||
| 18 | |||
| 19 | public $name; |
||
| 20 | public $type; |
||
| 21 | public $static = false; |
||
| 22 | public $const = false; |
||
| 23 | public $access = self::ACCESS_NONE; |
||
| 24 | public $owner_class; |
||
| 25 | public $access_path; |
||
| 26 | public $operator = self::OPERATOR_NONE; |
||
| 27 | public $reference = false; |
||
| 28 | public $size = null; |
||
| 29 | public $depth = 0; |
||
| 30 | public $value = null; |
||
| 31 | public $hints = array(); |
||
| 32 | |||
| 33 | protected $representations = array(); |
||
| 34 | |||
| 35 | public function __construct() |
||
| 38 | |||
| 39 | public function addRepresentation(Representation $rep, $pos = null) |
||
| 57 | |||
| 58 | public function replaceRepresentation(Representation $rep, $pos = null) |
||
| 67 | |||
| 68 | public function removeRepresentation($rep) |
||
| 76 | |||
| 77 | public function getRepresentation($name) |
||
| 83 | |||
| 84 | public function getRepresentations() |
||
| 88 | |||
| 89 | public function clearRepresentations() |
||
| 93 | |||
| 94 | public function getType() |
||
| 98 | |||
| 99 | public function getModifiers() |
||
| 115 | |||
| 116 | public function getAccess() |
||
| 127 | |||
| 128 | public function getName() |
||
| 132 | |||
| 133 | public function getOperator() |
||
| 145 | |||
| 146 | public function getSize() |
||
| 150 | |||
| 151 | public function getValueShort() |
||
| 161 | |||
| 162 | public function getAccessPath() |
||
| 166 | |||
| 167 | public static function blank($name = null, $access_path = null) |
||
| 178 | |||
| 179 | public function transplant(BasicObject $new) |
||
| 198 | |||
| 199 | public static function sortByAccess(BasicObject $a, BasicObject $b) |
||
| 210 | |||
| 211 | public static function sortByName(BasicObject $a, BasicObject $b) |
||
| 221 | } |
||
| 222 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.