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