Completed
Push — master ( f7e09f...fa72d2 )
by Michał
01:58
created

HmacSha1::getGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace nyx\auth\id\protocols\oauth1\signers;
2
3
// External dependencies
4
use Psr\Http\Message\RequestInterface as Request;
5
6
// Internal dependencies
7
use nyx\auth\id\protocols\oauth1;
8
use nyx\auth;
9
10
/**
11
 * OAuth 1.0a HMAC-SHA1 Request Signer
12
 *
13
 * @package     Nyx\Auth
14
 * @version     0.1.0
15
 * @author      Michal Chojnacki <[email protected]>
16
 * @copyright   2012-2017 Nyx Dev Team
17
 * @link        https://github.com/unyx/nyx
18
 * ----
19
 * @see         https://oauth.net/core/1.0a/#anchor15 (Spec #9.2 HMAC-SHA1)
20
 */
21 View Code Duplication
class HmacSha1 extends oauth1\Signer
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function getMethod() : string
27
    {
28
        return oauth1\interfaces\Signer::METHOD_HMAC_SHA1;
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    public function sign(Request $request, array $params, auth\id\credentials\Client $client, auth\interfaces\Credentials $token = null) : string
35
    {
36
        // Base64 encode the generated base string signed using the HMAC-SHA1 method using our client secret and token
37
        // forming the signing key.
38
        return base64_encode($this->getGenerator()->sign($this->buildBaseString($request, $params), $this->createKey($client, $token)));
39
    }
40
41
    /**
42
     * Returns the base signature generator used by this Request Signer.
43
     *
44
     * @return  auth\interfaces\Signer
45
     */
46
    protected function getGenerator() : auth\interfaces\Signer
47
    {
48
        static $generator;
49
50
        return $generator ?? $generator = new auth\signers\hmac\Sha1;
51
    }
52
}
53