Passed
Pull Request — master (#662)
by Songda
02:21
created

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