GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 12a2af...2513b2 )
by Tyler
06:16 queued 02:53
created

MonologHandlerFactory::mailgun()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 21

Duplication

Lines 26
Ratio 100 %

Code Coverage

Tests 20
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 26
loc 26
ccs 20
cts 20
cp 1
rs 8.8571
cc 1
eloc 21
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Tylercd100\Notify\Factories;
4
5
use Mail;
6
use Monolog\Logger;
7
use Swift_Message;
8
9
class MonologHandlerFactory
10
{
11
    /**
12
     * Returns an instance of \Monolog\Handler\HandlerInterface
13
     * @param  string $name   Then name of the handler you want to create
14
     * @param  array  $config An array of config values to use
15
     * @param string $title
16
     * @return \Monolog\Handler\HandlerInterface
17
     */
18 39
    public static function create($name, array $config = [], $title = null){
19 39
        return call_user_func([MonologHandlerFactory::class,$name], $config, $title);
20
    }
21
22
    /**
23
     * Returns a PushoverHandler
24
     * @param  array  $config An array of config values to use
25
     * @param  string $title The title/subject to use
26
     * @return \Monolog\Handler\PushoverHandler
27
     */
28 12
    protected static function pushover(array $config = [], $title = null){
29
        $defaults = [
30 9
            "title" => null,
31 9
            "level" => Logger::DEBUG,
32 9
            "bubble" => true,
33 9
            "useSSL" => true,
34 9
            "highPriorityLevel" => Logger::CRITICAL,
35 9
            "emergencyLevel" => Logger::EMERGENCY,
36 9
            "retry" => 30,
37
            "expire" => 25200
38 9
        ];
39
40 9
        $c = array_merge($defaults,$config);
41
42 9
        $c['title'] = $title;
43
44 9
        return new \Monolog\Handler\PushoverHandler(
45 9
            $c['token'],
46 9
            $c['users'],
47 9
            $c['title'],
48 9
            $c['level'],
49 9
            $c['bubble'],
50 9
            $c['useSSL'],
51 9
            $c['highPriorityLevel'],
52 12
            $c['emergencyLevel'],
53 9
            $c['retry'],
54 9
            $c['expire']);
55
    }
56
57
    /**
58
     * Returns a PushoverHandler
59
     * @param  array  $config An array of config values to use
60
     * @param  string $title The title/subject to use
61
     * @return \Tylercd100\Monolog\Handler\MailgunHandler
62
     */
63 6 View Code Duplication
    protected static function mailgun(array $config = [], $title = null){
64
        $defaults = [
65 3
            "title" => null,
66 3
            "level" => Logger::CRITICAL,
67 3
            "bubble" => true,
68 3
            "useSSL" => true,
69 3
            "host" => 'api.mailgun.net',
70
            "version" => 'v3'
71 3
        ];
72
73 3
        $c = array_merge($defaults,$config);
74
75 3
        $c['title'] = $title;
76
77 3
        return new \Tylercd100\Monolog\Handler\MailgunHandler(
78 3
            $c["to"],
79 3
            $c["title"],
80 3
            $c["from"],
81 3
            $c["token"],
82 6
            $c["domain"],
83 3
            $c["level"],
84 3
            $c["bubble"],
85 3
            $c["useSSL"],
86 3
            $c["host"],
87 3
            $c["version"]);
88
    }
89
90
    /**
91
     * Returns a FlowdockHandler
92
     * @param  array  $config An array of config values to use
93
     * @param  string $title The title/subject to use
94
     * @return \Monolog\Handler\FlowdockHandler
95
     */
96 3 View Code Duplication
    protected static function flowdock(array $config = [], $title = null){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
        $defaults = [
98 3
            "level" => Logger::DEBUG,
99 3
            "bubble" => true,
100 3
        ];
101
102 3
        $c = array_merge($defaults,$config);
103
104 3
        return new \Monolog\Handler\FlowdockHandler(
105 3
            $c['token'],
106 3
            $c['level'],
107 3
            $c['bubble']);
108
    }
109
110
    /**
111
     * Returns a FleepHookHandler
112
     * @param  array  $config An array of config values to use
113
     * @param  string $title The title/subject to use
114
     * @return \Monolog\Handler\FleepHookHandler
115
     */
116 3 View Code Duplication
    protected static function fleephook(array $config = [], $title = null){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
        $defaults = [
118 3
            "level" => Logger::DEBUG,
119 3
            "bubble" => true,
120 3
        ];
121
122 3
        $c = array_merge($defaults,$config);
123
124 3
        return new \Monolog\Handler\FleepHookHandler(
125 3
            $c['token'],
126 3
            $c['level'],
127 3
            $c['bubble']);
128
    }
129
130
    /**
131
     * Returns a PlivoHandler
132
     * @param  array  $config An array of config values to use
133
     * @param  string $title The title/subject to use
134
     * @return \Tylercd100\Monolog\Handler\PlivoHandler
135
     */
136 3 View Code Duplication
    protected static function plivo(array $config = [], $title = null){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
        $defaults = [
138 3
            'level' => Logger::DEBUG,
139 3
            'bubble' => true,
140 3
            'useSSL' => true,
141 3
            'host' => 'api.plivo.com',
142 3
            'version' => 'v1',
143 3
            'limit' => 160,
144 3
        ];
145
146 3
        $c = array_merge($defaults,$config);
147
148 3
        return new \Tylercd100\Monolog\Handler\PlivoHandler(
149 3
            $c['token'],
150 3
            $c['auth_id'],
151 3
            $c['from'],
152 3
            $c['to'],
153 3
            $c['level'],
154 3
            $c['bubble'],
155 3
            $c['useSSL'],
156 3
            $c['host'],
157 3
            $c['version'],
158 3
            $c['limit']);
159
    }
160
161
    /**
162
     * Returns a TwilioHandler
163
     * @param  array  $config An array of config values to use
164
     * @param  string $title The title/subject to use
165
     * @return \Tylercd100\Monolog\Handler\TwilioHandler
166
     */
167 3 View Code Duplication
    protected static function twilio(array $config = [], $title = null){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
168
        $defaults = [
169 3
            'level' => Logger::DEBUG,
170 3
            'bubble' => true,
171 3
            'useSSL' => true,
172 3
            'host' => 'api.twilio.com',
173 3
            'version' => '2010-04-01',
174 3
            'limit' => 160,
175 3
        ];
176
177 3
        $c = array_merge($defaults,$config);
178
179 3
        return new \Tylercd100\Monolog\Handler\TwilioHandler(
180 3
            $c['secret'],
181 3
            $c['sid'],
182 3
            $c['from'],
183 3
            $c['to'],
184 3
            $c['level'],
185 3
            $c['bubble'],
186 3
            $c['useSSL'],
187 3
            $c['host'],
188 3
            $c['version'],
189 3
            $c['limit']);
190
    }
191
192
    /**
193
     * Returns a RavenHandler
194
     * @param  array  $config An array of config values to use
195
     * @param  string $title The title/subject to use
196
     * @return \Monolog\Handler\RavenHandler
197
     */
198 3
    protected static function raven(array $config = [], $title = null){
199
        $defaults = [
200 3
            'dsn'    => null,
201 3
            'level'  => Logger::ERROR,
202 3
            'bubble' => true,
203 3
        ];
204
205 3
        $c = array_merge($defaults, $config);
206
207 3
        return new \Monolog\Handler\RavenHandler(
208 3
            new \Raven_Client($c['dsn'], array_except($c, ['dsn'])),
209 3
            $c['level'],
210 3
            $c['bubble']
211 3
        );
212
    }
213
214
    /**
215
     * Returns a SlackHandler
216
     * @param  array  $config An array of config values to use
217
     * @param  string $title The title/subject to use
218
     * @return \Monolog\Handler\SlackHandler
219
     */
220 9
    protected static function slack(array $config = [], $title = null){
221
        $defaults = [
222 9
            'username' => 'Monolog',
223 9
            'useAttachment' => true,
224 9
            'iconEmoji' => null,
225 9
            'level' => Logger::DEBUG,
226 9
            'bubble' => true,
227 9
            'useShortAttachment' => false,
228
            'includeContextAndExtra' => false
229 9
        ];
230
231 9
        $c = array_merge($defaults,$config);
232
233 9
        return new \Monolog\Handler\SlackHandler(
234 9
            $c['token'],
235 9
            $c['channel'],
236 9
            $c['username'],
237 9
            $c['useAttachment'],
238 9
            $c['iconEmoji'],
239 9
            $c['level'],
240 9
            $c['bubble'],
241 9
            $c['useShortAttachment'],
242 9
            $c['includeContextAndExtra']);
243
    }
244
245
    /**
246
     * Returns a HipChatHandler
247
     * @param  array  $config An array of config values to use
248
     * @param  string $title The title/subject to use
249
     * @return \Monolog\Handler\HipChatHandler
250
     */
251 9
    protected static function hipchat(array $config = [], $title = null){
252
        $defaults = [
253 9
            'name'    => 'Monolog',
254 9
            'notify'  => false,
255 9
            'level'   => Logger::DEBUG,
256 9
            'bubble'  => true,
257 9
            'useSSL'  => true,
258 9
            'format'  => 'text',
259 9
            'host'    => 'api.hipchat.com',
260
            'version' => 'v1'
261 9
        ];
262
263 9
        $c = array_merge($defaults,$config);
264
265 9
        return new \Monolog\Handler\HipChatHandler(
266 9
            $c['token'],
267 9
            $c['room'],
268 9
            $c['name'],
269 9
            $c['notify'],
270 9
            $c['level'],
271 9
            $c['bubble'],
272 9
            $c['useSSL'],
273 9
            $c['format'],
274 9
            $c['host'],
275 9
            $c['version']);
276
    }
277
278
    /**
279
     * Creates Mail Monolog Handler
280
     * @param  array  $config An array of config values to use
281
     * @param  string $title The title/subject to use
282
     * @return \Monolog\Handler\MailHandler
283
     */
284 6
    protected static function mail(array $config = [], $title = null)
285
    {
286 6
        if (isset($config['smtp']) && $config['smtp']) {
287 3
            return self::swiftMail($config,$title);
288
        } else {
289 3
            return self::nativeMail($config,$title);
290
        }
291
    }
292
293
    /**
294
     * Creates Mail Monolog Handler
295
     * @param  array  $config An array of config values to use
296
     * @param  string $title The title/subject to use
297
     * @return \Monolog\Handler\SwiftMailerHandler
298
     */
299 3
    protected static function swiftMail(array $config, $title = null)
300
    {
301
        $defaults = [
302 3
            'level' => Logger::DEBUG,
303
            'bubble' => true
304 3
        ];
305
306 3
        $c = array_merge($defaults,$config);
307
308 3
        $c['title'] = $title;
309
310 3
        return new \Monolog\Handler\SwiftMailerHandler(
311 3
            Mail::getSwiftMailer(),
312 3
            Swift_Message::newInstance($c['title'])->setFrom($c['from'])->setTo($c['to']),
313 3
            $c['level'],
314 3
            $c['bubble']
315 3
        );
316
    }
317
318
    /**
319
     * Creates Mail Monolog Handler
320
     * @param  array  $config An array of config values to use
321
     * @param  string $title The title/subject to use
322
     * @return \Monolog\Handler\NativeMailerHandler
323
     */
324 3
    protected static function nativeMail(array $config, $title = null)
325
    {
326
        $defaults = [
327 3
            'level' => Logger::DEBUG,
328 3
            'bubble' => true,
329
            'maxColumnWidth' => 70
330 3
        ];
331
332 3
        $c = array_merge($defaults,$config);
333
334 3
        $c['title'] = $title;
335
336 3
        return new \Monolog\Handler\NativeMailerHandler(
337 3
            $c['to'],
338 3
            $c['title'],
339 3
            $c['from'],
340 3
            $c['level'],
341 3
            $c['bubble'],
342 3
            $c['maxColumnWidth']
343 3
        );
344
    }
345
}