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