MessageFactory::fromXML()   B
last analyzed

Complexity

Conditions 8
Paths 8

Size

Total Lines 26
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 22
nc 8
nop 1
dl 0
loc 26
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\Constants was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
12
use function var_export;
13
14
/**
15
 * Factory class for all SAML 2 messages.
16
 *
17
 * @package simplesamlphp/saml2
18
 */
19
abstract class MessageFactory
20
{
21
    /**
22
     * Convert an XML element into a message.
23
     *
24
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
25
     *   if the qualified name of the supplied element is wrong
26
     */
27
    public static function fromXML(DOMElement $xml): AbstractMessage
28
    {
29
        Assert::same(
30
            $xml->namespaceURI,
31
            C::NS_SAMLP,
32
            'Unknown namespace of SAML message: ' . var_export($xml->namespaceURI, true),
33
            InvalidDOMElementException::class,
34
        );
35
36
        switch ($xml->localName) {
37
            case 'AttributeQuery':
38
                return AttributeQuery::fromXML($xml);
39
            case 'AuthnRequest':
40
                return AuthnRequest::fromXML($xml);
41
            case 'LogoutResponse':
42
                return LogoutResponse::fromXML($xml);
43
            case 'LogoutRequest':
44
                return LogoutRequest::fromXML($xml);
45
            case 'Response':
46
                return Response::fromXML($xml);
47
            case 'ArtifactResponse':
48
                return ArtifactResponse::fromXML($xml);
49
            case 'ArtifactResolve':
50
                return ArtifactResolve::fromXML($xml);
51
            default:
52
                throw new InvalidDOMElementException('Unknown SAML message: ' . var_export($xml->localName, true));
53
        }
54
    }
55
}
56