Completed
Pull Request — master (#16)
by
unknown
26:15 queued 12:34
created

WebhookMessage::verify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\Webhook;
4
5
class WebhookMessage
6
{
7
    /**
8
     * The GET parameters of the request.
9
     *
10
     * @var array|string|null
11
     */
12
    protected $query;
13
14
    /**
15
     * The POST data of the Webhook request.
16
     *
17
     * @var mixed
18
     */
19
    protected $data;
20
21 1
    /**
22
     * The headers to send with the request.
23 1
     *
24
     * @var array|null
25
     */
26
    protected $headers;
27
28
    /**
29 8
     * The user agent header.
30
     *
31 8
     * @var string|null
32 8
     */
33
    protected $userAgent;
34
35
    /**
36
     * The Guzzle verify option.
37
     *
38
     * @var bool|string
39
     */
40
    protected $verify = false;
41 1
42
    /**
43 1
     * @param mixed $data
44
     *
45 1
     * @return static
46
     */
47
    public static function create($data = '')
48
    {
49
        return new static($data);
50
    }
51
52
    /**
53
     * @param mixed $data
54
     */
55
    public function __construct($data = '')
56 4
    {
57
        $this->data = $data;
58 4
    }
59
60 4
    /**
61
     * Set the Webhook parameters to be URL encoded.
62
     *
63
     * @param mixed $query
64
     *
65
     * @return $this
66
     */
67
    public function query($query)
68
    {
69
        $this->query = $query;
70 4
71
        return $this;
72 4
    }
73
74 4
    /**
75
     * Set the Webhook data to be JSON encoded.
76
     *
77
     * @param mixed $data
78
     *
79
     * @return $this
80 8
     */
81
    public function data($data)
82
    {
83 8
        $this->data = $data;
84 8
85
        return $this;
86
    }
87
88
    /**
89
     * Add a Webhook request custom header.
90
     *
91
     * @param string $name
92
     * @param string $value
93
     *
94
     * @return $this
95
     */
96
    public function header($name, $value)
97
    {
98
        $this->headers[$name] = $value;
99
100
        return $this;
101
    }
102
103
    /**
104
     * Set the Webhook request UserAgent.
105
     *
106
     * @param string $userAgent
107
     *
108
     * @return $this
109
     */
110
    public function userAgent($userAgent)
111
    {
112
        $this->headers['User-Agent'] = $userAgent;
113
114
        return $this;
115
    }
116
117
    /**
118
     * Indicate that the request should be verified.
119
     *
120
     * @return $this
121
     */
122
    public function verify($value = true)
123
    {
124
        $this->verify = $value;
125
126
        return $this;
127
    }
128
129
    /**
130
     * @return array
131
     */
132
    public function toArray()
133
    {
134
        return [
135
            'query' => $this->query,
136
            'data' => $this->data,
137
            'headers' => $this->headers,
138
            'verify' => $this->verify,
139
        ];
140
    }
141
}
142