Passed
Pull Request — master (#662)
by Songda
06:50
created

QueryShortcut::getPlugins()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Unipay\Shortcut;
6
7
use Yansongda\Pay\Contract\ShortcutInterface;
8
use Yansongda\Pay\Exception\Exception;
9
use Yansongda\Pay\Exception\InvalidParamsException;
10
use Yansongda\Pay\Plugin\Unipay\OnlineGateway\QueryPlugin;
11
use Yansongda\Supports\Str;
12
13
class QueryShortcut implements ShortcutInterface
14
{
15
    /**
16
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
17
     */
18
    public function getPlugins(array $params): array
19
    {
20
        $typeMethod = Str::studly($params['_type'] ?? 'default').'Plugins';
21
22
        if (method_exists($this, $typeMethod)) {
23
            return $this->{$typeMethod}();
24
        }
25
26
        throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Query type [$typeMethod] not supported");
27
    }
28
29
    public function defaultPlugins(): array
30
    {
31
        return [
32
            QueryPlugin::class,
33
        ];
34
    }
35
36
    protected function qrCodePlugins(): array
37
    {
38
        return [
39
            \Yansongda\Pay\Plugin\Unipay\QrCode\QueryPlugin::class,
40
        ];
41
    }
42
}
43