Security::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
cc 3
nc 4
nop 4
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\WsSecurity;
6
7
use DOMElement;
8
9
class Security extends Element
10
{
11
    public const NAME = 'Security';
12
13
    public const ATTRIBUTE_MUST_UNDERSTAND = ':mustunderstand';
14
15
    public const ATTRIBUTE_ACTOR = ':actor';
16
17
    public const ENV_NAMESPACE = 'SOAP-ENV';
18
19
    protected ?UsernameToken $usernameToken = null;
20
21
    protected ?Timestamp $timestamp = null;
22
23 18
    public function __construct(bool $mustUnderstand = false, ?string $actor = null, string $namespace = self::NS_WSSE, string $envelopeNamespace = self::ENV_NAMESPACE)
24
    {
25 18
        parent::__construct(self::NAME, $namespace);
26
27 18
        if (true === $mustUnderstand) {
28 14
            $this->setAttribute($envelopeNamespace.self::ATTRIBUTE_MUST_UNDERSTAND, $mustUnderstand);
29
        }
30
31 18
        if (!empty($actor)) {
32 12
            $this->setAttribute($envelopeNamespace.self::ATTRIBUTE_ACTOR, $actor);
33
        }
34
    }
35
36
    /**
37
     * Overrides methods in order to set the values.
38
     *
39
     * @param bool $asDomElement returns elements as a DOMElement or as a string
40
     *
41
     * @return DOMElement|false|string
42
     */
43 18
    protected function __toSend(bool $asDomElement = false)
44
    {
45 18
        $this->setValue([
46 18
            $this->getUsernameToken(),
47 18
            $this->getTimestamp(),
48
        ]);
49
50 18
        return parent::__toSend($asDomElement);
51
    }
52
53 18
    public function getUsernameToken(): ?UsernameToken
54
    {
55 18
        return $this->usernameToken;
56
    }
57
58 18
    public function setUsernameToken(UsernameToken $usernameToken): self
59
    {
60 18
        $this->usernameToken = $usernameToken;
61
62 18
        return $this;
63
    }
64
65 18
    public function getTimestamp(): ?Timestamp
66
    {
67 18
        return $this->timestamp;
68
    }
69
70 2
    public function setTimestamp(Timestamp $timestamp): self
71
    {
72 2
        $this->timestamp = $timestamp;
73
74 2
        return $this;
75
    }
76
}
77