Passed
Pull Request — master (#913)
by Songda
01:55
created

AddPayloadBodyPlugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 16
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBody() 0 3 1
A assembly() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Unipay;
6
7
use Closure;
8
use Yansongda\Pay\Contract\PluginInterface;
9
use Yansongda\Pay\Logger;
10
use Yansongda\Pay\Rocket;
11
use Yansongda\Supports\Collection;
12
13
use function Yansongda\Pay\filter_params;
14
15
class AddPayloadBodyPlugin implements PluginInterface
16
{
17
    public function assembly(Rocket $rocket, Closure $next): Rocket
18
    {
19
        Logger::debug('[Wechat][AddPayloadBodyPlugin] 插件开始装载', ['rocket' => $rocket]);
20
21
        $rocket->mergePayload(['_body' => $this->getBody($rocket->getPayload())]);
22
23
        Logger::info('[Wechat][AddPayloadBodyPlugin] 插件装载完毕', ['rocket' => $rocket]);
24
25
        return $next($rocket);
26
    }
27
28
    protected function getBody(?Collection $payload): string
29
    {
30
        return Collection::wrap(filter_params($payload->all()))->query();
0 ignored issues
show
Bug introduced by
The method all() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return Collection::wrap(filter_params($payload->/** @scrutinizer ignore-call */ all()))->query();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
    }
32
}
33