| Conditions | 9 |
| Paths | 6 |
| Total Lines | 70 |
| Code Lines | 36 |
| 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 |
||
| 106 | public static function fromXML(DOMElement $xml): static |
||
| 107 | { |
||
| 108 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
| 109 | Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
||
| 110 | |||
| 111 | $user = User::getChildrenOfClass($xml); |
||
| 112 | Assert::count( |
||
| 113 | $user, |
||
| 114 | 1, |
||
| 115 | 'Exactly one <cas:user> must be specified.', |
||
| 116 | MissingElementException::class, |
||
| 117 | ); |
||
| 118 | |||
| 119 | $attributes = Attributes::getChildrenOfClass($xml); |
||
| 120 | Assert::count( |
||
| 121 | $attributes, |
||
| 122 | 1, |
||
| 123 | 'Exactly one <cas:attributes> must be specified.', |
||
| 124 | MissingElementException::class, |
||
| 125 | ); |
||
| 126 | |||
| 127 | $proxyGrantingTicket = ProxyGrantingTicket::getChildrenOfClass($xml); |
||
| 128 | $proxies = Proxies::getChildrenOfClass($xml); |
||
| 129 | |||
| 130 | $obj = new static( |
||
| 131 | $user[0], |
||
| 132 | $attributes[0], |
||
| 133 | array_pop($proxyGrantingTicket), |
||
| 134 | array_pop($proxies), |
||
| 135 | ); |
||
| 136 | |||
| 137 | /* |
||
| 138 | * Technolutions Slate’s SAMLValidate may emit vendor elements (e.g., slate:person, slate:round) directly under |
||
| 139 | * cas:authenticationSuccess, not only inside cas:attributes. To interoperate without loosening CAS strictness, |
||
| 140 | * we preserve and round‑trip only non‑CAS, namespaced children at that level and ignore unknown CAS‑namespace |
||
| 141 | * elements. |
||
| 142 | * This keeps vendor metadata intact for consumers (XPath, downstream mapping) while avoiding acceptance of |
||
| 143 | * schema‑unknown CAS elements. |
||
| 144 | */ |
||
| 145 | $metadata = []; |
||
| 146 | foreach ($xml->childNodes as $child) { |
||
| 147 | if (!$child instanceof DOMElement) { |
||
| 148 | continue; |
||
| 149 | } |
||
| 150 | |||
| 151 | // Skip all known CAS elements in the CAS namespace |
||
| 152 | if ($child->namespaceURI === static::getNamespaceURI()) { |
||
| 153 | // Known, schema-defined children |
||
| 154 | if ( |
||
| 155 | $child->localName === 'user' || |
||
| 156 | $child->localName === 'attributes' || |
||
| 157 | $child->localName === 'proxyGrantingTicket' || |
||
| 158 | $child->localName === 'proxies' |
||
| 159 | ) { |
||
| 160 | continue; |
||
| 161 | } |
||
| 162 | // Unknown elements in the CAS namespace are ignored to preserve strictness |
||
| 163 | continue; |
||
| 164 | } |
||
| 165 | |||
| 166 | // Only keep vendor elements with a non-null namespace (exclude local/no-namespace) |
||
| 167 | if ($child->namespaceURI === null) { |
||
| 168 | continue; |
||
| 169 | } |
||
| 170 | |||
| 171 | $metadata[] = $child; |
||
| 172 | } |
||
| 173 | $obj->authenticationSuccessMetadata = $metadata; |
||
| 174 | |||
| 175 | return $obj; |
||
| 176 | } |
||
| 205 |