Passed
Push — master ( 39227b...013b57 )
by Songda
02:46 queued 52s
created

QueryShortcut::refundH5Plugins()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Shortcut\Alipay;
6
7
use Yansongda\Artful\Contract\ShortcutInterface;
8
use Yansongda\Artful\Exception\InvalidParamsException;
9
use Yansongda\Artful\Plugin\ParserPlugin;
10
use Yansongda\Pay\Exception\Exception;
11
use Yansongda\Pay\Plugin\Alipay\V2\AddPayloadSignaturePlugin;
12
use Yansongda\Pay\Plugin\Alipay\V2\AddRadarPlugin;
13
use Yansongda\Pay\Plugin\Alipay\V2\FormatPayloadBizContentPlugin;
14
use Yansongda\Pay\Plugin\Alipay\V2\Fund\Transfer\QueryPlugin as TransferQueryPlugin;
15
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Agreement\QueryPlugin as AgreementQueryPlugin;
16
use Yansongda\Pay\Plugin\Alipay\V2\Pay\App\QueryPlugin as AppQueryPlugin;
17
use Yansongda\Pay\Plugin\Alipay\V2\Pay\App\QueryRefundPlugin as AppQueryRefundPlugin;
18
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Authorization\QueryPlugin as AuthorizationQueryPlugin;
19
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Authorization\QueryRefundPlugin as AuthorizationQueryRefundPlugin;
20
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Face\QueryPlugin as FaceQueryPlugin;
21
use Yansongda\Pay\Plugin\Alipay\V2\Pay\H5\QueryPlugin as H5QueryPlugin;
22
use Yansongda\Pay\Plugin\Alipay\V2\Pay\H5\QueryRefundPlugin as H5QueryRefundPlugin;
23
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Mini\QueryPlugin as MiniQueryPlugin;
24
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Mini\QueryRefundPlugin as MiniQueryRefundPlugin;
25
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Pos\QueryPlugin as PosQueryPlugin;
26
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Pos\QueryRefundPlugin as PosQueryRefundPlugin;
27
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Scan\QueryPlugin as ScanQueryPlugin;
28
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Scan\QueryRefundPlugin as ScanQueryRefundPlugin;
29
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Web\QueryPlugin as WebQueryPlugin;
30
use Yansongda\Pay\Plugin\Alipay\V2\Pay\Web\QueryRefundPlugin as WebQueryRefundPlugin;
31
use Yansongda\Pay\Plugin\Alipay\V2\ResponsePlugin;
32
use Yansongda\Pay\Plugin\Alipay\V2\StartPlugin;
33
use Yansongda\Pay\Plugin\Alipay\V2\VerifySignaturePlugin;
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\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...
47
        }
48
49
        if (method_exists($this, $method)) {
50
            return $this->{$method}();
51
        }
52
53
        throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Query action [{$method}] not supported");
54
    }
55
56
    protected function defaultPlugins(): array
57
    {
58
        return $this->webPlugins();
59
    }
60
61
    protected function agreementPlugins(): array
62
    {
63
        return [
64
            StartPlugin::class,
65
            AgreementQueryPlugin::class,
66
            FormatPayloadBizContentPlugin::class,
67
            AddPayloadSignaturePlugin::class,
68
            AddRadarPlugin::class,
69
            VerifySignaturePlugin::class,
70
            ResponsePlugin::class,
71
            ParserPlugin::class,
72
        ];
73
    }
74
75
    protected function appPlugins(): array
76
    {
77
        return [
78
            StartPlugin::class,
79
            AppQueryPlugin::class,
80
            FormatPayloadBizContentPlugin::class,
81
            AddPayloadSignaturePlugin::class,
82
            AddRadarPlugin::class,
83
            VerifySignaturePlugin::class,
84
            ResponsePlugin::class,
85
            ParserPlugin::class,
86
        ];
87
    }
88
89
    protected function authorizationPlugins(): array
90
    {
91
        return [
92
            StartPlugin::class,
93
            AuthorizationQueryPlugin::class,
94
            FormatPayloadBizContentPlugin::class,
95
            AddPayloadSignaturePlugin::class,
96
            AddRadarPlugin::class,
97
            VerifySignaturePlugin::class,
98
            ResponsePlugin::class,
99
            ParserPlugin::class,
100
        ];
101
    }
102
103
    protected function facePlugins(): array
104
    {
105
        return [
106
            StartPlugin::class,
107
            FaceQueryPlugin::class,
108
            FormatPayloadBizContentPlugin::class,
109
            AddPayloadSignaturePlugin::class,
110
            AddRadarPlugin::class,
111
            VerifySignaturePlugin::class,
112
            ResponsePlugin::class,
113
            ParserPlugin::class,
114
        ];
115
    }
116
117
    protected function miniPlugins(): array
118
    {
119
        return [
120
            StartPlugin::class,
121
            MiniQueryPlugin::class,
122
            FormatPayloadBizContentPlugin::class,
123
            AddPayloadSignaturePlugin::class,
124
            AddRadarPlugin::class,
125
            VerifySignaturePlugin::class,
126
            ResponsePlugin::class,
127
            ParserPlugin::class,
128
        ];
129
    }
130
131
    protected function posPlugins(): array
132
    {
133
        return [
134
            StartPlugin::class,
135
            PosQueryPlugin::class,
136
            FormatPayloadBizContentPlugin::class,
137
            AddPayloadSignaturePlugin::class,
138
            AddRadarPlugin::class,
139
            VerifySignaturePlugin::class,
140
            ResponsePlugin::class,
141
            ParserPlugin::class,
142
        ];
143
    }
144
145
    protected function scanPlugins(): array
146
    {
147
        return [
148
            StartPlugin::class,
149
            ScanQueryPlugin::class,
150
            FormatPayloadBizContentPlugin::class,
151
            AddPayloadSignaturePlugin::class,
152
            AddRadarPlugin::class,
153
            VerifySignaturePlugin::class,
154
            ResponsePlugin::class,
155
            ParserPlugin::class,
156
        ];
157
    }
158
159
    protected function h5Plugins(): array
160
    {
161
        return [
162
            StartPlugin::class,
163
            H5QueryPlugin::class,
164
            FormatPayloadBizContentPlugin::class,
165
            AddPayloadSignaturePlugin::class,
166
            AddRadarPlugin::class,
167
            VerifySignaturePlugin::class,
168
            ResponsePlugin::class,
169
            ParserPlugin::class,
170
        ];
171
    }
172
173
    protected function webPlugins(): array
174
    {
175
        return [
176
            StartPlugin::class,
177
            WebQueryPlugin::class,
178
            FormatPayloadBizContentPlugin::class,
179
            AddPayloadSignaturePlugin::class,
180
            AddRadarPlugin::class,
181
            VerifySignaturePlugin::class,
182
            ResponsePlugin::class,
183
            ParserPlugin::class,
184
        ];
185
    }
186
187
    protected function transferPlugins(): array
188
    {
189
        return [
190
            StartPlugin::class,
191
            TransferQueryPlugin::class,
192
            FormatPayloadBizContentPlugin::class,
193
            AddPayloadSignaturePlugin::class,
194
            AddRadarPlugin::class,
195
            VerifySignaturePlugin::class,
196
            ResponsePlugin::class,
197
            ParserPlugin::class,
198
        ];
199
    }
200
201
    protected function refundPlugins(): array
202
    {
203
        return $this->refundWebPlugins();
204
    }
205
206
    protected function refundAppPlugins(): array
207
    {
208
        return [
209
            StartPlugin::class,
210
            AppQueryRefundPlugin::class,
211
            FormatPayloadBizContentPlugin::class,
212
            AddPayloadSignaturePlugin::class,
213
            AddRadarPlugin::class,
214
            VerifySignaturePlugin::class,
215
            ResponsePlugin::class,
216
            ParserPlugin::class,
217
        ];
218
    }
219
220
    protected function refundAuthorizationPlugins(): array
221
    {
222
        return [
223
            StartPlugin::class,
224
            AuthorizationQueryRefundPlugin::class,
225
            FormatPayloadBizContentPlugin::class,
226
            AddPayloadSignaturePlugin::class,
227
            AddRadarPlugin::class,
228
            VerifySignaturePlugin::class,
229
            ResponsePlugin::class,
230
            ParserPlugin::class,
231
        ];
232
    }
233
234
    protected function refundMiniPlugins(): array
235
    {
236
        return [
237
            StartPlugin::class,
238
            MiniQueryRefundPlugin::class,
239
            FormatPayloadBizContentPlugin::class,
240
            AddPayloadSignaturePlugin::class,
241
            AddRadarPlugin::class,
242
            VerifySignaturePlugin::class,
243
            ResponsePlugin::class,
244
            ParserPlugin::class,
245
        ];
246
    }
247
248
    protected function refundPosPlugins(): array
249
    {
250
        return [
251
            StartPlugin::class,
252
            PosQueryRefundPlugin::class,
253
            FormatPayloadBizContentPlugin::class,
254
            AddPayloadSignaturePlugin::class,
255
            AddRadarPlugin::class,
256
            VerifySignaturePlugin::class,
257
            ResponsePlugin::class,
258
            ParserPlugin::class,
259
        ];
260
    }
261
262
    protected function refundScanPlugins(): array
263
    {
264
        return [
265
            StartPlugin::class,
266
            ScanQueryRefundPlugin::class,
267
            FormatPayloadBizContentPlugin::class,
268
            AddPayloadSignaturePlugin::class,
269
            AddRadarPlugin::class,
270
            VerifySignaturePlugin::class,
271
            ResponsePlugin::class,
272
            ParserPlugin::class,
273
        ];
274
    }
275
276
    protected function refundH5Plugins(): array
277
    {
278
        return [
279
            StartPlugin::class,
280
            H5QueryRefundPlugin::class,
281
            FormatPayloadBizContentPlugin::class,
282
            AddPayloadSignaturePlugin::class,
283
            AddRadarPlugin::class,
284
            VerifySignaturePlugin::class,
285
            ResponsePlugin::class,
286
            ParserPlugin::class,
287
        ];
288
    }
289
290
    protected function refundWebPlugins(): array
291
    {
292
        return [
293
            StartPlugin::class,
294
            WebQueryRefundPlugin::class,
295
            FormatPayloadBizContentPlugin::class,
296
            AddPayloadSignaturePlugin::class,
297
            AddRadarPlugin::class,
298
            VerifySignaturePlugin::class,
299
            ResponsePlugin::class,
300
            ParserPlugin::class,
301
        ];
302
    }
303
}
304