HmacSha1Signer::hash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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