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

MonologHandlerFactory   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 282
Duplicated Lines 26.24 %

Coupling/Cohesion

Components 0
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 1 Features 4
Metric Value
wmc 13
c 7
b 1
f 4
lcom 0
cbo 11
dl 74
loc 282
ccs 151
cts 151
cp 1
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
B pushover() 0 28 1
A flowdock() 13 13 1
A fleephook() 13 13 1
B plivo() 24 24 1
B twilio() 24 24 1
B slack() 0 24 1
B hipchat() 0 26 1
A mail() 0 8 3
A swiftMail() 0 18 1
A nativeMail() 0 21 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 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 SlackHandler
161
     * @param  array  $config An array of config values to use
162
     * @param  string $title The title/subject to use
163
     * @return \Monolog\Handler\SlackHandler
164
     */
165 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...
166
        $defaults = [
167 9
            'username' => 'Monolog', 
168 9
            'useAttachment' => true, 
169 9
            'iconEmoji' => null, 
170 9
            'level' => Logger::DEBUG, 
171 9
            'bubble' => true, 
172 9
            'useShortAttachment' => false, 
173
            'includeContextAndExtra' => false
174 9
        ];
175
176 9
        $c = array_merge($defaults,$config);
177
178 9
        return new \Monolog\Handler\SlackHandler(
179 9
            $c['token'], 
180 9
            $c['channel'], 
181 9
            $c['username'],
182 9
            $c['useAttachment'],
183 9
            $c['iconEmoji'],
184 9
            $c['level'],
185 9
            $c['bubble'],
186 9
            $c['useShortAttachment'],
187 9
            $c['includeContextAndExtra']);
188
    }
189
190
    /**
191
     * Returns a HipChatHandler
192
     * @param  array  $config An array of config values to use
193
     * @param  string $title The title/subject to use
194
     * @return \Monolog\Handler\HipChatHandler
195
     */
196 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...
197
        $defaults = [
198 9
            'name'    => 'Monolog',
199 9
            'notify'  => false,
200 9
            'level'   => Logger::DEBUG,
201 9
            'bubble'  => true,
202 9
            'useSSL'  => true,
203 9
            'format'  => 'text',
204 9
            'host'    => 'api.hipchat.com',
205
            'version' => 'v1'
206 9
        ];
207
208 9
        $c = array_merge($defaults,$config);
209
210 9
        return new \Monolog\Handler\HipChatHandler(
211 9
            $c['token'],
212 9
            $c['room'],
213 9
            $c['name'],
214 9
            $c['notify'],
215 9
            $c['level'],
216 9
            $c['bubble'],
217 9
            $c['useSSL'],
218 9
            $c['format'],
219 9
            $c['host'],
220 9
            $c['version']);
221
    }
222
223
    /**
224
     * Creates Mail Monolog Handler
225
     * @param  array  $config An array of config values to use
226
     * @param  string $title The title/subject to use
227
     * @return \Monolog\Handler\MailHandler
228
     */
229 6
    protected static function mail(array $config = [], $title = null)
230
    {
231 6
        if (isset($config['smtp']) && $config['smtp']) {
232 3
            return self::swiftMail($config,$title);            
233
        } else {
234 3
            return self::nativeMail($config,$title);
235
        }
236
    }
237
238
    /**
239
     * Creates Mail Monolog Handler
240
     * @param  array  $config An array of config values to use
241
     * @param  string $title The title/subject to use
242
     * @return \Monolog\Handler\SwiftMailerHandler
243
     */
244 3
    protected static function swiftMail(array $config, $title = null)
245
    {
246
        $defaults = [
247 3
            'level' => Logger::DEBUG, 
248
            'bubble' => true
249 3
        ];
250
251 3
        $c = array_merge($defaults,$config);
252
253 3
        $c['title'] = $title;
254
255 3
        return new \Monolog\Handler\SwiftMailerHandler(
256 3
            Mail::getSwiftMailer(),
257 3
            Swift_Message::newInstance($c['title'])->setFrom($c['from'])->setTo($c['to']),
258 3
            $c['level'], 
259 3
            $c['bubble']
260 3
        );
261
    }
262
263
    /**
264
     * Creates Mail Monolog Handler
265
     * @param  array  $config An array of config values to use
266
     * @param  string $title The title/subject to use
267
     * @return \Monolog\Handler\NativeMailerHandler
268
     */
269 3
    protected static function nativeMail(array $config, $title = null)
270
    {
271
        $defaults = [
272 3
            'level' => Logger::DEBUG,
273 3
            'bubble' => true,
274
            'maxColumnWidth' => 70
275 3
        ];
276
277 3
        $c = array_merge($defaults,$config);
278
279 3
        $c['title'] = $title;
280
281 3
        return new \Monolog\Handler\NativeMailerHandler(
282 3
            $c['to'],
283 3
            $c['title'],
284 3
            $c['from'],
285 3
            $c['level'], 
286 3
            $c['bubble'], 
287 3
            $c['maxColumnWidth']
288 3
        );
289
    }
290
}