Signature   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 31
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B generate() 0 25 5
1
<?php
2
3
namespace Acquia\Network;
4
5
use Acquia\Rest\SignatureAbstract;
6
7
/**
8
 * Generates the HMAC hash used to sign Acquia Network requests.
9
 */
10
class Signature extends SignatureAbstract
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 39
    public function generate($params = array())
16
    {
17 39
         if (!is_array($params)) {
18 3
             throw new \UnexpectedValueException('Expecting data to be an array.');
19
         }
20
21 36
         $time = $this->getRequestTime();
22 36
         $nonce = $this->generateNonce();
23 36
         $key = $this->getSecretKey();
24
25 36
         if (empty($params['rpc_version']) || $params['rpc_version'] < 2) {
26 30
              $string = $time . ':' . $nonce . ':' . $key . ':' . serialize($params);
27
28 30
              return base64_encode(
29 30
                  pack("H*", sha1((str_pad($key, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) .
30 30
                  pack("H*", sha1((str_pad($key, 64, chr(0x00)) ^ (str_repeat(chr(0x36), 64))) .
31 30
                  $string)))));
32 6
        } elseif ($params['rpc_version'] == 2) {
33 3
              $string = $time . ':' . $nonce . ':' . json_encode($params);
34 3
              return sha1((str_pad($key, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) . pack("H*", sha1((str_pad($key, 64, chr(0x00)) ^ (str_repeat(chr(0x36), 64))) . $string)));
35
        } else {
36 3
              $string = $time . ':' . $nonce;
37 3
              return sha1((str_pad($key, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) . pack("H*", sha1((str_pad($key, 64, chr(0x00)) ^ (str_repeat(chr(0x36), 64))) . $string)));
38
        }
39
    }
40
}
41