| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 36 | public static function fromXML(DOMElement $xml): static |
||
| 37 | { |
||
| 38 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
| 39 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
| 40 | |||
| 41 | // Prohibited attributes |
||
| 42 | $ref = self::getOptionalAttribute($xml, 'ref', QNameValue::class, null); |
||
| 43 | Assert::null($ref, SchemaViolationException::class); |
||
| 44 | |||
| 45 | $form = self::getOptionalAttribute($xml, 'form', FormChoiceValue::class, null); |
||
| 46 | Assert::null($form, SchemaViolationException::class); |
||
| 47 | |||
| 48 | $minCount = self::getOptionalAttribute($xml, 'minCount', MinOccursValue::class, null); |
||
| 49 | Assert::null($minCount, SchemaViolationException::class); |
||
| 50 | |||
| 51 | $maxCount = self::getOptionalAttribute($xml, 'maxCount', MaxOccursValue::class, null); |
||
| 52 | Assert::null($maxCount, SchemaViolationException::class); |
||
| 53 | |||
| 54 | // The annotation |
||
| 55 | $annotation = Annotation::getChildrenOfClass($xml); |
||
| 56 | Assert::maxCount($annotation, 1, TooManyElementsException::class); |
||
| 57 | |||
| 58 | // The local type |
||
| 59 | $localSimpleType = LocalSimpleType::getChildrenOfClass($xml); |
||
| 60 | Assert::maxCount($localSimpleType, 1, TooManyElementsException::class); |
||
| 61 | |||
| 62 | $localComplexType = LocalComplexType::getChildrenOfClass($xml); |
||
| 63 | Assert::maxCount($localComplexType, 1, TooManyElementsException::class); |
||
| 64 | |||
| 65 | $localType = array_merge($localSimpleType, $localComplexType); |
||
| 66 | Assert::maxCount($localType, 1, TooManyElementsException::class); |
||
| 67 | |||
| 68 | // The identity constraint |
||
| 69 | $key = Key::getChildrenOfClass($xml); |
||
| 70 | $keyref = Keyref::getChildrenOfClass($xml); |
||
| 71 | $unique = Unique::getChildrenOfClass($xml); |
||
| 72 | $identityConstraint = array_merge($key, $keyref, $unique); |
||
| 73 | |||
| 74 | return new static( |
||
| 75 | self::getAttribute($xml, 'name', NCNameValue::class), |
||
| 76 | array_pop($localType), |
||
| 77 | $identityConstraint, |
||
| 78 | self::getOptionalAttribute($xml, 'type', QNameValue::class, null), |
||
| 79 | self::getOptionalAttribute($xml, 'substitutionGroup', QNameValue::class, null), |
||
| 80 | self::getOptionalAttribute($xml, 'default', StringValue::class, null), |
||
| 81 | self::getOptionalAttribute($xml, 'fixed', StringValue::class, null), |
||
| 82 | self::getOptionalAttribute($xml, 'nillable', BooleanValue::class, null), |
||
| 83 | self::getOptionalAttribute($xml, 'abstract', BooleanValue::class, null), |
||
| 84 | self::getOptionalAttribute($xml, 'final', DerivationSetValue::class, null), |
||
| 85 | self::getOptionalAttribute($xml, 'block', BlockSetValue::class, null), |
||
| 86 | array_pop($annotation), |
||
| 87 | self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
||
| 88 | self::getAttributesNSFromXML($xml), |
||
| 89 | ); |
||
| 92 |