ExtensionPointTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 20
c 1
b 0
f 0
dl 0
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getXsiTypeNamespaceURI() 0 10 1
A getXsiType() 0 3 1
A getXsiTypePrefix() 0 12 1
A getXsiTypeName() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML;
6
7
use RuntimeException;
8
use SimpleSAML\SAML11\Assert\Assert;
9
use SimpleSAML\XMLSchema\Type\{AnyURIValue, NCNameValue, QNameValue};
10
11
use function constant;
12
use function defined;
13
use function sprintf;
14
15
/**
16
 * Trait for several extension points objects.
17
 *
18
 * @package simplesamlphp/saml11
19
 */
20
trait ExtensionPointTrait
21
{
22
    /**
23
     * @return \SimpleSAML\XMLSchema\Type\QNameValue
24
     */
25
    public function getXsiType(): QNameValue
26
    {
27
        return $this->type;
28
    }
29
30
31
    /**
32
     * Get the local name for the element's xsi:type.
33
     *
34
     * @return \SimpleSAML\XMLSchema\Type\NCNameValue
35
     */
36
    public static function getXsiTypeName(): NCNameValue
37
    {
38
        Assert::true(
39
            defined('static::XSI_TYPE_NAME'),
40
            self::getClassName(static::class)
41
            . '::XSI_TYPE_NAME constant must be defined and set to unprefixed type for the xsi:type it represents.',
42
            RuntimeException::class,
43
        );
44
45
        return NCNameValue::fromString(constant('static::XSI_TYPE_NAME'));
46
    }
47
48
49
    /**
50
     * Get the namespace for the element's xsi:type.
51
     *
52
     * @return \SimpleSAML\XMLSchema\Type\AnyURIValue
53
     */
54
    public static function getXsiTypeNamespaceURI(): AnyURIValue
55
    {
56
        Assert::true(
57
            defined('static::XSI_TYPE_NAMESPACE'),
58
            self::getClassName(static::class)
59
            . '::XSI_TYPE_NAMESPACE constant must be defined and set to the namespace for the xsi:type it represents.',
60
            RuntimeException::class,
61
        );
62
63
        return AnyURIValue::fromString(constant('static::XSI_TYPE_NAMESPACE'));
64
    }
65
66
67
    /**
68
     * Get the namespace-prefix for the element's xsi:type.
69
     *
70
     * @return \SimpleSAML\XMLSchema\Type\NCNameValue
71
     */
72
    public static function getXsiTypePrefix(): NCNameValue
73
    {
74
        Assert::true(
75
            defined('static::XSI_TYPE_PREFIX'),
76
            sprintf(
77
                '%s::XSI_TYPE_PREFIX constant must be defined and set to the namespace for the xsi:type it represents.',
78
                self::getClassName(static::class),
79
            ),
80
            RuntimeException::class,
81
        );
82
83
        return NCNameValue::fromString(constant('static::XSI_TYPE_PREFIX'));
84
    }
85
}
86