Passed
Pull Request — master (#501)
by Songda
03:29
created

DownloadReceiptPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A doSomething() 0 3 1
A getMethod() 0 3 1
A getUri() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Fund\Transfer;
6
7
use Yansongda\Pay\Exception\Exception;
8
use Yansongda\Pay\Exception\InvalidParamsException;
9
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
10
use Yansongda\Pay\Rocket;
11
12
class DownloadReceiptPlugin extends GeneralPlugin
13
{
14
    /**
15
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
16
     */
17
    protected function getUri(Rocket $rocket): string
18
    {
19
        $payload = $rocket->getPayload();
20
21
        if (is_null($payload->get('download_url'))) {
22
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
23
        }
24
25
        return $payload->get('download_url');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $payload->get('download_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...
26
    }
27
28
    protected function getMethod(): string
29
    {
30
        return 'GET';
31
    }
32
33
    protected function doSomething(Rocket $rocket): void
34
    {
35
        $rocket->setPayload(null);
36
    }
37
}
38