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 ( 676889...623b3f )
by Tyler
04:34
created

MonologHandlerFactory::flowdock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 13
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 9
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 33
    public static function create($name, array $config = [], $title = null){
19 33
        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 9
    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 9
            $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
            'version' => 'v1'
110 3
        ];
111
112 3
        $c = array_merge($defaults,$config);
113
114 3
        return new \Tylercd100\Monolog\Handler\PlivoHandler(
115 3
            $c['token'],
116 3
            $c['auth_id'],
117 3
            $c['from'],
118 3
            $c['to'],
119 3
            $c['level'],
120 3
            $c['bubble'],
121 3
            $c['useSSL'],
122 3
            $c['host'],
123 3
            $c['version']);
124
    }
125
126
    /**
127
     * Returns a TwilioHandler
128
     * @param  array  $config An array of config values to use
129
     * @param  string $title The title/subject to use
130
     * @return \Tylercd100\Monolog\Handler\TwilioHandler
131
     */
132 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...
133
        $defaults = [
134 3
            'level' => Logger::DEBUG,
135 3
            'bubble' => true,
136 3
            'useSSL' => true,
137 3
            'host' => 'api.twilio.com',
138
            'version' => '2010-04-01'
139 3
        ];
140
141 3
        $c = array_merge($defaults,$config);
142
143 3
        return new \Tylercd100\Monolog\Handler\TwilioHandler(
144 3
            $c['secret'],
145 3
            $c['sid'],
146 3
            $c['from'],
147 3
            $c['to'],
148 3
            $c['level'],
149 3
            $c['bubble'],
150 3
            $c['useSSL'],
151 3
            $c['host'],
152 3
            $c['version']);
153
    }
154
155
    /**
156
     * Returns a SlackHandler
157
     * @param  array  $config An array of config values to use
158
     * @param  string $title The title/subject to use
159
     * @return \Monolog\Handler\SlackHandler
160
     */
161 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...
162
        $defaults = [
163 9
            'username' => 'Monolog', 
164 9
            'useAttachment' => true, 
165 9
            'iconEmoji' => null, 
166 9
            'level' => Logger::DEBUG, 
167 9
            'bubble' => true, 
168 9
            'useShortAttachment' => false, 
169
            'includeContextAndExtra' => false
170 9
        ];
171
172 9
        $c = array_merge($defaults,$config);
173
174 9
        return new \Monolog\Handler\SlackHandler(
175 9
            $c['token'], 
176 9
            $c['channel'], 
177 9
            $c['username'],
178 9
            $c['useAttachment'],
179 9
            $c['iconEmoji'],
180 9
            $c['level'],
181 9
            $c['bubble'],
182 9
            $c['useShortAttachment'],
183 9
            $c['includeContextAndExtra']);
184
    }
185
186
    /**
187
     * Returns a HipChatHandler
188
     * @param  array  $config An array of config values to use
189
     * @param  string $title The title/subject to use
190
     * @return \Monolog\Handler\HipChatHandler
191
     */
192 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...
193
        $defaults = [
194 9
            'name'    => 'Monolog',
195 9
            'notify'  => false,
196 9
            'level'   => Logger::DEBUG,
197 9
            'bubble'  => true,
198 9
            'useSSL'  => true,
199 9
            'format'  => 'text',
200 9
            'host'    => 'api.hipchat.com',
201
            'version' => 'v1'
202 9
        ];
203
204 9
        $c = array_merge($defaults,$config);
205
206 9
        return new \Monolog\Handler\HipChatHandler(
207 9
            $c['token'],
208 9
            $c['room'],
209 9
            $c['name'],
210 9
            $c['notify'],
211 9
            $c['level'],
212 9
            $c['bubble'],
213 9
            $c['useSSL'],
214 9
            $c['format'],
215 9
            $c['host'],
216 9
            $c['version']);
217
    }
218
219
    /**
220
     * Creates Mail Monolog Handler
221
     * @param  array  $config An array of config values to use
222
     * @param  string $title The title/subject to use
223
     * @return \Monolog\Handler\MailHandler
224
     */
225 6
    protected static function mail(array $config = [], $title = null)
226
    {
227 6
        if (isset($config['smtp']) && $config['smtp']) {
228 3
            return self::swiftMail($config,$title);            
229
        } else {
230 3
            return self::nativeMail($config,$title);
231
        }
232
    }
233
234
    /**
235
     * Creates Mail Monolog Handler
236
     * @param  array  $config An array of config values to use
237
     * @param  string $title The title/subject to use
238
     * @return \Monolog\Handler\SwiftMailerHandler
239
     */
240 3
    protected static function swiftMail(array $config, $title = null)
241
    {
242
        $defaults = [
243 3
            'level' => Logger::DEBUG, 
244
            'bubble' => true
245 3
        ];
246
247 3
        $c = array_merge($defaults,$config);
248
249 3
        $c['title'] = $title;
250
251 3
        return new \Monolog\Handler\SwiftMailerHandler(
252 3
            Mail::getSwiftMailer(),
253 3
            Swift_Message::newInstance($c['title'])->setFrom($c['from'])->setTo($c['to']),
254 3
            $c['level'], 
255 3
            $c['bubble']
256 3
        );
257
    }
258
259
    /**
260
     * Creates Mail Monolog Handler
261
     * @param  array  $config An array of config values to use
262
     * @param  string $title The title/subject to use
263
     * @return \Monolog\Handler\NativeMailerHandler
264
     */
265 3
    protected static function nativeMail(array $config, $title = null)
266
    {
267
        $defaults = [
268 3
            'level' => Logger::DEBUG,
269 3
            'bubble' => true,
270
            'maxColumnWidth' => 70
271 3
        ];
272
273 3
        $c = array_merge($defaults,$config);
274
275 3
        $c['title'] = $title;
276
277 3
        return new \Monolog\Handler\NativeMailerHandler(
278 3
            $c['to'],
279 3
            $c['title'],
280 3
            $c['from'],
281 3
            $c['level'], 
282 3
            $c['bubble'], 
283 3
            $c['maxColumnWidth']
284 3
        );
285
    }
286
}