Passed
Push — develop ( 176838...c67b25 )
by mingyoung
01:40
created

AsyncClient::ofAgent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the mingyoung/dingtalk.
5
 *
6
 * (c) mingyoung <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyDingTalk\Message;
13
14
use EasyDingTalk\Kernel\BaseClient;
15
use EasyDingTalk\Kernel\Messages\Message;
16
17
/**
18
 * Class AsyncClient.
19
 *
20
 * @author mingyoung <[email protected]>
21
 */
22
class AsyncClient extends BaseClient
23
{
24
    /**
25
     * @var array
26
     */
27
    protected $data = [];
28
29
    /**
30
     * @param int $agentId
31
     * @param int $taskId
32
     *
33
     * @return array
34
     */
35
    public function progress(int $agentId, int $taskId)
36
    {
37
        return $this->httpGetMethod('dingtalk.corp.message.corpconversation.getsendprogress', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->httpGetMet... 'task_id' => $taskId)) also could return the type GuzzleHttp\Psr7\Response which is incompatible with the documented return type array.
Loading history...
38
            'agent_id' => $agentId,
39
            'task_id' => $taskId,
40
        ]);
41
    }
42
43
    /**
44
     * @param int $agentId
45
     * @param int $taskId
46
     *
47
     * @return array
48
     */
49
    public function result(int $agentId, int $taskId)
50
    {
51
        return $this->httpGetMethod('dingtalk.corp.message.corpconversation.getsendresult', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->httpGetMet... 'task_id' => $taskId)) also could return the type GuzzleHttp\Psr7\Response which is incompatible with the documented return type array.
Loading history...
52
            'agent_id' => $agentId,
53
            'task_id' => $taskId,
54
        ]);
55
    }
56
57
    /**
58
     * @param array|null $data
59
     *
60
     * @return array
61
     */
62
    public function send(array $data = null)
63
    {
64
        return $this->httpGetMethod('dingtalk.corp.message.corpconversation.asyncsend', $data ?? $this->data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->httpGetMet..., $data ?? $this->data) also could return the type GuzzleHttp\Psr7\Response which is incompatible with the documented return type array.
Loading history...
65
    }
66
67
    /**
68
     * @param $message
69
     *
70
     * @return $this
71
     */
72
    public function withReply($message)
73
    {
74
        $message = Message::parse($message);
75
76
        $this->data['msgtype'] = $message->type();
77
        $this->data['msgcontent'] = json_encode($message->body());
78
79
        return $this;
80
    }
81
82
    /**
83
     * @param string|array $user
84
     *
85
     * @return $this
86
     */
87
    public function toUser($user)
88
    {
89
        $this->data['userid_list'] = implode('|', (array) $user);
90
91
        return $this;
92
    }
93
94
    /**
95
     * @param string|array $party
96
     *
97
     * @return $this
98
     */
99
    public function toParty($party)
100
    {
101
        $this->data['dept_id_list'] = implode('|', (array) $party);
102
103
        return $this;
104
    }
105
106
    /**
107
     * @param int $agent
108
     *
109
     * @return $this
110
     */
111
    public function ofAgent(int $agent)
112
    {
113
        $this->data['agent_id'] = $agent;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return $this
120
     */
121
    public function toAll()
122
    {
123
        $this->data['to_all_user'] = 'true';
124
125
        return $this;
126
    }
127
}
128