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