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. 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 Schema, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Schema |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @param bool[] $calling |
||
| 21 | * |
||
| 22 | * @return SchemaItem|null |
||
| 23 | */ |
||
| 24 | 47 | protected function findSomethingNoThrow( |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @param Schema[] $schemas |
||
| 60 | * @param bool[] $calling |
||
| 61 | * |
||
| 62 | * @return SchemaItem|null |
||
| 63 | */ |
||
| 64 | 47 | protected function findSomethingNoThrowSchemas( |
|
| 85 | |||
| 86 | /** |
||
| 87 | * @throws TypeNotFoundException |
||
| 88 | */ |
||
| 89 | 47 | protected function findSomething(string $getter, string $name, string $namespace = null, array &$calling = array()): SchemaItem |
|
| 111 | |||
| 112 | /** |
||
| 113 | * @var bool |
||
| 114 | */ |
||
| 115 | protected $elementsQualification = false; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @var bool |
||
| 119 | */ |
||
| 120 | protected $attributesQualification = false; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var string|null |
||
| 124 | */ |
||
| 125 | protected $targetNamespace; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @var Schema[] |
||
| 129 | */ |
||
| 130 | protected $schemas = array(); |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var Type[] |
||
| 134 | */ |
||
| 135 | protected $types = array(); |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var ElementDef[] |
||
| 139 | */ |
||
| 140 | protected $elements = array(); |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @var Group[] |
||
| 144 | */ |
||
| 145 | protected $groups = array(); |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @var AttributeGroup[] |
||
| 149 | */ |
||
| 150 | protected $attributeGroups = array(); |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @var AttributeDef[] |
||
| 154 | */ |
||
| 155 | protected $attributes = array(); |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var string|null |
||
| 159 | */ |
||
| 160 | protected $doc; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @var \GoetasWebservices\XML\XSDReader\Schema\SchemaItem[] |
||
| 164 | */ |
||
| 165 | protected $typeCache = array(); |
||
| 166 | |||
| 167 | public function getElementsQualification(): bool |
||
| 171 | |||
| 172 | 47 | public function setElementsQualification(bool $elementsQualification): void |
|
| 176 | |||
| 177 | public function getAttributesQualification(): bool |
||
| 181 | |||
| 182 | 47 | public function setAttributesQualification(bool $attributesQualification): void |
|
| 186 | |||
| 187 | /** |
||
| 188 | * @return string|null |
||
| 189 | */ |
||
| 190 | 47 | public function getTargetNamespace(): ?string |
|
| 194 | |||
| 195 | /** |
||
| 196 | * @param string|null $targetNamespace |
||
| 197 | */ |
||
| 198 | 47 | public function setTargetNamespace($targetNamespace): void |
|
| 202 | |||
| 203 | /** |
||
| 204 | * @return Type[] |
||
| 205 | */ |
||
| 206 | 5 | public function getTypes(): array |
|
| 210 | |||
| 211 | /** |
||
| 212 | * @return ElementDef[] |
||
| 213 | */ |
||
| 214 | 3 | public function getElements(): array |
|
| 218 | |||
| 219 | /** |
||
| 220 | * @return Schema[] |
||
| 221 | */ |
||
| 222 | 47 | public function getSchemas(): array |
|
| 226 | |||
| 227 | /** |
||
| 228 | * @return AttributeDef[] |
||
| 229 | */ |
||
| 230 | 1 | public function getAttributes(): array |
|
| 234 | |||
| 235 | /** |
||
| 236 | * @return Group[] |
||
| 237 | */ |
||
| 238 | 2 | public function getGroups(): array |
|
| 242 | |||
| 243 | /** |
||
| 244 | * @return string|null |
||
| 245 | */ |
||
| 246 | public function getDoc(): ?string |
||
| 250 | |||
| 251 | 47 | public function setDoc(string $doc): void |
|
| 255 | |||
| 256 | 47 | public function addType(Type $type): void |
|
| 260 | |||
| 261 | 47 | public function addElement(ElementDef $element): void |
|
| 265 | |||
| 266 | 47 | public function addSchema(self $schema, string $namespace = null): void |
|
| 283 | |||
| 284 | 47 | public function addAttribute(AttributeDef $attribute): void |
|
| 288 | |||
| 289 | 47 | public function addGroup(Group $group): void |
|
| 293 | |||
| 294 | 47 | public function addAttributeGroup(AttributeGroup $group): void |
|
| 298 | |||
| 299 | /** |
||
| 300 | * @return AttributeGroup[] |
||
| 301 | */ |
||
| 302 | 1 | public function getAttributeGroups(): array |
|
| 306 | |||
| 307 | 47 | public function getGroup(string $name): ?Group |
|
| 315 | |||
| 316 | 47 | public function getElement(string $name): ?ElementItem |
|
| 324 | |||
| 325 | 47 | public function getType(string $name): ?Type |
|
| 333 | |||
| 334 | 47 | public function getAttribute(string $name): ? AttributeItem |
|
| 342 | |||
| 343 | 47 | public function getAttributeGroup(string $name): ?AttributeGroup |
|
| 351 | |||
| 352 | public function __toString(): string |
||
| 356 | |||
| 357 | 47 | public function findType(string $name, string $namespace = null): Type |
|
| 367 | |||
| 368 | 47 | public function findGroup(string $name, string $namespace = null): Group |
|
| 378 | |||
| 379 | 47 | public function findElement(string $name, string $namespace = null): ElementDef |
|
| 389 | |||
| 390 | 47 | public function findAttribute(string $name, string $namespace = null): AttributeItem |
|
| 400 | |||
| 401 | 47 | public function findAttributeGroup(string $name, string $namespace = null): AttributeGroup |
|
| 411 | } |
||
| 412 |