Completed
Push — feature/issue-7 ( 9d75a7...1ff64b )
by Mikaël
03:36
created

Security::setUsernameToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace WsdlToPhp\WsSecurity;
4
5
class Security extends Element
6
{
7
    /**
8
     * Element name.
9
     *
10
     * @var string
11
     */
12
    const NAME = 'Security';
13
    /**
14
     * Element attribute mustunderstand name.
15
     *
16
     * @var string
17
     */
18
    const ATTRIBUTE_MUST_UNDERSTAND = ':mustunderstand';
19
    /**
20
     * Element attribute mustunderstand name.
21
     *
22
     * @var string
23
     */
24
    const ATTRIBUTE_ACTOR = ':actor';
25
    /**
26
     * Envelop namespace.
27
     *
28
     * @var string
29
     */
30
    const ENV_NAMESPACE = 'SOAP-ENV';
31
    /**
32
     * UsernameToken element.
33
     *
34
     * @var UsernameToken
35
     */
36
    protected $usernameToken;
37
    /**
38
     * Timestamp element.
39
     *
40
     * @var Timestamp
41
     */
42
    protected $timestamp;
43
44
    /**
45
     * Constructor for Nonce element.
46
     *
47
     * @param bool   $mustunderstand
48
     * @param string $actor
49
     * @param string $envelopeNamespace
50
     * @param string $namespace         the namespace
51
     */
52 54
    public function __construct($mustunderstand = false, $actor = null, $namespace = self::NS_WSSE, $envelopeNamespace = self::ENV_NAMESPACE)
53
    {
54 54
        parent::__construct(self::NAME, $namespace);
55
        // Sets attributes
56 54
        if (true === $mustunderstand) {
57 42
            $this->setAttribute($envelopeNamespace . self::ATTRIBUTE_MUST_UNDERSTAND, $mustunderstand);
58 21
        }
59 54
        if (!empty($actor)) {
60 36
            $this->setAttribute($envelopeNamespace . self::ATTRIBUTE_ACTOR, $actor);
61 18
        }
62 54
    }
63
64
    /**
65
     * Overrides methods in order to set the values.
66
     *
67
     * @param bool $asDomElement returns elements as a DOMElement or as a string
68
     *
69
     * @return \DOMElement|string
70
     */
71 54
    protected function __toSend($asDomElement = false)
72
    {
73 54
        $this->setValue([
74 54
            $this->getUsernameToken(),
75 54
            $this->getTimestamp(),
76 27
        ]);
77
78 54
        return parent::__toSend($asDomElement);
79
    }
80
81
    /**
82
     * @return UsernameToken
83
     */
84 54
    public function getUsernameToken()
85
    {
86 54
        return $this->usernameToken;
87
    }
88
89
    /**
90
     * @param UsernameToken $usernameToken
91
     *
92
     * @return Security
93
     */
94 54
    public function setUsernameToken(UsernameToken $usernameToken)
95
    {
96 54
        $this->usernameToken = $usernameToken;
97
98 54
        return $this;
99
    }
100
101
    /**
102
     * @return Timestamp
103
     */
104 54
    public function getTimestamp()
105
    {
106 54
        return $this->timestamp;
107
    }
108
109
    /**
110
     * @param Timestamp $timestamp
111
     *
112
     * @return Security
113
     */
114 6
    public function setTimestamp(Timestamp $timestamp)
115
    {
116 6
        $this->timestamp = $timestamp;
117
118 6
        return $this;
119
    }
120
}
121