Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 37 |
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 | // Prohibited attributes |
||
48 | $ref = self::getOptionalAttribute($xml, 'ref', QNameValue::class, null); |
||
49 | Assert::null($ref, SchemaViolationException::class); |
||
50 | |||
51 | $form = self::getOptionalAttribute($xml, 'form', FormChoiceValue::class, null); |
||
52 | Assert::null($form, SchemaViolationException::class); |
||
53 | |||
54 | $minCount = self::getOptionalAttribute($xml, 'minCount', MinOccursValue::class, null); |
||
55 | Assert::null($minCount, SchemaViolationException::class); |
||
56 | |||
57 | $maxCount = self::getOptionalAttribute($xml, 'maxCount', MaxOccursValue::class, null); |
||
58 | Assert::null($maxCount, SchemaViolationException::class); |
||
59 | |||
60 | // The annotation |
||
61 | $annotation = Annotation::getChildrenOfClass($xml); |
||
62 | Assert::maxCount($annotation, 1, TooManyElementsException::class); |
||
63 | |||
64 | // The local type |
||
65 | $localSimpleType = LocalSimpleType::getChildrenOfClass($xml); |
||
66 | Assert::maxCount($localSimpleType, 1, TooManyElementsException::class); |
||
67 | |||
68 | $localComplexType = LocalComplexType::getChildrenOfClass($xml); |
||
69 | Assert::maxCount($localComplexType, 1, TooManyElementsException::class); |
||
70 | |||
71 | $localType = array_merge($localSimpleType, $localComplexType); |
||
72 | Assert::maxCount($localType, 1, TooManyElementsException::class); |
||
73 | |||
74 | // The identity constraint |
||
75 | $key = Key::getChildrenOfClass($xml); |
||
76 | $keyref = Keyref::getChildrenOfClass($xml); |
||
77 | $unique = Unique::getChildrenOfClass($xml); |
||
78 | $identityConstraint = array_merge($key, $keyref, $unique); |
||
79 | |||
80 | return new static( |
||
81 | self::getAttribute($xml, 'name', NCNameValue::class), |
||
82 | array_pop($localType), |
||
83 | $identityConstraint, |
||
84 | self::getOptionalAttribute($xml, 'type', QNameValue::class, null), |
||
85 | self::getOptionalAttribute($xml, 'substitutionGroup', QNameValue::class, null), |
||
86 | self::getOptionalAttribute($xml, 'default', StringValue::class, null), |
||
87 | self::getOptionalAttribute($xml, 'fixed', StringValue::class, null), |
||
88 | self::getOptionalAttribute($xml, 'nillable', BooleanValue::class, null), |
||
89 | self::getOptionalAttribute($xml, 'abstract', BooleanValue::class, null), |
||
90 | self::getOptionalAttribute($xml, 'final', DerivationSetValue::class, null), |
||
91 | self::getOptionalAttribute($xml, 'block', BlockSetValue::class, null), |
||
92 | array_pop($annotation), |
||
93 | self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
||
94 | self::getAttributesNSFromXML($xml), |
||
95 | ); |
||
98 |