Complex classes like Schema 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.
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 Schema, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class Schema |
||
15 | { |
||
16 | |||
17 | protected $elementsQualification = true; |
||
18 | |||
19 | protected $attributesQualification = false; |
||
20 | |||
21 | protected $targetNamespace; |
||
22 | |||
23 | protected $schemas = array(); |
||
24 | |||
25 | protected $types = array(); |
||
26 | |||
27 | protected $elements = array(); |
||
28 | |||
29 | protected $groups = array(); |
||
30 | |||
31 | protected $attributeGroups = array(); |
||
32 | |||
33 | protected $attributes = array(); |
||
34 | |||
35 | protected $doc; |
||
36 | |||
37 | private $typeCache = array(); |
||
38 | |||
39 | |||
40 | public function getElementsQualification() |
||
44 | |||
45 | public function setElementsQualification($elementsQualification) |
||
49 | |||
50 | public function getAttributesQualification() |
||
54 | |||
55 | public function setAttributesQualification($attributesQualification) |
||
59 | |||
60 | public function getTargetNamespace() |
||
64 | |||
65 | public function setTargetNamespace($targetNamespace) |
||
69 | |||
70 | public function getTypes() |
||
74 | |||
75 | public function getElements() |
||
79 | |||
80 | public function getSchemas() |
||
84 | |||
85 | public function getAttributes() |
||
89 | |||
90 | public function getGroups() |
||
94 | |||
95 | public function getDoc() |
||
99 | |||
100 | public function setDoc($doc) |
||
104 | |||
105 | public function addType(Type $type) |
||
109 | |||
110 | public function addElement(ElementDef $element) |
||
114 | |||
115 | public function addSchema(Schema $schema, $namespace = null) |
||
127 | |||
128 | public function addAttribute(AttributeDef $attribute) |
||
132 | |||
133 | public function addGroup(Group $group) |
||
137 | |||
138 | public function addAttributeGroup(AttributeGroup $group) |
||
142 | |||
143 | public function getAttributeGroups() |
||
147 | |||
148 | /** |
||
149 | * |
||
150 | * @param string $name |
||
151 | * @return Group|false |
||
152 | */ |
||
153 | public function getGroup($name) |
||
160 | |||
161 | /** |
||
162 | * |
||
163 | * @param string $name |
||
164 | * @return ElementItem|false |
||
165 | */ |
||
166 | public function getElement($name) |
||
173 | |||
174 | /** |
||
175 | * |
||
176 | * @param string $name |
||
177 | * @return Type|false |
||
178 | */ |
||
179 | public function getType($name) |
||
186 | |||
187 | /** |
||
188 | * |
||
189 | * @param string $name |
||
190 | * @return AttributeItem|false |
||
191 | */ |
||
192 | public function getAttribute($name) |
||
199 | |||
200 | /** |
||
201 | * |
||
202 | * @param string $name |
||
203 | * @return AttributeGroup|false |
||
204 | */ |
||
205 | public function getAttributeGroup($name) |
||
212 | |||
213 | public function __toString() |
||
217 | |||
218 | /** |
||
219 | * |
||
220 | * @param string $getter |
||
221 | * @param string $name |
||
222 | * @param string $namespace |
||
223 | * @throws TypeNotFoundException |
||
224 | * @return \Goetas\XML\XSDReader\Schema\SchemaItem |
||
225 | */ |
||
226 | protected function findSomething($getter, $name, $namespace = null, &$calling = array()) |
||
250 | |||
251 | /** |
||
252 | * |
||
253 | * @param string $name |
||
254 | * @param string $namespace |
||
255 | * @return Type |
||
256 | */ |
||
257 | public function findType($name, $namespace = null) |
||
261 | |||
262 | /** |
||
263 | * |
||
264 | * @param string $name |
||
265 | * @param string $namespace |
||
266 | * @return Group |
||
267 | */ |
||
268 | public function findGroup($name, $namespace = null) |
||
272 | |||
273 | /** |
||
274 | * |
||
275 | * @param string $name |
||
276 | * @param string $namespace |
||
277 | * @return ElementDef |
||
278 | */ |
||
279 | public function findElement($name, $namespace = null) |
||
283 | |||
284 | /** |
||
285 | * |
||
286 | * @param string $name |
||
287 | * @param string $namespace |
||
288 | * @return AttributeReal |
||
289 | */ |
||
290 | public function findAttribute($name, $namespace = null) |
||
294 | |||
295 | /** |
||
296 | * |
||
297 | * @param string $name |
||
298 | * @param string $namespace |
||
299 | * @return AttributeGroup |
||
300 | */ |
||
301 | public function findAttributeGroup($name, $namespace = null) |
||
305 | } |
||
306 |