Passed
Pull Request — master (#305)
by Tim
02:37
created

ExtensionPointTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getXsiTypeName() 0 11 1
A getXsiTypeNamespacePrefix() 0 11 1
A getXsiType() 0 3 1
A getXsiTypeNamespaceURI() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML;
6
7
use RuntimeException;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
11
/**
12
 * Trait for several extension points objects.
13
 *
14
 * @package simplesamlphp/saml2
15
 */
16
trait ExtensionPointTrait
17
{
18
    /**
19
     * Get the local name for the element's xsi:type.
20
     *
21
     * @return string
22
     */
23
    public static function getXsiTypeName(): string
24
    {
25
        Assert::true(
26
            defined('static::NS_XSI_TYPE_NAME'),
27
            self::getClassName(static::class)
28
            . '::NS_XSI_TYPE_NAME constant must be defined and set to unprefixed type for the xsi:type it represents.',
29
            RuntimeException::class,
30
        );
31
32
        Assert::validNCName(static::NS_XSI_TYPE_NAME, SchemaViolationException::class);
0 ignored issues
show
Bug introduced by
The constant SimpleSAML\SAML2\XML\Ext...Trait::NS_XSI_TYPE_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
33
        return static::NS_XSI_TYPE_NAME;
34
    }
35
36
37
    /**
38
     * Get the namespace for the element's xsi:type.
39
     *
40
     * @return string
41
     */
42
    public static function getXsiTypeNamespaceURI(): string
43
    {
44
        Assert::true(
45
            defined('static::NS_XSI_TYPE_NAMESPACE'),
46
            self::getClassName(static::class)
47
            . '::NS_XSI_TYPE_NAMESPACE constant must be defined and set to the namespace for the xsi:type it represents.',
48
            RuntimeException::class,
49
        );
50
51
        Assert::validURI(static::NS_XSI_TYPE_NAMESPACE, SchemaViolationException::class);
0 ignored issues
show
Bug introduced by
The constant SimpleSAML\SAML2\XML\Ext...::NS_XSI_TYPE_NAMESPACE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
52
        return static::NS_XSI_TYPE_NAMESPACE;
53
    }
54
55
56
    /**
57
     * Get the namespace-prefix for the element's xsi:type.
58
     *
59
     * @return string
60
     */
61
    public static function getXsiTypeNamespacePrefix(): string
62
    {
63
        Assert::true(
64
            defined('static::NS_XSI_TYPE_PREFIX'),
65
            self::getClassName(static::class)
66
            . '::NS_XSI_TYPE_PREFIX constant must be defined and set to the namespace for the xsi:type it represents.',
67
            RuntimeException::class,
68
        );
69
70
        Assert::validNCName(static::NS_XSI_TYPE_PREFIX, SchemaViolationException::class);
0 ignored issues
show
Bug introduced by
The constant SimpleSAML\SAML2\XML\Ext...ait::NS_XSI_TYPE_PREFIX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
71
        return static::NS_XSI_TYPE_PREFIX;
72
    }
73
74
75
    /**
76
     * Return the xsi:type value corresponding this element.
77
     *
78
     * @return string
79
     */
80
    public static function getXsiType(): string
81
    {
82
        return static::getXsiTypeNamespacePrefix() . ':' . static::getXsiTypeName();
83
    }
84
}
85