Passed
Push — master ( 8e58b4...d1dcd3 )
by Songda
02:46 queued 48s
created

RefundShortcut   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlugins() 0 9 2
A qrCodePlugins() 0 8 1
A defaultPlugins() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Shortcut\Unipay;
6
7
use Yansongda\Pay\Contract\ShortcutInterface;
8
use Yansongda\Pay\Exception\Exception;
9
use Yansongda\Pay\Exception\InvalidParamsException;
10
use Yansongda\Pay\Plugin\ParserPlugin;
11
use Yansongda\Pay\Plugin\Unipay\LaunchPlugin;
12
use Yansongda\Pay\Plugin\Unipay\OnlineGateway\RefundPlugin;
13
use Yansongda\Pay\Plugin\Unipay\PreparePlugin;
14
use Yansongda\Pay\Plugin\Unipay\RadarSignPlugin;
15
use Yansongda\Supports\Str;
16
17
class RefundShortcut implements ShortcutInterface
18
{
19
    /**
20
     * @throws InvalidParamsException
21
     */
22
    public function getPlugins(array $params): array
23
    {
24
        $typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins';
25
26
        if (method_exists($this, $typeMethod)) {
27
            return $this->{$typeMethod}();
28
        }
29
30
        throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Refund action [{$typeMethod}] not supported");
31
    }
32
33
    protected function defaultPlugins(): array
34
    {
35
        return [
36
            PreparePlugin::class,
37
            RefundPlugin::class,
38
            RadarSignPlugin::class,
39
            LaunchPlugin::class,
40
            ParserPlugin::class,
41
        ];
42
    }
43
44
    protected function qrCodePlugins(): array
45
    {
46
        return [
47
            PreparePlugin::class,
48
            \Yansongda\Pay\Plugin\Unipay\QrCode\RefundPlugin::class,
49
            RadarSignPlugin::class,
50
            LaunchPlugin::class,
51
            ParserPlugin::class,
52
        ];
53
    }
54
}
55