Completed
Pull Request — master (#13)
by Kyle
07:02
created

WebhookMessage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\Webhook;
4
5
class WebhookMessage
6
{
7
    /** @var mixed */
8
    protected $data;
9
10
    /** @var array|null */
11
    protected $headers;
12
13
    /** @var string|null */
14
    protected $userAgent;
15
16
    /**
17
     * @param mixed $data
18
     *
19
     * @return static
20
     */
21
    public static function create($data = '')
22
    {
23
        return new static($data);
24
    }
25
26
    /**
27
     * @param mixed $data
28
     */
29
    public function __construct($data = '')
30
    {
31
        $this->data = $data;
32
    }
33
34
    /**
35
     * Set the Webhook data to be JSON encoded.
36
     *
37
     * @param mixed $data
38
     *
39
     * @return $this
40
     */
41
    public function data($data)
42
    {
43
        $this->data = $data;
44
45
        return $this;
46
    }
47
48
    /**
49
     * Add a Webhook request custom header.
50
     *
51
     * @param string $name
52
     * @param string $value
53
     *
54
     * @return $this
55
     */
56
    public function header($name, $value)
57
    {
58
        $this->headers[$name] = $value;
59
60
        return $this;
61
    }
62
63
    /**
64
     * Set the Webhook request UserAgent.
65
     *
66
     * @param string $userAgent
67
     *
68
     * @return $this
69
     */
70
    public function userAgent($userAgent)
71
    {
72
        $this->headers['User-Agent'] = $userAgent;
73
74
        return $this;
75
    }
76
77
    /**
78
     * @return array
79
     */
80
    public function toArray()
81
    {
82
        return [
83
            'data' => $this->data,
84
            'headers' => $this->headers,
85
        ];
86
    }
87
}
88