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

Nonce::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace WsdlToPhp\WsSecurity;
4
5
class Nonce extends Element
6
{
7
    /**
8
     * Element name.
9
     *
10
     * @var string
11
     */
12
    const NAME = 'Nonce';
13
    /**
14
     * Element name.
15
     *
16
     * @var string
17
     */
18
    const ATTRIBUTE_ENCODING_TYPE = 'EncodingType';
19
    /**
20
     * Element name.
21
     *
22
     * @var string
23
     */
24
    const NS_ENCODING = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary';
25
26
    /**
27
     * Constructor for Nonce element.
28
     *
29
     * @param string $nonce     the nonce value
30
     * @param string $namespace the namespace
31
     */
32 48
    public function __construct($nonce, $namespace = self::NS_WSSE)
33
    {
34 48
        parent::__construct(self::NAME, $namespace, self::encodeNonce($nonce), [
35 48
            self::ATTRIBUTE_ENCODING_TYPE => self::NS_ENCODING,
36 24
        ]);
37 48
    }
38
39
    /**
40
     * Encode Nonce value.
41
     *
42
     * @param string $nonce
43
     *
44
     * @return string
45
     */
46 48
    public static function encodeNonce($nonce)
47
    {
48 48
        return base64_encode(pack('H*', $nonce));
49
    }
50
}
51