HashGenerator::generateHash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 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