Passed
Push — master ( 6db269...70aff8 )
by Jaime Pérez
02:49
created

ExtensionsTrait::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2;
6
7
use DOMElement;
8
use SAML2\XML\AbstractXMLElement;
9
10
/**
11
 * Trait grouping common functionality for elements implementing ExtensionType.
12
 *
13
 * @package simplesamlphp/saml2
14
 */
15
trait ExtensionsTrait
16
{
17
    /**
18
     * @var AbstractXMLElement[]
19
     */
20
    protected $extensions = [];
21
22
23
    /**
24
     * Extensions constructor.
25
     *
26
     * @var AbstractXMLElement[]
27
     */
28
    public function __construct(array $extensions)
29
    {
30
        $this->extensions = $extensions;
31
    }
32
33
34
    /**
35
     * Get an array with all extensions present.
36
     *
37
     * @return AbstractXMLElement[]
38
     */
39
    public function getList(): array
40
    {
41
        return $this->extensions;
42
    }
43
44
45
    /**
46
     * @return bool
47
     */
48
    public function isEmptyElement(): bool
49
    {
50
        if (empty($this->extensions)) {
51
            return true;
52
        }
53
54
        $empty = false;
55
        foreach ($this->extensions as $extension) {
56
            $empty &= $extension->isEmptyElement();
57
        }
58
59
        return boolval($empty);
60
    }
61
62
63
    /**
64
     * Convert this object into its md:Extensions XML representation.
65
     *
66
     * @param \DOMElement|null $parent The element we should add this Extensions element to.
67
     * @return \DOMElement The new md:Extensions XML element.
68
     */
69
    public function toXML(DOMElement $parent = null): DOMElement
70
    {
71
        $e = $this->instantiateParentElement($parent);
0 ignored issues
show
Bug introduced by
It seems like instantiateParentElement() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        /** @scrutinizer ignore-call */ 
72
        $e = $this->instantiateParentElement($parent);
Loading history...
72
        foreach ($this->extensions as $extension) {
73
            if (!$extension->isEmptyElement()) {
74
                $extension->toXML($e);
75
            }
76
        }
77
        return $e;
78
    }
79
}
80