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 ( 8a5ca1...b4ccc7 )
by Tyler
04:22
created

MonologHandlerFactory::create()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.072

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 16
ccs 8
cts 10
cp 0.8
rs 9.4285
cc 3
eloc 8
nc 4
nop 3
crap 3.072
1
<?php
2
3
namespace Tylercd100\Notify\Factories;
4
5
use Mail;
6
use Monolog\Logger;
7
use Swift_Message;
8
use Monolog\Formatter\LineFormatter;
9
10
class MonologHandlerFactory
11
{
12
    /**
13
     * Returns an instance of \Monolog\Handler\HandlerInterface
14
     * @param  string $name   Then name of the handler you want to create
15
     * @param  array  $config An array of config values to use
16
     * @param string $title
17
     * @return \Monolog\Handler\HandlerInterface
18
     */
19 39
    public static function create($name, array $config = [], $title = null){
20 39
        $handler = call_user_func([MonologHandlerFactory::class,$name], $config, $title);
21
        
22
        // Keep newline characters
23 39
        $format = ['mail', 'mailgun'];
24
        
25 39
        if(in_array($name, $format)) {
26 15
            $handler->setFormatter(new LineFormatter(null, null, true));
27 15
        }
28
29 39
        if ($handler instanceof NativeMailerHandler) {
0 ignored issues
show
Bug introduced by
The class Tylercd100\Notify\Factories\NativeMailerHandler does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
30
            $handler->setContentType('text/html');
31
        }
32
33 39
        return $handler;
34
    }
35
36
    /**
37
     * Returns a PushoverHandler
38
     * @param  array  $config An array of config values to use
39
     * @param  string $title The title/subject to use
40
     * @return \Monolog\Handler\PushoverHandler
41
     */
42 12
    protected static function pushover(array $config = [], $title = null){
43
        $defaults = [
44 9
            "title" => null,
45 9
            "level" => Logger::DEBUG,
46 9
            "bubble" => true,
47 9
            "useSSL" => true,
48 9
            "highPriorityLevel" => Logger::CRITICAL,
49 9
            "emergencyLevel" => Logger::EMERGENCY,
50 9
            "retry" => 30,
51
            "expire" => 25200
52 10
        ];
53
54 9
        $c = array_merge($defaults,$config);
55
56 11
        $c['title'] = $title;
57
58 10
        return new \Monolog\Handler\PushoverHandler(
59 9
            $c['token'],
60 9
            $c['users'],
61 9
            $c['title'],
62 11
            $c['level'],
63 9
            $c['bubble'],
64 9
            $c['useSSL'],
65 9
            $c['highPriorityLevel'],
66 9
            $c['emergencyLevel'],
67 9
            $c['retry'],
68 9
            $c['expire']);
69
    }
70
71
    /**
72
     * Returns a PushoverHandler
73
     * @param  array  $config An array of config values to use
74
     * @param  string $title The title/subject to use
75
     * @return \Tylercd100\Monolog\Handler\MailgunHandler
76
     */
77 6
    protected static function mailgun(array $config = [], $title = null){
78
        $defaults = [
79 3
            "title" => null,
80 3
            "level" => Logger::CRITICAL,
81 3
            "bubble" => true,
82 4
            "host" => 'api.mailgun.net',
83
            "version" => 'v3'
84 3
        ];
85
86 3
        $c = array_merge($defaults,$config);
87
88 3
        $c['title'] = $title;
89
90 3
        return new \Tylercd100\Monolog\Handler\MailgunHandler(
91 3
            $c["to"],
92 5
            $c["title"],
93 3
            $c["from"],
94 3
            $c["token"],
95 3
            $c["domain"],
96 3
            $c["level"],
97 3
            $c["bubble"],
98 3
            $c["host"],
99 3
            $c["version"]);
100
    }
101
102
    /**
103
     * Returns a FlowdockHandler
104
     * @param  array  $config An array of config values to use
105
     * @param  string $title The title/subject to use
106
     * @return \Monolog\Handler\FlowdockHandler
107
     */
108 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...
109
        $defaults = [
110 3
            "level" => Logger::DEBUG,
111 3
            "bubble" => true,
112 3
        ];
113
114 3
        $c = array_merge($defaults,$config);
115
116 3
        return new \Monolog\Handler\FlowdockHandler(
117 3
            $c['token'],
118 3
            $c['level'],
119 3
            $c['bubble']);
120
    }
121
122
    /**
123
     * Returns a FleepHookHandler
124
     * @param  array  $config An array of config values to use
125
     * @param  string $title The title/subject to use
126
     * @return \Monolog\Handler\FleepHookHandler
127
     */
128 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...
129
        $defaults = [
130 3
            "level" => Logger::DEBUG,
131 3
            "bubble" => true,
132 3
        ];
133
134 3
        $c = array_merge($defaults,$config);
135
136 3
        return new \Monolog\Handler\FleepHookHandler(
137 3
            $c['token'],
138 3
            $c['level'],
139 3
            $c['bubble']);
140
    }
141
142
    /**
143
     * Returns a PlivoHandler
144
     * @param  array  $config An array of config values to use
145
     * @param  string $title The title/subject to use
146
     * @return \Tylercd100\Monolog\Handler\PlivoHandler
147
     */
148 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...
149
        $defaults = [
150 3
            'level' => Logger::DEBUG,
151 3
            'bubble' => true,
152 3
            'useSSL' => true,
153 3
            'host' => 'api.plivo.com',
154 3
            'version' => 'v1',
155 3
            'limit' => 160,
156 3
        ];
157
158 3
        $c = array_merge($defaults,$config);
159
160 3
        return new \Tylercd100\Monolog\Handler\PlivoHandler(
161 3
            $c['token'],
162 3
            $c['auth_id'],
163 3
            $c['from'],
164 3
            $c['to'],
165 3
            $c['level'],
166 3
            $c['bubble'],
167 3
            $c['useSSL'],
168 3
            $c['host'],
169 3
            $c['version'],
170 3
            $c['limit']);
171
    }
172
173
    /**
174
     * Returns a TwilioHandler
175
     * @param  array  $config An array of config values to use
176
     * @param  string $title The title/subject to use
177
     * @return \Tylercd100\Monolog\Handler\TwilioHandler
178
     */
179 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...
180
        $defaults = [
181 3
            'level' => Logger::DEBUG,
182 3
            'bubble' => true,
183 3
            'useSSL' => true,
184 3
            'host' => 'api.twilio.com',
185 3
            'version' => '2010-04-01',
186 3
            'limit' => 160,
187 3
        ];
188
189 3
        $c = array_merge($defaults,$config);
190
191 3
        return new \Tylercd100\Monolog\Handler\TwilioHandler(
192 3
            $c['secret'],
193 3
            $c['sid'],
194 3
            $c['from'],
195 3
            $c['to'],
196 3
            $c['level'],
197 3
            $c['bubble'],
198 3
            $c['useSSL'],
199 3
            $c['host'],
200 3
            $c['version'],
201 3
            $c['limit']);
202
    }
203
204
    /**
205
     * Returns a RavenHandler
206
     * @param  array  $config An array of config values to use
207
     * @param  string $title The title/subject to use
208
     * @return \Monolog\Handler\RavenHandler
209
     */
210 3
    protected static function raven(array $config = [], $title = null){
211
        $defaults = [
212 3
            'dsn'    => null,
213 3
            'level'  => Logger::ERROR,
214 3
            'bubble' => true,
215 3
        ];
216
217 3
        $c = array_merge($defaults, $config);
218
219 3
        return new \Monolog\Handler\RavenHandler(
220 3
            new \Raven_Client($c['dsn'], array_except($c, ['dsn'])),
221 3
            $c['level'],
222 3
            $c['bubble']
223 3
        );
224
    }
225
226
    /**
227
     * Returns a SlackHandler
228
     * @param  array  $config An array of config values to use
229
     * @param  string $title The title/subject to use
230
     * @return \Monolog\Handler\SlackHandler
231
     */
232 9
    protected static function slack(array $config = [], $title = null){
233
        $defaults = [
234 9
            'username' => 'Monolog',
235 9
            'useAttachment' => true,
236 9
            'iconEmoji' => null,
237 9
            'level' => Logger::DEBUG,
238 9
            'bubble' => true,
239 9
            'useShortAttachment' => false,
240
            'includeContextAndExtra' => false
241 9
        ];
242
243 9
        $c = array_merge($defaults,$config);
244
245 9
        return new \Monolog\Handler\SlackHandler(
246 9
            $c['token'],
247 9
            $c['channel'],
248 9
            $c['username'],
249 9
            $c['useAttachment'],
250 9
            $c['iconEmoji'],
251 9
            $c['level'],
252 9
            $c['bubble'],
253 9
            $c['useShortAttachment'],
254 9
            $c['includeContextAndExtra']);
255
    }
256
257
    /**
258
     * Returns a HipChatHandler
259
     * @param  array  $config An array of config values to use
260
     * @param  string $title The title/subject to use
261
     * @return \Monolog\Handler\HipChatHandler
262
     */
263 9
    protected static function hipchat(array $config = [], $title = null){
264
        $defaults = [
265 9
            'name'    => 'Monolog',
266 9
            'notify'  => false,
267 9
            'level'   => Logger::DEBUG,
268 9
            'bubble'  => true,
269 9
            'useSSL'  => true,
270 9
            'format'  => 'text',
271 9
            'host'    => 'api.hipchat.com',
272
            'version' => 'v1'
273 9
        ];
274
275 9
        $c = array_merge($defaults,$config);
276
277 9
        return new \Monolog\Handler\HipChatHandler(
278 9
            $c['token'],
279 9
            $c['room'],
280 9
            $c['name'],
281 9
            $c['notify'],
282 9
            $c['level'],
283 9
            $c['bubble'],
284 9
            $c['useSSL'],
285 9
            $c['format'],
286 9
            $c['host'],
287 9
            $c['version']);
288
    }
289
290
    /**
291
     * Creates Mail Monolog Handler
292
     * @param  array  $config An array of config values to use
293
     * @param  string $title The title/subject to use
294
     * @return \Monolog\Handler\MailHandler
295
     */
296 12
    protected static function mail(array $config = [], $title = null)
297
    {
298 12
        if (isset($config['smtp']) && $config['smtp']) {
299 9
            return self::swiftMail($config,$title);
300
        } else {
301 3
            return self::nativeMail($config,$title);
302
        }
303
    }
304
305
    /**
306
     * Creates Mail Monolog Handler
307
     * @param  array  $config An array of config values to use
308
     * @param  string $title The title/subject to use
309
     * @return \Monolog\Handler\SwiftMailerHandler
310
     */
311 9
    protected static function swiftMail(array $config, $title = null)
312
    {
313
        $defaults = [
314 9
            'level' => Logger::DEBUG,
315
            'bubble' => true
316 9
        ];
317
318 9
        $c = array_merge($defaults,$config);
319
320 9
        $c['title'] = $title;
321
322 9
        return new \Monolog\Handler\SwiftMailerHandler(
323 9
            Mail::getSwiftMailer(),
324 9
            Swift_Message::newInstance($c['title'])->setFrom($c['from'])->setTo($c['to']),
325 9
            $c['level'],
326 9
            $c['bubble']
327 9
        );
328
    }
329
330
    /**
331
     * Creates Mail Monolog Handler
332
     * @param  array  $config An array of config values to use
333
     * @param  string $title The title/subject to use
334
     * @return \Monolog\Handler\NativeMailerHandler
335
     */
336 3
    protected static function nativeMail(array $config, $title = null)
337
    {
338
        $defaults = [
339 3
            'level' => Logger::DEBUG,
340 3
            'bubble' => true,
341
            'maxColumnWidth' => 70
342 3
        ];
343
344 3
        $c = array_merge($defaults,$config);
345
346 3
        $c['title'] = $title;
347
348 3
        return new \Monolog\Handler\NativeMailerHandler(
349 3
            $c['to'],
350 3
            $c['title'],
351 3
            $c['from'],
352 3
            $c['level'],
353 3
            $c['bubble'],
354 3
            $c['maxColumnWidth']
355 3
        );
356
    }
357
}