Completed
Pull Request — master (#19)
by Adam
12:29 queued 08:49
created

WebhookMessage::header()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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 1
    public static function create($data = '')
22
    {
23 1
        return new static($data);
24
    }
25
26
    /**
27
     * @param mixed $data
28
     */
29 8
    public function __construct($data = '')
30
    {
31 8
        $this->data = $data;
32 8
    }
33
34
    /**
35
     * Set the Webhook data to be JSON encoded.
36
     *
37
     * @param mixed $data
38
     *
39
     * @return $this
40
     */
41 1
    public function data($data)
42
    {
43 1
        $this->data = $data;
44
45 1
        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 4
    public function header($name, $value)
57
    {
58 4
        $this->headers[$name] = $value;
59
60 4
        return $this;
61
    }
62
63
    /**
64
     * Set the Webhook request UserAgent.
65
     *
66
     * @param string $userAgent
67
     *
68
     * @return $this
69
     */
70 4
    public function userAgent($userAgent)
71
    {
72 4
        $this->headers['User-Agent'] = $userAgent;
73
74 4
        return $this;
75
    }
76
77
    /**
78
     * @return array
79
     */
80 8
    public function toArray()
81
    {
82
        return [
83 8
            'data' => $this->data,
84 8
            'headers' => $this->headers,
85
        ];
86
    }
87
}
88