Security   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 21
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createSignature() 0 9 2
1
<?php
2
3
namespace Omnipay\CyberSource\Message;
4
5
/**
6
 * Security
7
 *
8
 * This class provides a common signing function.
9
 * While this code could be called statically, it is left as a regular class in order to faciliate unit testing.
10
 */
11
class Security
12
{
13
    /**
14
     * Create signature hash used to verify messages
15
     *
16
     * @param mixed[]  $data    Full set of data
17
     * @param string[] $fields  Array of keys to filter
18
     * @param string   $key     The key used to encrypt the data
19
     *
20
     * @return string  Generated signature
21
     */
22 11
    public function createSignature($data, $fields, $key)
23
    {
24 11
        $signable = array();
25 11
        foreach ($fields as $field) {
26 11
            $signable[] = $field.'='.$data[$field];
27
        }
28 11
        $message = implode(',', $signable);
29 11
        return base64_encode(hash_hmac('sha256', $message, $key, true));
30
    }
31
}
32