Passed
Pull Request — master (#662)
by Songda
01:53
created

QueryShortcut::transferBillReceipt()   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\Pay\Common\FindRefundPlugin;
11
use Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin;
12
use Yansongda\Supports\Str;
13
14
class QueryShortcut implements ShortcutInterface
15
{
16
    /**
17
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
18
     */
19
    public function getPlugins(array $params): array
20
    {
21
        if (isset($params['combine_out_trade_no'])) {
22
            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...
23
        }
24
25
        $typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
26
27
        if (method_exists($this, $typeMethod)) {
28
            return $this->{$typeMethod}();
29
        }
30
31
        throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Query type [$typeMethod] not supported");
32
    }
33
34
    protected function defaultPlugins(): array
35
    {
36
        return [
37
            QueryPlugin::class,
38
        ];
39
    }
40
41
    protected function refundPlugins(): array
42
    {
43
        return [
44
            FindRefundPlugin::class,
45
        ];
46
    }
47
48
    protected function combinePlugins(): array
49
    {
50
        return [
51
            \Yansongda\Pay\Plugin\Wechat\Pay\Combine\QueryPlugin::class,
52
        ];
53
    }
54
}
55