Issues (1482)

src/service/dingdanxia/DingDanXiaService.php (1 issue)

1
<?php
2
3
namespace DtApp\ThinkLibrary\service\dingdanxia;
4
5
use DtApp\ThinkLibrary\exception\DtaException;
6
use DtApp\ThinkLibrary\Service;
7
use DtApp\ThinkLibrary\service\curl\HttpService;
8
use think\exception\HttpException;
9
10
/**
11
 * 订单侠开放平台
12
 * Class DingDanXiaService
13
 * @package DtApp\ThinkLibrary\service\dingdanxia
14
 */
15
class DingDanXiaService extends Service
16
{
17
    /**
18
     * 接口秘钥
19
     * @var string
20
     */
21
    private $app_key;
22
23
    /**
24
     * API接口
25
     * @var string
26
     */
27
    private $method;
28
29
    /**
30
     * 需要发送的的参数
31
     * @var
32
     */
33
    private $param;
34
35
    /**
36
     * 响应内容
37
     * @var
38
     */
39
    private $output;
40
41
    /**
42
     * 接口秘钥,请登录后台获取
43
     * @param string $appKey
44
     * @return $this
45
     */
46
    public function appKey(string $appKey): self
47
    {
48
        $this->app_key = $appKey;
49
        return $this;
50
    }
51
52
    /**
53
     * 自定义接口
54
     * @param string $method
55
     * @return $this
56
     */
57
    public function setMethod($method = ''): self
58
    {
59
        $this->method = $method;
60
        return $this;
61
    }
62
63
    /**
64
     * 请求参数
65
     * @param array $param
66
     * @return $this
67
     */
68
    public function param(array $param): self
69
    {
70
        $this->param = $param;
71
        return $this;
72
    }
73
74
    /**
75
     * 获取配置信息
76
     * @return $this
77
     */
78
    private function getConfig(): self
79
    {
80
        $this->app_key = config('dtapp.dingdanxia.app_key');
0 ignored issues
show
Documentation Bug introduced by
It seems like config('dtapp.dingdanxia.app_key') can also be of type boolean. However, the property $app_key is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
81
        return $this;
82
    }
83
84
    /**
85
     * 返回Array
86
     * @return array|mixed
87
     * @throws DtaException
88
     */
89
    public function toArray()
90
    {
91
        //首先检测是否支持curl
92
        if (!extension_loaded("curl")) {
93
            throw new HttpException(404, '请开启curl模块!');
94
        }
95
        if (empty($this->app_key)) {
96
            $this->getConfig();
97
        }
98
        if (empty($this->method)) {
99
            throw new DtaException('请检查接口');
100
        }
101
        $this->output = HttpService::instance()
102
            ->url($this->method)
103
            ->data($this->param)
104
            ->post()
105
            ->toArray();
106
        return $this->output;
107
    }
108
}