Passed
Push — master ( a1bcd2...a1b58e )
by Songda
02:08
created

QueryShortcut::transferBatchId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\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\Wechat\Fund\Transfer\QueryBatchDetailIdPlugin;
11
use Yansongda\Pay\Plugin\Wechat\Fund\Transfer\QueryBatchIdPlugin;
12
use Yansongda\Pay\Plugin\Wechat\Fund\Transfer\QueryBillReceiptPlugin;
13
use Yansongda\Pay\Plugin\Wechat\Fund\Transfer\QueryDetailReceiptPlugin;
14
use Yansongda\Pay\Plugin\Wechat\Fund\Transfer\QueryOutBatchDetailNoPlugin;
15
use Yansongda\Pay\Plugin\Wechat\Fund\Transfer\QueryOutBatchNoPlugin;
16
use Yansongda\Pay\Plugin\Wechat\Pay\Common\FindRefundPlugin;
17
use Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin;
18
19
class QueryShortcut implements ShortcutInterface
20
{
21
    /**
22
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
23
     */
24
    public function getPlugins(array $params): array
25
    {
26
        $typeMethod = ($params['_type'] ?? 'default').'Plugins';
27
28
        if (isset($params['combine_out_trade_no'])) {
29
            return $this->combinePlugins();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->combinePlugins() returns the type array<integer,string> which is incompatible with the return type mandated by Yansongda\Pay\Contract\S...Interface::getPlugins() of Yansongda\Pay\Contract\PluginInterface[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
30
        }
31
32
        if (method_exists($this, $typeMethod)) {
33
            return $this->{$typeMethod}();
34
        }
35
36
        throw new InvalidParamsException(Exception::SHORTCUT_QUERY_TYPE_ERROR, "Query type [$typeMethod] not supported");
37
    }
38
39
    public function transferBatchId(): array
40
    {
41
        return [
42
            QueryBatchIdPlugin::class,
43
        ];
44
    }
45
46
    public function transferBillReceipt(): array
47
    {
48
        return [
49
            QueryBillReceiptPlugin::class,
50
        ];
51
    }
52
53
    public function transferDetailReceipt(): array
54
    {
55
        return [
56
            QueryDetailReceiptPlugin::class,
57
        ];
58
    }
59
60
    public function transferOutBatchDetailNo(): array
61
    {
62
        return [
63
            QueryOutBatchDetailNoPlugin::class,
64
        ];
65
    }
66
67
    public function transferOutBatchNo(): array
68
    {
69
        return [
70
            QueryOutBatchNoPlugin::class,
71
        ];
72
    }
73
74
    protected function defaultPlugins(): array
75
    {
76
        return [
77
            QueryPlugin::class,
78
        ];
79
    }
80
81
    protected function refundPlugins(): array
82
    {
83
        return [
84
            FindRefundPlugin::class,
85
        ];
86
    }
87
88
    protected function combinePlugins(): array
89
    {
90
        return [
91
            \Yansongda\Pay\Plugin\Wechat\Pay\Combine\QueryPlugin::class,
92
        ];
93
    }
94
95
    protected function transferBatchDetailId(): array
96
    {
97
        return [
98
            QueryBatchDetailIdPlugin::class,
99
        ];
100
    }
101
}
102