Code Duplication    Length = 34-38 lines in 2 locations

src/SAML2/AuthnRequest.php 1 location

@@ 173-206 (lines=34) @@
170
     *
171
     * @throws \Exception
172
     */
173
    private function parseSubject(\DOMElement $xml)
174
    {
175
        $subject = Utils::xpQuery($xml, './saml_assertion:Subject');
176
        if (empty($subject)) {
177
            return;
178
        }
179
180
        if (count($subject) > 1) {
181
            throw new \Exception('More than one <saml:Subject> in <saml:AuthnRequest>.');
182
        }
183
        $subject = $subject[0];
184
185
        $nameId = Utils::xpQuery(
186
            $subject,
187
            './saml_assertion:NameID | ./saml_assertion:EncryptedID/xenc:EncryptedData'
188
        );
189
        if (empty($nameId)) {
190
            throw new \Exception('Missing <saml:NameID> or <saml:EncryptedID> in <saml:Subject>.');
191
        } elseif (count($nameId) > 1) {
192
            throw new \Exception('More than one <saml:NameID> or <saml:EncryptedID> in <saml:Subject>.');
193
        }
194
        $nameId = $nameId[0];
195
        if ($nameId->localName === 'EncryptedData') {
196
            /* The NameID element is encrypted. */
197
            $this->encryptedNameId = $nameId;
198
        } else {
199
            $this->nameId = Utils::parseNameId($nameId);
200
        }
201
202
        $subjectConfirmation = Utils::xpQuery($subject, './saml_assertion:SubjectConfirmation');
203
        foreach ($subjectConfirmation as $sc) {
204
            $this->subjectConfirmation[] = new SubjectConfirmation($sc);
205
        }
206
    }
207
208
    /**
209
     * @param \DOMElement $xml

src/SAML2/Assertion.php 1 location

@@ 273-310 (lines=38) @@
270
     * @param \DOMElement $xml The assertion XML element.
271
     * @throws \Exception
272
     */
273
    private function parseSubject(\DOMElement $xml)
274
    {
275
        $subject = Utils::xpQuery($xml, './saml_assertion:Subject');
276
        if (empty($subject)) {
277
            /* No Subject node. */
278
279
            return;
280
        } elseif (count($subject) > 1) {
281
            throw new \Exception('More than one <saml:Subject> in <saml:Assertion>.');
282
        }
283
        $subject = $subject[0];
284
285
        $nameId = Utils::xpQuery(
286
            $subject,
287
            './saml_assertion:NameID | ./saml_assertion:EncryptedID/xenc:EncryptedData'
288
        );
289
        if (empty($nameId)) {
290
            throw new \Exception('Missing <saml:NameID> or <saml:EncryptedID> in <saml:Subject>.');
291
        } elseif (count($nameId) > 1) {
292
            throw new \Exception('More than one <saml:NameID> or <saml:EncryptedD> in <saml:Subject>.');
293
        }
294
        $nameId = $nameId[0];
295
        if ($nameId->localName === 'EncryptedData') {
296
            /* The NameID element is encrypted. */
297
            $this->encryptedNameId = $nameId;
298
        } else {
299
            $this->nameId = Utils::parseNameId($nameId);
300
        }
301
302
        $subjectConfirmation = Utils::xpQuery($subject, './saml_assertion:SubjectConfirmation');
303
        if (empty($subjectConfirmation)) {
304
            throw new \Exception('Missing <saml:SubjectConfirmation> in <saml:Subject>.');
305
        }
306
307
        foreach ($subjectConfirmation as $sc) {
308
            $this->SubjectConfirmation[] = new SubjectConfirmation($sc);
309
        }
310
    }
311
312
    /**
313
     * Parse conditions in assertion.