HashGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
c 1
b 0
f 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateHash() 0 10 1
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\FirstData\Business\Api\Generator;
9
10
use SprykerEco\Zed\FirstData\FirstDataConfig;
11
12
class HashGenerator implements HashGeneratorInterface
13
{
14
    /**
15
     * @var \SprykerEco\Zed\FirstData\FirstDataConfig;
16
     */
17
    protected $firstDataConfig;
18
19
    /**
20
     * @param \SprykerEco\Zed\FirstData\FirstDataConfig $firstDataConfig
21
     */
22
    public function __construct(FirstDataConfig $firstDataConfig)
23
    {
24
        $this->firstDataConfig = $firstDataConfig;
25
    }
26
27
    /**
28
     * @param array $params
29
     *
30
     * @return string
31
     */
32
    public function generateHash(array $params): string
33
    {
34
        $messageSignatureContent = implode('', $params);
35
        $hmac = hash_hmac(
36
            $this->firstDataConfig->getHashAlgo(),
37
            $messageSignatureContent,
38
            $this->firstDataConfig->getFirstDataApiSecret()
39
        );
40
41
        return base64_encode($hmac);
42
    }
43
}
44