| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 42 | public static function fromXML(DOMElement $xml): static |
||
| 43 | { |
||
| 44 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
| 45 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
| 46 | |||
| 47 | $annotation = Annotation::getChildrenOfClass($xml); |
||
| 48 | Assert::maxCount($annotation, 1, TooManyElementsException::class); |
||
| 49 | |||
| 50 | $simpleContent = SimpleContent::getChildrenOfClass($xml); |
||
| 51 | Assert::maxCount($simpleContent, 1, TooManyElementsException::class); |
||
| 52 | |||
| 53 | $complexContent = ComplexContent::getChildrenOfClass($xml); |
||
| 54 | Assert::maxCount($complexContent, 1, TooManyElementsException::class); |
||
| 55 | |||
| 56 | $content = array_merge($simpleContent, $complexContent); |
||
| 57 | Assert::maxCount($content, 1, TooManyElementsException::class); |
||
| 58 | |||
| 59 | $referencedGroup = ReferencedGroup::getChildrenOfClass($xml); |
||
| 60 | Assert::maxCount($referencedGroup, 1, TooManyElementsException::class); |
||
| 61 | |||
| 62 | $all = All::getChildrenOfClass($xml); |
||
| 63 | Assert::maxCount($all, 1, TooManyElementsException::class); |
||
| 64 | |||
| 65 | $choice = Choice::getChildrenOfClass($xml); |
||
| 66 | Assert::maxCount($choice, 1, TooManyElementsException::class); |
||
| 67 | |||
| 68 | $sequence = Sequence::getChildrenOfClass($xml); |
||
| 69 | Assert::maxCount($sequence, 1, TooManyElementsException::class); |
||
| 70 | |||
| 71 | $particles = array_merge($referencedGroup, $all, $choice, $sequence); |
||
| 72 | Assert::maxCount($particles, 1, TooManyElementsException::class); |
||
| 73 | |||
| 74 | $localAttribute = LocalAttribute::getChildrenOfClass($xml); |
||
| 75 | $referencedAttributeGroup = ReferencedAttributeGroup::getChildrenOfClass($xml); |
||
| 76 | $attributes = array_merge($localAttribute, $referencedAttributeGroup); |
||
| 77 | |||
| 78 | $anyAttribute = AnyAttribute::getChildrenOfClass($xml); |
||
| 79 | Assert::maxCount($anyAttribute, 1, TooManyElementsException::class); |
||
| 80 | |||
| 81 | return new static( |
||
| 82 | self::getAttribute($xml, 'name', NCNameValue::class), |
||
| 83 | self::getOptionalAttribute($xml, 'mixed', BooleanValue::class, null), |
||
| 84 | self::getOptionalAttribute($xml, 'abstract', BooleanValue::class, null), |
||
| 85 | self::getOptionalAttribute($xml, 'final', DerivationSetValue::class, null), |
||
| 86 | self::getOptionalAttribute($xml, 'block', DerivationSetValue::class, null), |
||
| 87 | array_pop($content), |
||
| 88 | array_pop($particles), |
||
| 89 | $attributes, |
||
| 90 | array_pop($anyAttribute), |
||
| 91 | array_pop($annotation), |
||
| 92 | self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
||
| 93 | self::getAttributesNSFromXML($xml), |
||
| 94 | ); |
||
| 97 |