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

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