Passed
Push — master ( ad42db...10cb08 )
by Tim
02:04
created

XMLStringElementTrait::getContent()   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
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XML;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Constants;
10
11
/**
12
 * Trait grouping common functionality for simple elements with just some textContent
13
 *
14
 * @package simplesamlphp/xml-common
15
 */
16
trait XMLStringElementTrait
17
{
18
    /** @var string */
19
    protected string $content;
20
21
22
    /**
23
     * Set the content of the element.
24
     *
25
     * @param string $content  The value to go in the XML textContent
26
     * @param array $validators  An array of callbacks that may perform validations on the content
27
     */
28
    public function setElements(string $content, $validators = []): void
29
    {
30
        if (!empty($validators)) {
31
            foreach ($validators as $validator) {
32
                call_user_func($validator, $content);
33
            }
34
        }
35
36
        $this->content = $content;
37
    }
38
39
40
    /**
41
     * Get the content of the element.
42
     *
43
     * @return string
44
     */
45
    public function getContent(): string
46
    {
47
        return $this->content;
48
    }
49
}
50