Completed
Pull Request — master (#3)
by Risan Bagja
02:02 queued 34s
created

HmacSha1Signer::sign()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Risan\OAuth1\Signature;
4
5
use Risan\OAuth1\Credentials\ClientCredentials;
6
7
class HmacSha1Signer implements SignerInterface, BaseStringSignerInterface, KeyBasedSignerInterface
8
{
9
    use CanBuildBaseString,
10
        CanGetSigningKey;
11
12
    /**
13
     * {@inheritDoc}
14
     */
15 1
    public function getMethod()
16
    {
17 1
        return 'HMAC-SHA1';
18
    }
19
20
    /**
21
     * {@inheritDoc}
22
     */
23 1
    public function sign($uri, array $parameters = [], $httpMethod = 'POST')
24
    {
25 1
        $baseString = $this->buildBaseString($uri, $parameters, $httpMethod);
26
27 1
        return base64_encode($this->hash($baseString));
28
    }
29
30
    /**
31
     * Hash the data with HMAC method.
32
     *
33
     * @param  string $data
34
     * @return string
35
     */
36 2
    public function hash($data)
37
    {
38 2
        return hash_hmac('sha1', $data, $this->getKey(), true);
39
    }
40
}
41