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 ( ef3201...7a6069 )
by Tyler
03:41
created

MonologHandlerFactory::raven()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
ccs 11
cts 11
cp 1
cc 1
eloc 10
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 36
    public static function create($name, array $config = [], $title = null){
19 36
        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 FlowdockHandler
59
     * @param  array  $config An array of config values to use
60
     * @param  string $title The title/subject to use
61
     * @return \Monolog\Handler\FlowdockHandler
62
     */
63 3 View Code Duplication
    protected static function flowdock(array $config = [], $title = null){
1 ignored issue
show
Unused Code introduced by
The parameter $title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
64
        $defaults = [
65 3
            "level" => Logger::DEBUG,
66 3
            "bubble" => true,
67 3
        ];
68
69 3
        $c = array_merge($defaults,$config);
70
71 3
        return new \Monolog\Handler\FlowdockHandler(
72 3
            $c['token'],
73 3
            $c['level'],
74 3
            $c['bubble']);
75
    }
76
77
    /**
78
     * Returns a FleepHookHandler
79
     * @param  array  $config An array of config values to use
80
     * @param  string $title The title/subject to use
81
     * @return \Monolog\Handler\FleepHookHandler
82
     */
83 3 View Code Duplication
    protected static function fleephook(array $config = [], $title = null){
1 ignored issue
show
Unused Code introduced by
The parameter $title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
84
        $defaults = [
85 3
            "level" => Logger::DEBUG,
86 3
            "bubble" => true,
87 3
        ];
88
89 3
        $c = array_merge($defaults,$config);
90
91 3
        return new \Monolog\Handler\FleepHookHandler(
92 3
            $c['token'],
93 3
            $c['level'],
94 3
            $c['bubble']);
95
    }
96
97
    /**
98
     * Returns a PlivoHandler
99
     * @param  array  $config An array of config values to use
100
     * @param  string $title The title/subject to use
101
     * @return \Tylercd100\Monolog\Handler\PlivoHandler
102
     */
103 3 View Code Duplication
    protected static function plivo(array $config = [], $title = null){
1 ignored issue
show
Unused Code introduced by
The parameter $title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
104
        $defaults = [
105 3
            'level' => Logger::DEBUG,
106 3
            'bubble' => true,
107 3
            'useSSL' => true,
108 3
            'host' => 'api.plivo.com',
109 3
            'version' => 'v1',
110 3
            'limit' => 160,
111 3
        ];
112
113 3
        $c = array_merge($defaults,$config);
114
115 3
        return new \Tylercd100\Monolog\Handler\PlivoHandler(
116 3
            $c['token'],
117 3
            $c['auth_id'],
118 3
            $c['from'],
119 3
            $c['to'],
120 3
            $c['level'],
121 3
            $c['bubble'],
122 3
            $c['useSSL'],
123 3
            $c['host'],
124 3
            $c['version'],
125 3
            $c['limit']);
126
    }
127
128
    /**
129
     * Returns a TwilioHandler
130
     * @param  array  $config An array of config values to use
131
     * @param  string $title The title/subject to use
132
     * @return \Tylercd100\Monolog\Handler\TwilioHandler
133
     */
134 3 View Code Duplication
    protected static function twilio(array $config = [], $title = null){
1 ignored issue
show
Unused Code introduced by
The parameter $title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
135
        $defaults = [
136 3
            'level' => Logger::DEBUG,
137 3
            'bubble' => true,
138 3
            'useSSL' => true,
139 3
            'host' => 'api.twilio.com',
140 3
            'version' => '2010-04-01',
141 3
            'limit' => 160,
142 3
        ];
143
144 3
        $c = array_merge($defaults,$config);
145
146 3
        return new \Tylercd100\Monolog\Handler\TwilioHandler(
147 3
            $c['secret'],
148 3
            $c['sid'],
149 3
            $c['from'],
150 3
            $c['to'],
151 3
            $c['level'],
152 3
            $c['bubble'],
153 3
            $c['useSSL'],
154 3
            $c['host'],
155 3
            $c['version'],
156 3
            $c['limit']);
157
    }
158
159
    /**
160
     * Returns a RavenHandler
161
     * @param  array  $config An array of config values to use
162
     * @param  string $title The title/subject to use
163
     * @return \Monolog\Handler\RavenHandler
164
     */
165 3
    protected static function raven(array $config = [], $title = null){
1 ignored issue
show
Unused Code introduced by
The parameter $title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
166
        $defaults = [
167 3
            'dsn'    => null,
168 3
            'level'  => Logger::ERROR,
169 3
            'bubble' => true,
170 3
        ];
171
172 3
        $c = array_merge($defaults, $config);
173
174 3
        return new \Monolog\Handler\RavenHandler(
175 3
            new \Raven_Client($c['dsn'], array_except($c, ['dsn'])),
176 3
            $c['level'],
177 3
            $c['bubble']
178 3
        );
179
    }
180
181
    /**
182
     * Returns a SlackHandler
183
     * @param  array  $config An array of config values to use
184
     * @param  string $title The title/subject to use
185
     * @return \Monolog\Handler\SlackHandler
186
     */
187 9
    protected static function slack(array $config = [], $title = null){
1 ignored issue
show
Unused Code introduced by
The parameter $title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
188
        $defaults = [
189 9
            'username' => 'Monolog',
190 9
            'useAttachment' => true,
191 9
            'iconEmoji' => null,
192 9
            'level' => Logger::DEBUG,
193 9
            'bubble' => true,
194 9
            'useShortAttachment' => false,
195
            'includeContextAndExtra' => false
196 9
        ];
197
198 9
        $c = array_merge($defaults,$config);
199
200 9
        return new \Monolog\Handler\SlackHandler(
201 9
            $c['token'],
202 9
            $c['channel'],
203 9
            $c['username'],
204 9
            $c['useAttachment'],
205 9
            $c['iconEmoji'],
206 9
            $c['level'],
207 9
            $c['bubble'],
208 9
            $c['useShortAttachment'],
209 9
            $c['includeContextAndExtra']);
210
    }
211
212
    /**
213
     * Returns a HipChatHandler
214
     * @param  array  $config An array of config values to use
215
     * @param  string $title The title/subject to use
216
     * @return \Monolog\Handler\HipChatHandler
217
     */
218 9
    protected static function hipchat(array $config = [], $title = null){
1 ignored issue
show
Unused Code introduced by
The parameter $title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
219
        $defaults = [
220 9
            'name'    => 'Monolog',
221 9
            'notify'  => false,
222 9
            'level'   => Logger::DEBUG,
223 9
            'bubble'  => true,
224 9
            'useSSL'  => true,
225 9
            'format'  => 'text',
226 9
            'host'    => 'api.hipchat.com',
227
            'version' => 'v1'
228 9
        ];
229
230 9
        $c = array_merge($defaults,$config);
231
232 9
        return new \Monolog\Handler\HipChatHandler(
233 9
            $c['token'],
234 9
            $c['room'],
235 9
            $c['name'],
236 9
            $c['notify'],
237 9
            $c['level'],
238 9
            $c['bubble'],
239 9
            $c['useSSL'],
240 9
            $c['format'],
241 9
            $c['host'],
242 9
            $c['version']);
243
    }
244
245
    /**
246
     * Creates Mail Monolog Handler
247
     * @param  array  $config An array of config values to use
248
     * @param  string $title The title/subject to use
249
     * @return \Monolog\Handler\MailHandler
250
     */
251 6
    protected static function mail(array $config = [], $title = null)
252
    {
253 6
        if (isset($config['smtp']) && $config['smtp']) {
254 3
            return self::swiftMail($config,$title);
255
        } else {
256 3
            return self::nativeMail($config,$title);
257
        }
258
    }
259
260
    /**
261
     * Creates Mail Monolog Handler
262
     * @param  array  $config An array of config values to use
263
     * @param  string $title The title/subject to use
264
     * @return \Monolog\Handler\SwiftMailerHandler
265
     */
266 3
    protected static function swiftMail(array $config, $title = null)
267
    {
268
        $defaults = [
269 3
            'level' => Logger::DEBUG,
270
            'bubble' => true
271 3
        ];
272
273 3
        $c = array_merge($defaults,$config);
274
275 3
        $c['title'] = $title;
276
277 3
        return new \Monolog\Handler\SwiftMailerHandler(
278 3
            Mail::getSwiftMailer(),
279 3
            Swift_Message::newInstance($c['title'])->setFrom($c['from'])->setTo($c['to']),
280 3
            $c['level'],
281 3
            $c['bubble']
282 3
        );
283
    }
284
285
    /**
286
     * Creates Mail Monolog Handler
287
     * @param  array  $config An array of config values to use
288
     * @param  string $title The title/subject to use
289
     * @return \Monolog\Handler\NativeMailerHandler
290
     */
291 3
    protected static function nativeMail(array $config, $title = null)
292
    {
293
        $defaults = [
294 3
            'level' => Logger::DEBUG,
295 3
            'bubble' => true,
296
            'maxColumnWidth' => 70
297 3
        ];
298
299 3
        $c = array_merge($defaults,$config);
300
301 3
        $c['title'] = $title;
302
303 3
        return new \Monolog\Handler\NativeMailerHandler(
304 3
            $c['to'],
305 3
            $c['title'],
306 3
            $c['from'],
307 3
            $c['level'],
308 3
            $c['bubble'],
309 3
            $c['maxColumnWidth']
310 3
        );
311
    }
312
}