QueryShortcut::refundMiniPlugins()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 11
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Shortcut\Wechat;
6
7
use Yansongda\Artful\Contract\ShortcutInterface;
8
use Yansongda\Artful\Exception\InvalidParamsException;
9
use Yansongda\Artful\Plugin\AddPayloadBodyPlugin;
10
use Yansongda\Artful\Plugin\ParserPlugin;
11
use Yansongda\Pay\Exception\Exception;
12
use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin;
13
use Yansongda\Pay\Plugin\Wechat\ResponsePlugin;
14
use Yansongda\Pay\Plugin\Wechat\StartPlugin;
15
use Yansongda\Pay\Plugin\Wechat\V3\AddPayloadSignaturePlugin;
16
use Yansongda\Pay\Plugin\Wechat\V3\Marketing\Transfer\Detail\QueryPlugin as TransferQueryPlugin;
17
use Yansongda\Pay\Plugin\Wechat\V3\Pay\App\QueryPlugin as AppQueryPlugin;
18
use Yansongda\Pay\Plugin\Wechat\V3\Pay\App\QueryRefundPlugin as AppQueryRefundPlugin;
19
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Combine\QueryPlugin as CombineQueryPlugin;
20
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Combine\QueryRefundPlugin as CombineQueryRefundPlugin;
21
use Yansongda\Pay\Plugin\Wechat\V3\Pay\H5\QueryPlugin as H5QueryPlugin;
22
use Yansongda\Pay\Plugin\Wechat\V3\Pay\H5\QueryRefundPlugin as H5QueryRefundPlugin;
23
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Jsapi\QueryPlugin as JsapiQueryPlugin;
24
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Jsapi\QueryRefundPlugin as JsapiQueryRefundPlugin;
25
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Mini\QueryPlugin as MiniQueryPlugin;
26
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Mini\QueryRefundPlugin as MiniQueryRefundPlugin;
27
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Native\QueryPlugin as NativeQueryPlugin;
28
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Native\QueryRefundPlugin as NativeQueryRefundPlugin;
29
use Yansongda\Pay\Plugin\Wechat\V3\VerifySignaturePlugin;
30
use Yansongda\Supports\Str;
31
32
class QueryShortcut implements ShortcutInterface
33
{
34
    /**
35
     * @throws InvalidParamsException
36
     */
37
    public function getPlugins(array $params): array
38
    {
39
        if (isset($params['combine_out_trade_no'])) {
40
            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\Artful\Contrac...Interface::getPlugins() of Yansongda\Artful\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...
41
        }
42
43
        $action = Str::camel($params['_action'] ?? 'default').'Plugins';
44
45
        if (method_exists($this, $action)) {
46
            return $this->{$action}();
47
        }
48
49
        throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Query action [{$action}] not supported");
50
    }
51
52
    protected function defaultPlugins(): array
53
    {
54
        return $this->jsapiPlugins();
55
    }
56
57
    protected function appPlugins(): array
58
    {
59
        return [
60
            StartPlugin::class,
61
            AppQueryPlugin::class,
62
            AddPayloadBodyPlugin::class,
63
            AddPayloadSignaturePlugin::class,
64
            AddRadarPlugin::class,
65
            VerifySignaturePlugin::class,
66
            ResponsePlugin::class,
67
            ParserPlugin::class,
68
        ];
69
    }
70
71
    protected function combinePlugins(): array
72
    {
73
        return [
74
            StartPlugin::class,
75
            CombineQueryPlugin::class,
76
            AddPayloadBodyPlugin::class,
77
            AddPayloadSignaturePlugin::class,
78
            AddRadarPlugin::class,
79
            VerifySignaturePlugin::class,
80
            ResponsePlugin::class,
81
            ParserPlugin::class,
82
        ];
83
    }
84
85
    protected function h5Plugins(): array
86
    {
87
        return [
88
            StartPlugin::class,
89
            H5QueryPlugin::class,
90
            AddPayloadBodyPlugin::class,
91
            AddPayloadSignaturePlugin::class,
92
            AddRadarPlugin::class,
93
            VerifySignaturePlugin::class,
94
            ResponsePlugin::class,
95
            ParserPlugin::class,
96
        ];
97
    }
98
99
    protected function jsapiPlugins(): array
100
    {
101
        return [
102
            StartPlugin::class,
103
            JsapiQueryPlugin::class,
104
            AddPayloadBodyPlugin::class,
105
            AddPayloadSignaturePlugin::class,
106
            AddRadarPlugin::class,
107
            VerifySignaturePlugin::class,
108
            ResponsePlugin::class,
109
            ParserPlugin::class,
110
        ];
111
    }
112
113
    protected function miniPlugins(): array
114
    {
115
        return [
116
            StartPlugin::class,
117
            MiniQueryPlugin::class,
118
            AddPayloadBodyPlugin::class,
119
            AddPayloadSignaturePlugin::class,
120
            AddRadarPlugin::class,
121
            VerifySignaturePlugin::class,
122
            ResponsePlugin::class,
123
            ParserPlugin::class,
124
        ];
125
    }
126
127
    protected function nativePlugins(): array
128
    {
129
        return [
130
            StartPlugin::class,
131
            NativeQueryPlugin::class,
132
            AddPayloadBodyPlugin::class,
133
            AddPayloadSignaturePlugin::class,
134
            AddRadarPlugin::class,
135
            VerifySignaturePlugin::class,
136
            ResponsePlugin::class,
137
            ParserPlugin::class,
138
        ];
139
    }
140
141
    protected function refundPlugins(): array
142
    {
143
        return $this->refundJsapiPlugins();
144
    }
145
146
    protected function refundAppPlugins(): array
147
    {
148
        return [
149
            StartPlugin::class,
150
            AppQueryRefundPlugin::class,
151
            AddPayloadBodyPlugin::class,
152
            AddPayloadSignaturePlugin::class,
153
            AddRadarPlugin::class,
154
            VerifySignaturePlugin::class,
155
            ResponsePlugin::class,
156
            ParserPlugin::class,
157
        ];
158
    }
159
160
    protected function refundCombinePlugins(): array
161
    {
162
        return [
163
            StartPlugin::class,
164
            CombineQueryRefundPlugin::class,
165
            AddPayloadBodyPlugin::class,
166
            AddPayloadSignaturePlugin::class,
167
            AddRadarPlugin::class,
168
            VerifySignaturePlugin::class,
169
            ResponsePlugin::class,
170
            ParserPlugin::class,
171
        ];
172
    }
173
174
    protected function refundH5Plugins(): array
175
    {
176
        return [
177
            StartPlugin::class,
178
            H5QueryRefundPlugin::class,
179
            AddPayloadBodyPlugin::class,
180
            AddPayloadSignaturePlugin::class,
181
            AddRadarPlugin::class,
182
            VerifySignaturePlugin::class,
183
            ResponsePlugin::class,
184
            ParserPlugin::class,
185
        ];
186
    }
187
188
    protected function refundJsapiPlugins(): array
189
    {
190
        return [
191
            StartPlugin::class,
192
            JsapiQueryRefundPlugin::class,
193
            AddPayloadBodyPlugin::class,
194
            AddPayloadSignaturePlugin::class,
195
            AddRadarPlugin::class,
196
            VerifySignaturePlugin::class,
197
            ResponsePlugin::class,
198
            ParserPlugin::class,
199
        ];
200
    }
201
202
    protected function refundMiniPlugins(): array
203
    {
204
        return [
205
            StartPlugin::class,
206
            MiniQueryRefundPlugin::class,
207
            AddPayloadBodyPlugin::class,
208
            AddPayloadSignaturePlugin::class,
209
            AddRadarPlugin::class,
210
            VerifySignaturePlugin::class,
211
            ResponsePlugin::class,
212
            ParserPlugin::class,
213
        ];
214
    }
215
216
    protected function refundNativePlugins(): array
217
    {
218
        return [
219
            StartPlugin::class,
220
            NativeQueryRefundPlugin::class,
221
            AddPayloadBodyPlugin::class,
222
            AddPayloadSignaturePlugin::class,
223
            AddRadarPlugin::class,
224
            VerifySignaturePlugin::class,
225
            ResponsePlugin::class,
226
            ParserPlugin::class,
227
        ];
228
    }
229
230
    protected function transferPlugins(): array
231
    {
232
        return [
233
            StartPlugin::class,
234
            TransferQueryPlugin::class,
235
            AddPayloadBodyPlugin::class,
236
            AddPayloadSignaturePlugin::class,
237
            AddRadarPlugin::class,
238
            VerifySignaturePlugin::class,
239
            ResponsePlugin::class,
240
            ParserPlugin::class,
241
        ];
242
    }
243
}
244