Sorter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 51
c 1
b 0
f 0
dl 0
loc 89
ccs 9
cts 9
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sortResponseParams() 0 5 1
A sort() 0 8 1
A sortRequestParams() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of the Pixidos package.
5
 *
6
 *  (c) Ondra Votava <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 *
11
 */
12
13
declare(strict_types=1);
14
15
namespace Pixidos\GPWebPay\Param\Utils;
16
17
use Pixidos\GPWebPay\Data\ResponseInterface;
18
use Pixidos\GPWebPay\Enum\Param;
19
20
class Sorter
21
{
22
    public const REQUEST_PARAM_ORDER = [
23
            Param::MERCHANTNUMBER,
24
            Param::OPERATION,
25
            Param::ORDERNUMBER,
26
            Param::AMOUNT,
27
            Param::CURRENCY,
28
            Param::DEPOSITFLAG,
29
            Param::MERORDERNUM,
30
            Param::RESPONSE_URL,
31
            Param::DESCRIPTION,
32
            Param::MD,
33
            Param::USERPARAM,
34
            Param::VRCODE,
35
            Param::FASTPAYID,
36
            Param::PAYMETHOD,
37
            Param::DISABLEPAYMETHOD,
38
            Param::PAYMETHODS,
39
            Param::EMAIL,
40
            Param::REFERENCENUMBER,
41
            Param::ADDINFO,
42
            Param::PANPATTERN,
43
            Param::TOKEN,
44
            Param::FAST_TOKEN,
45
            Param::DIGEST,
46
            Param::LANG,
47
    ];
48
49
    public const RESPONSE_PARAM_ORDER = [
50
            Param::OPERATION,
51
            Param::ORDERNUMBER,
52
            Param::MERORDERNUM,
53
            Param::MD,
54
            ResponseInterface::PRCODE,
55
            ResponseInterface::SRCODE,
56
            ResponseInterface::RESULTTEXT,
57
            Param::USERPARAM,
58
            Param::ADDINFO,
59
            Param::TOKEN,
60
            ResponseInterface::EXPIRY,
61
            ResponseInterface::ACSRES,
62
            ResponseInterface::ACCODE,
63
            Param::PANPATTERN,
64
            ResponseInterface::DAYTOCAPTURE,
65
            ResponseInterface::TOKENREGSTATUS,
66
            Param::DIGEST,
67
            'DIGEST1',
68
    ];
69
70
71
    /**
72
     * @template T
73
     * @param array<string, T> $params
74
     * @return array<string, T>
75
     */
76 9
    public static function sortRequestParams(array $params): array
77
    {
78 9
        $order = array_flip(self::REQUEST_PARAM_ORDER);
79
80 9
        return self::sort($params, $order);
81
    }
82
83
    /**
84
     * @template T
85
     * @param array<string, T> $params
86
     * @return array<string, T>
87
     */
88 14
    public static function sortResponseParams(array $params): array
89
    {
90 14
        $order = array_flip(self::RESPONSE_PARAM_ORDER);
91
92 14
        return self::sort($params, $order);
93
    }
94
95
    /**
96
     * @template T
97
     * @param array<string, T>   $params
98
     * @param array<string, int> $order
99
     * @return array<string, T>
100
     */
101 18
    private static function sort(array $params, array $order): array
102
    {
103 18
        $sort = array_replace($order, $params);
104
105
        /**
106
         * @phpstan-ignore-next-line
107
         */
108 18
        return array_intersect_key($sort, $params);
109
    }
110
}
111