Completed
Push — feature/issue-7 ( ac92bc...9d75a7 )
by Mikaël
03:43 queued 11s
created

Nonce   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 44
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A encodeNonce() 0 3 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
    public function __construct($nonce, $namespace = self::NS_WSSE)
33
    {
34
        parent::__construct(self::NAME, $namespace, self::encodeNonce($nonce), [
35
            self::ATTRIBUTE_ENCODING_TYPE => self::NS_ENCODING,
36
        ]);
37
    }
38
39
    /**
40
     * Encode Nonce value.
41
     *
42
     * @param string $nonce
43
     *
44
     * @return string
45
     */
46
    public static function encodeNonce($nonce)
47
    {
48
        return base64_encode(pack('H*', $nonce));
49
    }
50
}
51