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 ( dce2d2...f4749f )
by Tyler
04:05
created

MonologHandlerFactory::plivo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 18

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 22
loc 22
ccs 0
cts 17
cp 0
rs 9.2
cc 1
eloc 18
nc 1
nop 2
crap 2
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 27
    public static function create($name, array $config = [], $title = null){
19 27
        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 PlivoHandler
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\PlivoHandler
62
     */
63 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...
64
        $defaults = [
65
            'level' => Logger::DEBUG,
66
            'bubble' => true,
67
            'useSSL' => true,
68
            'host' => 'api.plivo.com',
69
            'version' => 'v1'
70
        ];
71
72
        $c = array_merge($defaults,$config);
73
74
        return new \Tylercd100\Monolog\Handler\PlivoHandler(
75
            $c['token'],
76
            $c['auth_id'],
77
            $c['from'],
78
            $c['to'],
79
            $c['level'],
80
            $c['bubble'],
81
            $c['useSSL'],
82
            $c['host'],
83
            $c['version']);
84
    }
85
86
    /**
87
     * Returns a TwilioHandler
88
     * @param  array  $config An array of config values to use
89
     * @param  string $title The title/subject to use
90
     * @return \Tylercd100\Monolog\Handler\TwilioHandler
91
     */
92 6 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...
93
        $defaults = [
94 6
            'level' => Logger::DEBUG,
95 6
            'bubble' => true,
96 6
            'useSSL' => true,
97 6
            'host' => 'api.twilio.com',
98
            'version' => '2010-04-01'
99 6
        ];
100
101 6
        $c = array_merge($defaults,$config);
102
103 6
        return new \Tylercd100\Monolog\Handler\TwilioHandler(
104 6
            $c['secret'],
105 6
            $c['sid'],
106 6
            $c['from'],
107 6
            $c['to'],
108 6
            $c['level'],
109 6
            $c['bubble'],
110 6
            $c['useSSL'],
111 6
            $c['host'],
112 6
            $c['version']);
113
    }
114
115
    /**
116
     * Returns a SlackHandler
117
     * @param  array  $config An array of config values to use
118
     * @param  string $title The title/subject to use
119
     * @return \Monolog\Handler\SlackHandler
120
     */
121 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...
122
        $defaults = [
123 9
            'username' => 'Monolog', 
124 9
            'useAttachment' => true, 
125 9
            'iconEmoji' => null, 
126 9
            'level' => Logger::DEBUG, 
127 9
            'bubble' => true, 
128 9
            'useShortAttachment' => false, 
129
            'includeContextAndExtra' => false
130 9
        ];
131
132 9
        $c = array_merge($defaults,$config);
133
134 9
        return new \Monolog\Handler\SlackHandler(
135 9
            $c['token'], 
136 9
            $c['channel'], 
137 9
            $c['username'],
138 9
            $c['useAttachment'],
139 9
            $c['iconEmoji'],
140 9
            $c['level'],
141 9
            $c['bubble'],
142 9
            $c['useShortAttachment'],
143 9
            $c['includeContextAndExtra']);
144
    }
145
146
    /**
147
     * Returns a HipChatHandler
148
     * @param  array  $config An array of config values to use
149
     * @param  string $title The title/subject to use
150
     * @return \Monolog\Handler\HipChatHandler
151
     */
152 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...
153
        $defaults = [
154 9
            'name'    => 'Monolog',
155 9
            'notify'  => false,
156 9
            'level'   => Logger::DEBUG,
157 9
            'bubble'  => true,
158 9
            'useSSL'  => true,
159 9
            'format'  => 'text',
160 9
            'host'    => 'api.hipchat.com',
161
            'version' => 'v1'
162 9
        ];
163
164 9
        $c = array_merge($defaults,$config);
165
166 9
        return new \Monolog\Handler\HipChatHandler(
167 9
            $c['token'],
168 9
            $c['room'],
169 9
            $c['name'],
170 9
            $c['notify'],
171 9
            $c['level'],
172 9
            $c['bubble'],
173 9
            $c['useSSL'],
174 9
            $c['format'],
175 9
            $c['host'],
176 9
            $c['version']);
177
    }
178
179
    /**
180
     * Creates Mail Monolog Handler
181
     * @param  array  $config An array of config values to use
182
     * @param  string $title The title/subject to use
183
     * @return \Monolog\Handler\MailHandler
184
     */
185 6
    protected static function mail(array $config = [], $title = null)
186
    {
187 6
        if (isset($config['smtp']) && $config['smtp']) {
188 3
            return self::swiftMail($config,$title);            
189
        } else {
190 3
            return self::nativeMail($config,$title);
191
        }
192
    }
193
194
    /**
195
     * Creates Mail Monolog Handler
196
     * @param  array  $config An array of config values to use
197
     * @param  string $title The title/subject to use
198
     * @return \Monolog\Handler\SwiftMailerHandler
199
     */
200 3
    protected static function swiftMail(array $config, $title = null)
201
    {
202
        $defaults = [
203 3
            'level' => Logger::DEBUG, 
204
            'bubble' => true
205 3
        ];
206
207 3
        $c = array_merge($defaults,$config);
208
209 3
        $c['title'] = $title;
210
211 3
        return new \Monolog\Handler\SwiftMailerHandler(
212 3
            Mail::getSwiftMailer(),
213 3
            Swift_Message::newInstance($c['title'])->setFrom($c['from'])->setTo($c['to']),
214 3
            $c['level'], 
215 3
            $c['bubble']
216 3
        );
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\NativeMailerHandler
224
     */
225 3
    protected static function nativeMail(array $config, $title = null)
226
    {
227
        $defaults = [
228 3
            'level' => Logger::DEBUG,
229 3
            'bubble' => true,
230
            'maxColumnWidth' => 70
231 3
        ];
232
233 3
        $c = array_merge($defaults,$config);
234
235 3
        $c['title'] = $title;
236
237 3
        return new \Monolog\Handler\NativeMailerHandler(
238 3
            $c['to'],
239 3
            $c['title'],
240 3
            $c['from'],
241 3
            $c['level'], 
242 3
            $c['bubble'], 
243 3
            $c['maxColumnWidth']
244 3
        );
245
    }
246
}