Conditions | 3 |
Paths | 2 |
Total Lines | 131 |
Code Lines | 90 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
38 | public static function fromXML(DOMElement $xml): static |
||
39 | { |
||
40 | Assert::same($xml->localName, 'RoleDescriptor', InvalidDOMElementException::class); |
||
41 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
42 | |||
43 | Assert::true( |
||
44 | $xml->hasAttributeNS(C::NS_XSI, 'type'), |
||
45 | 'Missing required xsi:type in <saml:RoleDescriptor> element.', |
||
46 | SchemaViolationException::class, |
||
47 | ); |
||
48 | |||
49 | $type = $xml->getAttributeNS(C::NS_XSI, 'type'); |
||
50 | Assert::validQName($type, SchemaViolationException::class); |
||
51 | Assert::same($type, static::XSI_TYPE_PREFIX . ':' . static::XSI_TYPE_NAME,); |
||
52 | |||
53 | $protocols = self::getAttribute($xml, 'protocolSupportEnumeration'); |
||
54 | $validUntil = self::getOptionalAttribute($xml, 'validUntil', null); |
||
55 | SAMLAssert::nullOrValidDateTime($validUntil); |
||
56 | |||
57 | $orgs = Organization::getChildrenOfClass($xml); |
||
58 | Assert::maxCount( |
||
59 | $orgs, |
||
60 | 1, |
||
61 | 'More than one Organization found in this descriptor', |
||
62 | TooManyElementsException::class, |
||
63 | ); |
||
64 | |||
65 | $extensions = Extensions::getChildrenOfClass($xml); |
||
66 | Assert::maxCount( |
||
67 | $extensions, |
||
68 | 1, |
||
69 | 'Only one md:Extensions element is allowed.', |
||
70 | TooManyElementsException::class, |
||
71 | ); |
||
72 | |||
73 | $logicalServiceNamesOffered = LogicalServiceNamesOffered::getChildrenOfClass($xml); |
||
74 | Assert::maxCount( |
||
75 | $logicalServiceNamesOffered, |
||
76 | 1, |
||
77 | 'Only one fed:LogicalServiceNamesOffered is allowed.', |
||
78 | TooManyElementsException::class, |
||
79 | ); |
||
80 | |||
81 | $tokenTypesOffered = TokenTypesOffered::getChildrenOfClass($xml); |
||
82 | Assert::maxCount( |
||
83 | $tokenTypesOffered, |
||
84 | 1, |
||
85 | 'Only one fed:TokenTypesOffered is allowed.', |
||
86 | TooManyElementsException::class, |
||
87 | ); |
||
88 | |||
89 | $claimDialectsOffered = ClaimDialectsOffered::getChildrenOfClass($xml); |
||
90 | Assert::maxCount( |
||
91 | $claimDialectsOffered, |
||
92 | 1, |
||
93 | 'Only one fed:ClaimDialectsOffered is allowed.', |
||
94 | TooManyElementsException::class, |
||
95 | ); |
||
96 | |||
97 | $claimTypesOffered = ClaimTypesOffered::getChildrenOfClass($xml); |
||
98 | Assert::maxCount( |
||
99 | $claimTypesOffered, |
||
100 | 1, |
||
101 | 'Only one fed:ClaimTypesOffered is allowed.', |
||
102 | TooManyElementsException::class, |
||
103 | ); |
||
104 | |||
105 | $claimTypesRequested = ClaimTypesRequested::getChildrenOfClass($xml); |
||
106 | Assert::maxCount( |
||
107 | $claimTypesRequested, |
||
108 | 1, |
||
109 | 'Only one fed:ClaimTypesRequested is allowed.', |
||
110 | TooManyElementsException::class, |
||
111 | ); |
||
112 | |||
113 | $automaticPseudonyms = AutomaticPseudonyms::getChildrenOfClass($xml); |
||
114 | Assert::maxCount( |
||
115 | $automaticPseudonyms, |
||
116 | 1, |
||
117 | 'Only one fed:AutomaticPseudonyms is allowed.', |
||
118 | TooManyElementsException::class, |
||
119 | ); |
||
120 | |||
121 | $targetScopes = TargetScopes::getChildrenOfClass($xml); |
||
122 | Assert::maxCount( |
||
123 | $targetScopes, |
||
124 | 1, |
||
125 | 'Only one fed:TargetScopes is allowed.', |
||
126 | TooManyElementsException::class, |
||
127 | ); |
||
128 | |||
129 | $signature = Signature::getChildrenOfClass($xml); |
||
130 | Assert::maxCount( |
||
131 | $signature, |
||
132 | 1, |
||
133 | 'Only one ds:Signature element is allowed.', |
||
134 | TooManyElementsException::class, |
||
135 | ); |
||
136 | |||
137 | $securityTokenServiceType = new static( |
||
138 | preg_split('/[\s]+/', trim($protocols)), |
||
139 | self::getOptionalAttribute($xml, 'ID', null), |
||
140 | $validUntil !== null ? new DateTimeImmutable($validUntil) : null, |
||
141 | self::getOptionalAttribute($xml, 'cacheDuration', null), |
||
142 | array_pop($extensions), |
||
143 | self::getOptionalAttribute($xml, 'errorURL', null), |
||
144 | KeyDescriptor::getChildrenOfClass($xml), |
||
145 | array_pop($orgs), |
||
146 | ContactPerson::getChildrenOfClass($xml), |
||
147 | self::getAttributesNSFromXML($xml), |
||
148 | array_pop($logicalServiceNamesOffered), |
||
149 | array_pop($tokenTypesOffered), |
||
150 | array_pop($claimDialectsOffered), |
||
151 | array_pop($claimTypesOffered), |
||
152 | array_pop($claimTypesRequested), |
||
153 | array_pop($automaticPseudonyms), |
||
154 | array_pop($targetScopes), |
||
155 | self::getOptionalAttribute($xml, 'ServiceDisplayName', null), |
||
156 | self::getOptionalAttribute($xml, 'ServiceDescription', null), |
||
157 | SecurityTokenServiceEndpoint::getChildrenOfClass($xml), |
||
158 | SingleSignOutSubscriptionEndpoint::getChildrenOfClass($xml), |
||
159 | SingleSignOutNotificationEndpoint::getChildrenOfClass($xml), |
||
160 | PassiveRequestorEndpoint::getChildrenOfClass($xml), |
||
161 | ); |
||
162 | |||
163 | if (!empty($signature)) { |
||
164 | $securityTokenServiceType->setSignature($signature[0]); |
||
165 | $securityTokenServiceType->setXML($xml); |
||
166 | } |
||
167 | |||
168 | return $securityTokenServiceType; |
||
169 | } |
||
171 |