Complex classes like XMLReaderElement 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 XMLReaderElement, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
4 | class XMLReaderElement implements \Iterator { |
||
5 | |||
6 | protected $namespace; |
||
7 | protected $name; |
||
8 | protected $attributes; |
||
9 | protected $value; |
||
10 | |||
11 | public function rewind() { |
||
14 | |||
15 | public function current() { |
||
18 | |||
19 | public function key() { |
||
22 | |||
23 | public function next() { |
||
26 | |||
27 | public function valid() { |
||
31 | |||
32 | public function parse($data) { |
||
50 | |||
51 | protected function isElementArray($value) { |
||
54 | |||
55 | protected function isElementValue($value) { |
||
58 | |||
59 | protected function parseNameSpace($data) { |
||
70 | |||
71 | protected function convertAttributes($attributes) { |
||
78 | |||
79 | protected function convertValue($value) { |
||
94 | |||
95 | /* Very specific type of integer checking to ensure |
||
96 | that we have a number value, and not one that has been |
||
97 | mistakenly casted by PHP. Examples below. |
||
98 | |||
99 | var_dump(isInteger(23)); //bool(true) |
||
100 | var_dump(isInteger("23")); //bool(true) |
||
101 | var_dump(isInteger(23.5)); //bool(false) |
||
102 | var_dump(isInteger(NULL)); //bool(false) |
||
103 | var_dump(isInteger("")); //bool(false) |
||
104 | */ |
||
105 | protected function isInteger($input) { |
||
108 | |||
109 | /* Very specific type of boolean checking to ensure |
||
110 | that we have a bool value, and not one that has been |
||
111 | mistakenly casted by PHP. Examples below. |
||
112 | |||
113 | var_dump(isBool(true)); //bool(true) |
||
114 | var_dump(isBool("false")); //bool(true) |
||
115 | var_dump(isBool(0)); //bool(false) |
||
116 | var_dump(isBool(NULL)); //bool(false) |
||
117 | var_dump(isBool("")); //bool(false) |
||
118 | */ |
||
119 | protected function isBool($input) { |
||
122 | |||
123 | public function children() { |
||
140 | |||
141 | public function hasChildren() { |
||
144 | |||
145 | public function findFirst($search) { |
||
148 | |||
149 | public function find($search) { |
||
168 | |||
169 | protected function findAttribute($search) { |
||
178 | |||
179 | public function __get($name) { |
||
189 | |||
190 | public function __debugInfo() { |
||
210 | } |
||
211 |