Passed
Pull Request — master (#773)
by Songda
02:17 queued 31s
created

PapayShortcut   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlugins() 0 8 1
A getInvoke() 0 11 3
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\Plugin\ParserPlugin;
9
use Yansongda\Pay\Plugin\Wechat\Papay\ContractOrderPlugin;
10
use Yansongda\Pay\Plugin\Wechat\Pay\Common\InvokePrepayV2Plugin;
11
use Yansongda\Pay\Plugin\Wechat\PreparePlugin;
12
use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin;
13
14
/**
15
 * 支付中签约.
16
 *
17
 * @see https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_5.shtml
18
 */
19
class PapayShortcut implements ShortcutInterface
20
{
21
    public function getPlugins(array $params): array
22
    {
23
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array(Yansongda\P...in\ParserPlugin::class) 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...
24
            PreparePlugin::class,
25
            ContractOrderPlugin::class,
26
            RadarSignPlugin::class,
27
            $this->getInvoke($params),
28
            ParserPlugin::class,
29
        ];
30
    }
31
32
    protected function getInvoke(array $params): string
33
    {
34
        switch ($params['_type'] ?? 'default') {
35
            case 'app':
36
                return \Yansongda\Pay\Plugin\Wechat\Pay\App\InvokePrepayV2Plugin::class;
37
38
            case 'mini':
39
                return \Yansongda\Pay\Plugin\Wechat\Pay\Mini\InvokePrepayV2Plugin::class;
40
41
            default:
42
                return InvokePrepayV2Plugin::class;
43
        }
44
    }
45
}
46