HmacSha1Signer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sign() 0 5 1
A hash() 0 3 1
A getMethod() 0 3 1
1
<?php
2
3
namespace Risan\OAuth1\Signature;
4
5
class HmacSha1Signer implements SignerInterface, BaseStringSignerInterface, KeyBasedSignerInterface
6
{
7
    use CanBuildBaseString,
8
        CanGetSigningKey;
9
10
    /**
11
     * {@inheritdoc}
12
     */
13 1
    public function getMethod()
14
    {
15 1
        return 'HMAC-SHA1';
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 1
    public function sign($uri, array $parameters = [], $httpMethod = 'POST')
22
    {
23 1
        $baseString = $this->buildBaseString($uri, $parameters, $httpMethod);
24
25 1
        return base64_encode($this->hash($baseString));
26
    }
27
28
    /**
29
     * Hash the data with HMAC method.
30
     *
31
     * @param string $data
32
     *
33
     * @return string
34
     */
35 2
    public function hash($data)
36
    {
37 2
        return hash_hmac('sha1', $data, $this->getKey(), true);
38
    }
39
}
40