Passed
Push — robot ( a5e4d6 )
by mingyoung
03:01
created

Robot   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 3 1
A send() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the mingyoung/dingtalk.
5
 *
6
 * (c) 张铭阳 <[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;
13
14
use Overtrue\Http\Traits\HasHttpRequests;
15
16
class Robot
17
{
18
    use HasHttpRequests;
19
20
    /**
21
     * 机器人 AccessToken
22
     *
23
     * @var string
24
     */
25
    protected $accessToken;
26
27
    /**
28
     * @param string $accessToken
29
     */
30
    public function __construct($accessToken)
31
    {
32
        $this->accessToken = $accessToken;
33
    }
34
35
    /**
36
     * @param string $accessToken
37
     */
38
    public static function create($accessToken)
39
    {
40
        return new static($accessToken);
41
    }
42
43
    /**
44
     * 发送消息
45
     *
46
     * @param array $message
47
     *
48
     * @return array
49
     */
50
    public function send($message)
51
    {
52
        $response = $this->getHttpClient()->request(
53
            'POST', 'https://oapi.dingtalk.com/robot/send?access_token='.$this->accessToken, ['json' => $message]
54
        );
55
56
        return $this->castResponseToType($response);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->castResponseToType($response) returns the type Overtrue\Http\Support\Collection which is incompatible with the documented return type array.
Loading history...
57
    }
58
}
59