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

QueryShortcut::getPlugins()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 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\QueryPlugin;
13
use Yansongda\Pay\Plugin\Unipay\PreparePlugin;
14
use Yansongda\Pay\Plugin\Unipay\RadarSignPlugin;
15
use Yansongda\Supports\Str;
16
17
class QueryShortcut 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, "Query action [{$typeMethod}] not supported");
31
    }
32
33
    protected function defaultPlugins(): array
34
    {
35
        return [
36
            PreparePlugin::class,
37
            QueryPlugin::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\QueryPlugin::class,
49
            RadarSignPlugin::class,
50
            LaunchPlugin::class,
51
            ParserPlugin::class,
52
        ];
53
    }
54
}
55