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

CancelShortcut   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 qrCodePlugins() 0 4 1
A defaultPlugins() 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\OnlineGateway\CancelPlugin;
11
use Yansongda\Supports\Str;
12
13
class CancelShortcut 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, "Cancel type [$typeMethod] not supported");
27
    }
28
29
    public function defaultPlugins(): array
30
    {
31
        return [
32
            CancelPlugin::class,
33
        ];
34
    }
35
36
    public function qrCodePlugins(): array
37
    {
38
        return [
39
            \Yansongda\Pay\Plugin\Unipay\QrCode\CancelPlugin::class,
40
        ];
41
    }
42
}
43