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

UsernameToken::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace WsdlToPhp\WsSecurity;
4
5
class UsernameToken extends Element
6
{
7
    /**
8
     * Element name.
9
     *
10
     * @var string
11
     */
12
    const NAME = 'UsernameToken';
13
    /**
14
     * Attribute id name.
15
     *
16
     * @var string
17
     */
18
    const ATTRIBUTE_ID = 'Id';
19
    /**
20
     * Username element.
21
     *
22
     * @var Username
23
     */
24
    protected $username;
25
    /**
26
     * Password element.
27
     *
28
     * @var Password
29
     */
30
    protected $password;
31
    /**
32
     * Created element.
33
     *
34
     * @var Created
35
     */
36
    protected $created;
37
    /**
38
     * Nonce element.
39
     *
40
     * @var Nonce
41
     */
42
    protected $nonce;
43
44
    /**
45
     * Constructor for UsernameToken element.
46
     *
47
     * @see Element::__construct()
48
     *
49
     * @param string $id
50
     * @param string $namespace the namespace
51
     */
52 54
    public function __construct($id = null, $namespace = self::NS_WSSE)
53
    {
54 54
        parent::__construct(self::NAME, $namespace, null, empty($id) ? [] : [
55 33
            sprintf('%s:%s', parent::NS_WSSU_NAME, self::ATTRIBUTE_ID) => $id,
56 27
        ]);
57 54
    }
58
59
    /**
60
     * Overrides method in order to add username, password and created values if they are set.
61
     *
62
     * @param bool $asDomElement returns elements as a DOMElement or as a string
63
     *
64
     * @return string
65
     */
66 54
    protected function __toSend($asDomElement = false)
67
    {
68 54
        $this->setValue([
69 54
            $this->getUsername(),
70 54
            $this->getPassword(),
71 54
            $this->getCreated(),
72 54
            $this->getNonce(),
73 27
        ]);
74
75 54
        return parent::__toSend($asDomElement);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::__toSend($asDomElement) also could return the type DOMElement which is incompatible with the documented return type string.
Loading history...
76
    }
77
78
    /**
79
     * @return Username
80
     */
81 54
    public function getUsername()
82
    {
83 54
        return $this->username;
84
    }
85
86
    /**
87
     * @param Username $username
88
     *
89
     * @return UsernameToken
90
     */
91 54
    public function setUsername(Username $username)
92
    {
93 54
        $this->username = $username;
94
95 54
        return $this;
96
    }
97
98
    /**
99
     * @return Password
100
     */
101 54
    public function getPassword()
102
    {
103 54
        return $this->password;
104
    }
105
106
    /**
107
     * @param Password $password
108
     *
109
     * @return UsernameToken
110
     */
111 54
    public function setPassword($password)
112
    {
113 54
        $this->password = $password;
114
115 54
        return $this;
116
    }
117
118
    /**
119
     * @return Created
120
     */
121 54
    public function getCreated()
122
    {
123 54
        return $this->created;
124
    }
125
126
    /**
127
     * @param Created $created
128
     *
129
     * @return UsernameToken
130
     */
131 54
    public function setCreated($created)
132
    {
133 54
        $this->created = $created;
134
135 54
        return $this;
136
    }
137
138
    /**
139
     * @return Nonce
140
     */
141 54
    public function getNonce()
142
    {
143 54
        return $this->nonce;
144
    }
145
146
    /**
147
     * @param Nonce $nonce
148
     *
149
     * @return UsernameToken
150
     */
151 48
    public function setNonce($nonce)
152
    {
153 48
        $this->nonce = $nonce;
154
155 48
        return $this;
156
    }
157
}
158