Completed
Push — master ( 3859e4...8b8edb )
by
unknown
03:04
created

WebhookMessage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 137
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 4 1
A query() 0 6 1
A data() 0 6 1
A header() 0 6 1
A userAgent() 0 6 1
A verify() 0 6 1
A toArray() 0 9 1
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
    /**
22
     * The headers to send with the request.
23
     *
24
     * @var array|null
25
     */
26
    protected $headers;
27
28
    /**
29
     * The user agent header.
30
     *
31
     * @var string|null
32
     */
33
    protected $userAgent;
34
35
    /**
36
     * The Guzzle verify option.
37
     *
38
     * @var bool|string
39
     */
40
    protected $verify = false;
41
42
    /**
43
     * @param mixed $data
44
     *
45
     * @return static
46
     */
47 1
    public static function create($data = '')
48
    {
49 1
        return new static($data);
50
    }
51
52
    /**
53
     * @param mixed $data
54
     */
55 11
    public function __construct($data = '')
56
    {
57 11
        $this->data = $data;
58 11
    }
59
60
    /**
61
     * Set the Webhook parameters to be URL encoded.
62
     *
63
     * @param mixed $query
64
     *
65
     * @return $this
66
     */
67 2
    public function query($query)
68
    {
69 2
        $this->query = $query;
70
71 2
        return $this;
72
    }
73
74
    /**
75
     * Set the Webhook data to be JSON encoded.
76
     *
77
     * @param mixed $data
78
     *
79
     * @return $this
80
     */
81 1
    public function data($data)
82
    {
83 1
        $this->data = $data;
84
85 1
        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 5
    public function header($name, $value)
97
    {
98 5
        $this->headers[$name] = $value;
99
100 5
        return $this;
101
    }
102
103
    /**
104
     * Set the Webhook request UserAgent.
105
     *
106
     * @param string $userAgent
107
     *
108
     * @return $this
109
     */
110 5
    public function userAgent($userAgent)
111
    {
112 5
        $this->headers['User-Agent'] = $userAgent;
113
114 5
        return $this;
115
    }
116
117
    /**
118
     * Indicate that the request should be verified.
119
     *
120
     * @return $this
121
     */
122 1
    public function verify($value = true)
123
    {
124 1
        $this->verify = $value;
125
126 1
        return $this;
127
    }
128
129
    /**
130
     * @return array
131
     */
132 11
    public function toArray()
133
    {
134
        return [
135 11
            'query' => $this->query,
136 11
            'data' => $this->data,
137 11
            'headers' => $this->headers,
138 11
            'verify' => $this->verify,
139
        ];
140
    }
141
}
142