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

Client::toChat()   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\Chat;
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 array $data
31
     *
32
     * @return array
33
     */
34
    public function create(array $data)
35
    {
36
        return $this->httpPostJson('chat/create', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->httpPostJson('chat/create', $data) 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 $data
41
     *
42
     * @return array
43
     */
44
    public function update(array $data)
45
    {
46
        return $this->httpPostJson('chat/update', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->httpPostJson('chat/update', $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 $chatId
51
     *
52
     * @return array
53
     */
54
    public function get(string $chatId)
55
    {
56
        return $this->httpGet('chat/get', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->httpGet('c...y('chatid' => $chatId)) also could return the type GuzzleHttp\Psr7\Response which is incompatible with the documented return type array.
Loading history...
57
            'chatid' => $chatId,
58
        ]);
59
    }
60
61
    /**
62
     * @param array $data
63
     *
64
     * @return array
65
     */
66
    public function send(array $data = null)
67
    {
68
        return $this->httpPostJson('chat/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...
69
    }
70
71
    /**
72
     * @param string $chatId
73
     *
74
     * @return $this
75
     */
76
    public function toChat(string $chatId)
77
    {
78
        $this->data['chatid'] = $chatId;
79
80
        return $this;
81
    }
82
83
    /**
84
     * @param $message
85
     *
86
     * @return $this
87
     */
88
    public function withReply($message)
89
    {
90
        $this->data += Message::parse($message)->transform();
91
92
        return $this;
93
    }
94
}
95