Passed
Push — master ( 2729ea...b493c9 )
by Songda
02:00
created

DownloadMediaPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 26
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A doSomething() 0 5 1
A getUri() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Risk\Complaints;
6
7
use Yansongda\Pay\Exception\Exception;
8
use Yansongda\Pay\Exception\InvalidParamsException;
9
use Yansongda\Pay\Parser\OriginResponseParser;
10
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
11
use Yansongda\Pay\Rocket;
12
13
/**
14
 * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_18.shtml
15
 */
16
class DownloadMediaPlugin extends GeneralPlugin
17
{
18
    /**
19
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
20
     */
21
    protected function getUri(Rocket $rocket): string
22
    {
23
        $payload = $rocket->getPayload();
24
25
        if (is_null($payload->get('media_url'))) {
26
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
27
        }
28
29
        return $payload->get('media_url');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $payload->get('media_url') could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
30
    }
31
32
    protected function getMethod(): string
33
    {
34
        return 'GET';
35
    }
36
37
    protected function doSomething(Rocket $rocket): void
38
    {
39
        $rocket->setDirection(OriginResponseParser::class);
40
41
        $rocket->setPayload(null);
42
    }
43
}
44