ActionCard::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 5
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DingNotice\Messages;
4
5
use DingNotice\DingTalkService;
6
7
class ActionCard extends Message
8
{
9
10
    protected $service;
11
12
    public function __construct(DingTalkService $service,$title, $markdown, $hideAvatar = 0, $btnOrientation = 0)
13
    {
14
        $this->service = $service;
15
        $this->setMessage($title,$markdown,$hideAvatar,$btnOrientation);
16
    }
17
18
    public function setMessage($title, $markdown, $hideAvatar = 0, $btnOrientation = 0){
19
        $this->message = [
20
            'msgtype' => 'actionCard',
21
            'actionCard' => [
22
                'title' => $title,
23
                'text' => $markdown,
24
                'hideAvatar' => $hideAvatar,
25
                'btnOrientation' => $btnOrientation
26
            ]
27
        ];
28
    }
29
30
    public function single($title,$url){
31
        $this->message['actionCard']['singleTitle'] = $title;
32
        $this->message['actionCard']['singleURL'] = $url;
33
        $this->service->setMessage($this);
34
        return $this;
35
    }
36
37
    public function addButtons($title,$url){
38
        $this->message['actionCard']['btns'][] = [
39
            'title' => $title,
40
            'actionURL' => $url
41
        ];
42
        return $this;
43
    }
44
45
    public function send(){
46
        $this->service->setMessage($this);
47
        return $this->service->send();
48
    }
49
50
}