Passed
Push — master ( e4a200...c44a4f )
by Songda
03:06 queued 01:11
created

QueryShortcut::refundMiniPlugins()   A

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\Alipay;
6
7
use Yansongda\Pay\Contract\ShortcutInterface;
8
use Yansongda\Pay\Exception\Exception;
9
use Yansongda\Pay\Exception\InvalidParamsException;
10
use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin;
11
use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin;
12
use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin;
13
use Yansongda\Pay\Plugin\Alipay\Fund\Transfer\QueryPlugin as TransferQueryPlugin;
14
use Yansongda\Pay\Plugin\Alipay\Pay\Agreement\QueryPlugin as AgreementQueryPlugin;
15
use Yansongda\Pay\Plugin\Alipay\Pay\App\QueryPlugin as AppQueryPlugin;
16
use Yansongda\Pay\Plugin\Alipay\Pay\App\QueryRefundPlugin as AppQueryRefundPlugin;
17
use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\QueryPlugin as AuthorizationQueryPlugin;
18
use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\QueryRefundPlugin as AuthorizationQueryRefundPlugin;
19
use Yansongda\Pay\Plugin\Alipay\Pay\Face\QueryPlugin as FaceQueryPlugin;
20
use Yansongda\Pay\Plugin\Alipay\Pay\Mini\QueryPlugin as MiniQueryPlugin;
21
use Yansongda\Pay\Plugin\Alipay\Pay\Mini\QueryRefundPlugin as MiniQueryRefundPlugin;
22
use Yansongda\Pay\Plugin\Alipay\Pay\Pos\QueryPlugin as PosQueryPlugin;
23
use Yansongda\Pay\Plugin\Alipay\Pay\Pos\QueryRefundPlugin as PosQueryRefundPlugin;
24
use Yansongda\Pay\Plugin\Alipay\Pay\Scan\QueryPlugin as ScanQueryPlugin;
25
use Yansongda\Pay\Plugin\Alipay\Pay\Scan\QueryRefundPlugin as ScanQueryRefundPlugin;
26
use Yansongda\Pay\Plugin\Alipay\Pay\Wap\QueryPlugin as WapQueryPlugin;
27
use Yansongda\Pay\Plugin\Alipay\Pay\Wap\QueryRefundPlugin as WapQueryRefundPlugin;
28
use Yansongda\Pay\Plugin\Alipay\Pay\Web\QueryPlugin as WebQueryPlugin;
29
use Yansongda\Pay\Plugin\Alipay\Pay\Web\QueryRefundPlugin as WebQueryRefundPlugin;
30
use Yansongda\Pay\Plugin\Alipay\ResponsePlugin;
31
use Yansongda\Pay\Plugin\Alipay\StartPlugin;
32
use Yansongda\Pay\Plugin\Alipay\VerifySignaturePlugin;
33
use Yansongda\Pay\Plugin\ParserPlugin;
34
use Yansongda\Supports\Str;
35
36
class QueryShortcut implements ShortcutInterface
37
{
38
    /**
39
     * @throws InvalidParamsException
40
     */
41
    public function getPlugins(array $params): array
42
    {
43
        $method = Str::camel($params['_action'] ?? 'default').'Plugins';
44
45
        if (isset($params['out_request_no'])) {
46
            return $this->refundPlugins();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->refundPlugins() 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...
47
        }
48
49
        if (method_exists($this, $method)) {
50
            return $this->{$method}();
51
        }
52
53
        throw new InvalidParamsException(Exception::SHORTCUT_MULTI_ACTION_ERROR, "Query action [{$method}] not supported");
54
    }
55
56
    protected function defaultPlugins(): array
57
    {
58
        return [
59
            StartPlugin::class,
60
            WebQueryPlugin::class,
61
            FormatBizContentPlugin::class,
62
            AddSignaturePlugin::class,
63
            AddRadarPlugin::class,
64
            VerifySignaturePlugin::class,
65
            ResponsePlugin::class,
66
            ParserPlugin::class,
67
        ];
68
    }
69
70
    protected function agreementPlugins(): array
71
    {
72
        return [
73
            StartPlugin::class,
74
            AgreementQueryPlugin::class,
75
            FormatBizContentPlugin::class,
76
            AddSignaturePlugin::class,
77
            AddRadarPlugin::class,
78
            VerifySignaturePlugin::class,
79
            ResponsePlugin::class,
80
            ParserPlugin::class,
81
        ];
82
    }
83
84
    protected function appPlugins(): array
85
    {
86
        return [
87
            StartPlugin::class,
88
            AppQueryPlugin::class,
89
            FormatBizContentPlugin::class,
90
            AddSignaturePlugin::class,
91
            AddRadarPlugin::class,
92
            VerifySignaturePlugin::class,
93
            ResponsePlugin::class,
94
            ParserPlugin::class,
95
        ];
96
    }
97
98
    protected function authorizationPlugins(): array
99
    {
100
        return [
101
            StartPlugin::class,
102
            AuthorizationQueryPlugin::class,
103
            FormatBizContentPlugin::class,
104
            AddSignaturePlugin::class,
105
            AddRadarPlugin::class,
106
            VerifySignaturePlugin::class,
107
            ResponsePlugin::class,
108
            ParserPlugin::class,
109
        ];
110
    }
111
112
    protected function facePlugins(): array
113
    {
114
        return [
115
            StartPlugin::class,
116
            FaceQueryPlugin::class,
117
            FormatBizContentPlugin::class,
118
            AddSignaturePlugin::class,
119
            AddRadarPlugin::class,
120
            VerifySignaturePlugin::class,
121
            ResponsePlugin::class,
122
            ParserPlugin::class,
123
        ];
124
    }
125
126
    protected function miniPlugins(): array
127
    {
128
        return [
129
            StartPlugin::class,
130
            MiniQueryPlugin::class,
131
            FormatBizContentPlugin::class,
132
            AddSignaturePlugin::class,
133
            AddRadarPlugin::class,
134
            VerifySignaturePlugin::class,
135
            ResponsePlugin::class,
136
            ParserPlugin::class,
137
        ];
138
    }
139
140
    protected function posPlugins(): array
141
    {
142
        return [
143
            StartPlugin::class,
144
            PosQueryPlugin::class,
145
            FormatBizContentPlugin::class,
146
            AddSignaturePlugin::class,
147
            AddRadarPlugin::class,
148
            VerifySignaturePlugin::class,
149
            ResponsePlugin::class,
150
            ParserPlugin::class,
151
        ];
152
    }
153
154
    protected function scanPlugins(): array
155
    {
156
        return [
157
            StartPlugin::class,
158
            ScanQueryPlugin::class,
159
            FormatBizContentPlugin::class,
160
            AddSignaturePlugin::class,
161
            AddRadarPlugin::class,
162
            VerifySignaturePlugin::class,
163
            ResponsePlugin::class,
164
            ParserPlugin::class,
165
        ];
166
    }
167
168
    protected function wapPlugins(): array
169
    {
170
        return [
171
            StartPlugin::class,
172
            WapQueryPlugin::class,
173
            FormatBizContentPlugin::class,
174
            AddSignaturePlugin::class,
175
            AddRadarPlugin::class,
176
            VerifySignaturePlugin::class,
177
            ResponsePlugin::class,
178
            ParserPlugin::class,
179
        ];
180
    }
181
182
    protected function webPlugins(): array
183
    {
184
        return [
185
            StartPlugin::class,
186
            WebQueryPlugin::class,
187
            FormatBizContentPlugin::class,
188
            AddSignaturePlugin::class,
189
            AddRadarPlugin::class,
190
            VerifySignaturePlugin::class,
191
            ResponsePlugin::class,
192
            ParserPlugin::class,
193
        ];
194
    }
195
196
    protected function transferPlugins(): array
197
    {
198
        return [
199
            StartPlugin::class,
200
            TransferQueryPlugin::class,
201
            FormatBizContentPlugin::class,
202
            AddSignaturePlugin::class,
203
            AddRadarPlugin::class,
204
            VerifySignaturePlugin::class,
205
            ResponsePlugin::class,
206
            ParserPlugin::class,
207
        ];
208
    }
209
210
    protected function refundPlugins(): array
211
    {
212
        return [
213
            StartPlugin::class,
214
            WebQueryRefundPlugin::class,
215
            FormatBizContentPlugin::class,
216
            AddSignaturePlugin::class,
217
            AddRadarPlugin::class,
218
            VerifySignaturePlugin::class,
219
            ResponsePlugin::class,
220
            ParserPlugin::class,
221
        ];
222
    }
223
224
    protected function refundAppPlugins(): array
225
    {
226
        return [
227
            StartPlugin::class,
228
            AppQueryRefundPlugin::class,
229
            FormatBizContentPlugin::class,
230
            AddSignaturePlugin::class,
231
            AddRadarPlugin::class,
232
            VerifySignaturePlugin::class,
233
            ResponsePlugin::class,
234
            ParserPlugin::class,
235
        ];
236
    }
237
238
    protected function refundAuthorizationPlugins(): array
239
    {
240
        return [
241
            StartPlugin::class,
242
            AuthorizationQueryRefundPlugin::class,
243
            FormatBizContentPlugin::class,
244
            AddSignaturePlugin::class,
245
            AddRadarPlugin::class,
246
            VerifySignaturePlugin::class,
247
            ResponsePlugin::class,
248
            ParserPlugin::class,
249
        ];
250
    }
251
252
    protected function refundMiniPlugins(): array
253
    {
254
        return [
255
            StartPlugin::class,
256
            MiniQueryRefundPlugin::class,
257
            FormatBizContentPlugin::class,
258
            AddSignaturePlugin::class,
259
            AddRadarPlugin::class,
260
            VerifySignaturePlugin::class,
261
            ResponsePlugin::class,
262
            ParserPlugin::class,
263
        ];
264
    }
265
266
    protected function refundPosPlugins(): array
267
    {
268
        return [
269
            StartPlugin::class,
270
            PosQueryRefundPlugin::class,
271
            FormatBizContentPlugin::class,
272
            AddSignaturePlugin::class,
273
            AddRadarPlugin::class,
274
            VerifySignaturePlugin::class,
275
            ResponsePlugin::class,
276
            ParserPlugin::class,
277
        ];
278
    }
279
280
    protected function refundScanPlugins(): array
281
    {
282
        return [
283
            StartPlugin::class,
284
            ScanQueryRefundPlugin::class,
285
            FormatBizContentPlugin::class,
286
            AddSignaturePlugin::class,
287
            AddRadarPlugin::class,
288
            VerifySignaturePlugin::class,
289
            ResponsePlugin::class,
290
            ParserPlugin::class,
291
        ];
292
    }
293
294
    protected function refundWapPlugins(): array
295
    {
296
        return [
297
            StartPlugin::class,
298
            WapQueryRefundPlugin::class,
299
            FormatBizContentPlugin::class,
300
            AddSignaturePlugin::class,
301
            AddRadarPlugin::class,
302
            VerifySignaturePlugin::class,
303
            ResponsePlugin::class,
304
            ParserPlugin::class,
305
        ];
306
    }
307
308
    protected function refundWebPlugins(): array
309
    {
310
        return [
311
            StartPlugin::class,
312
            WebQueryRefundPlugin::class,
313
            FormatBizContentPlugin::class,
314
            AddSignaturePlugin::class,
315
            AddRadarPlugin::class,
316
            VerifySignaturePlugin::class,
317
            ResponsePlugin::class,
318
            ParserPlugin::class,
319
        ];
320
    }
321
}
322