NotifyLKMessage::sender()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace ApiChef\NotifyLK;
4
5
use Illuminate\Contracts\Support\Arrayable;
6
7
class NotifyLKMessage implements Arrayable
8
{
9
    private $content;
10
    private $to;
11
    private $isUnicode;
12
    private $sender = null;
13
14
    /** @var Contact */
15
    private $contact = null;
16
17 6
    public function content(string $content, bool $isUnicode = false)
18
    {
19 6
        $this->content = $content;
20 6
        $this->isUnicode = $isUnicode;
21
22 6
        return $this;
23
    }
24
25 6
    public function to(string $to)
26
    {
27 6
        $this->to = $to;
28
29 6
        return $this;
30
    }
31
32
    public function sender(string $sender)
33
    {
34
        $this->sender = $sender;
35
36
        return $this;
37
    }
38
39 3
    public function contact(Contact $contact)
40
    {
41 3
        $this->contact = $contact;
42
43 3
        return $this;
44
    }
45
46 6
    public function toArray()
47
    {
48
        $data = [
49 6
            'user_id' => config('notify-lk.credentials.user_id'),
50 6
            'api_key' => config('notify-lk.credentials.api_key'),
51 6
            'sender_id' => $this->sender ?: config('notify-lk.default_sender_id'),
52 6
            'message' => $this->content,
53 6
            'to' => $this->to,
54
        ];
55
56 6
        if ($this->isUnicode) {
57
            $data['type'] = 'unicode';
58
        }
59
60 6
        if ($this->contact !== null) {
61 3
            $data = array_merge($data, $this->contact->toArray());
62
        }
63
64 6
        return $data;
65
    }
66
}
67