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

Client::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 Client.
19
 *
20
 * @author mingyoung <[email protected]>
21
 */
22
class Client extends BaseClient
23
{
24
    /**
25
     * @var array
26
     */
27
    protected $data = [];
28
29
    /**
30
     * @param string $messageId
31
     *
32
     * @return array
33
     */
34
    public function status(string $messageId)
35
    {
36
        return $this->httpPostJson('message/list_message_status', compact('messageId'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->httpPostJs..., compact('messageId')) also could return the type GuzzleHttp\Psr7\Response which is incompatible with the documented return type array.
Loading history...
37
    }
38
39
    /**
40
     * @param array|null $data
41
     *
42
     * @return array
43
     */
44
    public function send(array $data = null)
45
    {
46
        return $this->httpPostJson('message/send', $data ?? $this->data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->httpPostJs..., $data ?? $this->data) also could return the type GuzzleHttp\Psr7\Response which is incompatible with the documented return type array.
Loading history...
47
    }
48
49
    /**
50
     * @param string|array $user
51
     *
52
     * @return $this
53
     */
54
    public function toUser($user)
55
    {
56
        $this->data['touser'] = implode('|', (array) $user);
57
58
        return $this;
59
    }
60
61
    /**
62
     * @param string|array $party
63
     *
64
     * @return $this
65
     */
66
    public function toParty($party)
67
    {
68
        $this->data['toparty'] = implode('|', (array) $party);
69
70
        return $this;
71
    }
72
73
    /**
74
     * @param int $agent
75
     *
76
     * @return $this
77
     */
78
    public function ofAgent(int $agent)
79
    {
80
        $this->data['agentid'] = $agent;
81
82
        return $this;
83
    }
84
85
    /**
86
     * @param $message
87
     *
88
     * @return $this
89
     */
90
    public function withReply($message)
91
    {
92
        $this->data += Message::parse($message)->transform();
93
94
        return $this;
95
    }
96
}
97