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

PosShortcut   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 27
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlugins() 0 9 2
A defaultPlugins() 0 4 1
A preAuthPlugins() 0 4 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\PosNormalPlugin;
11
use Yansongda\Pay\Plugin\Unipay\QrCode\PosPreAuthPlugin;
12
use Yansongda\Supports\Str;
13
14
class PosShortcut implements ShortcutInterface
15
{
16
    /**
17
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
18
     */
19
    public function getPlugins(array $params): array
20
    {
21
        $typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
22
23
        if (method_exists($this, $typeMethod)) {
24
            return $this->{$typeMethod}();
25
        }
26
27
        throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Pos type [$typeMethod] not supported");
28
    }
29
30
    public function defaultPlugins(): array
31
    {
32
        return [
33
            PosNormalPlugin::class,
34
        ];
35
    }
36
37
    public function preAuthPlugins(): array
38
    {
39
        return [
40
            PosPreAuthPlugin::class,
41
        ];
42
    }
43
}
44