Code Duplication    Length = 33-33 lines in 2 locations

src/Message/Concerns/RequestHash.php 1 location

@@ 17-49 (lines=33) @@
14
 * @author Vuong Minh <[email protected]>
15
 * @since 1.0.0
16
 */
17
trait RequestHash
18
{
19
    /**
20
     * Trả về dữ liệu mã hóa theo [[getHashParameters()]].
21
     *
22
     * @return string
23
     */
24
    protected function generateHash(): string
25
    {
26
        $data = [];
27
        $rsa = new RSAEncrypt(
28
            $this->getPublicKey()
29
        );
30
        $parameters = $this->getParameters();
31
32
        foreach ($this->getHashParameters() as $pos => $parameter) {
33
            if (! is_string($pos)) {
34
                $pos = $parameter;
35
            }
36
37
            $data[$pos] = Arr::getValue($parameter, $parameters);
38
        }
39
40
        return $rsa->encrypt($data);
41
    }
42
43
    /**
44
     * Trả về danh sách parameters dùng để mã hóa gửi đến MoMo.
45
     *
46
     * @return array
47
     */
48
    abstract protected function getHashParameters(): array;
49
}
50

src/Message/Concerns/RequestSignature.php 1 location

@@ 17-49 (lines=33) @@
14
 * @author Vuong Minh <[email protected]>
15
 * @since 1.0.0
16
 */
17
trait RequestSignature
18
{
19
    /**
20
     * Trả về chữ ký điện tử gửi đến MoMo dựa theo [[getSignatureParameters()]].
21
     *
22
     * @return string
23
     */
24
    protected function generateSignature(): string
25
    {
26
        $data = [];
27
        $signature = new Signature(
28
            $this->getSecretKey()
29
        );
30
        $parameters = $this->getParameters();
31
32
        foreach ($this->getSignatureParameters() as $pos => $parameter) {
33
            if (! is_string($pos)) {
34
                $pos = $parameter;
35
            }
36
37
            $data[$pos] = Arr::getValue($parameter, $parameters);
38
        }
39
40
        return $signature->generate($data);
41
    }
42
43
    /**
44
     * Trả về danh sách parameters dùng để tạo chữ ký số.
45
     *
46
     * @return array
47
     */
48
    abstract protected function getSignatureParameters(): array;
49
}
50