Passed
Pull Request — master (#662)
by Songda
01:49
created

ScanShortcut::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\QrCode\ScanFeePlugin;
11
use Yansongda\Pay\Plugin\Unipay\QrCode\ScanNormalPlugin;
12
use Yansongda\Pay\Plugin\Unipay\QrCode\ScanPreAuthPlugin;
13
use Yansongda\Pay\Plugin\Unipay\QrCode\ScanPreOrderPlugin;
14
use Yansongda\Supports\Str;
15
16
class ScanShortcut implements ShortcutInterface
17
{
18
    /**
19
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
20
     */
21
    public function getPlugins(array $params): array
22
    {
23
        $typeMethod = Str::studly($params['_type'] ?? 'default').'Plugins';
24
25
        if (method_exists($this, $typeMethod)) {
26
            return $this->{$typeMethod}();
27
        }
28
29
        throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Scan type [$typeMethod] not supported");
30
    }
31
32
    public function defaultPlugins(): array
33
    {
34
        return [
35
            ScanNormalPlugin::class,
36
        ];
37
    }
38
39
    public function preAuthPlugins(): array
40
    {
41
        return [
42
            ScanPreAuthPlugin::class,
43
        ];
44
    }
45
46
    public function preOrderPlugins(): array
47
    {
48
        return [
49
            ScanPreOrderPlugin::class,
50
        ];
51
    }
52
53
    public function feePlugins(): array
54
    {
55
        return [
56
            ScanFeePlugin::class,
57
        ];
58
    }
59
}
60