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 ( 250abc...ed5ff2 )
by Tyler
04:00
created

MonologHandlerFactory::mail()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 3
eloc 5
nc 2
nop 2
crap 3
1
<?php
2
3
namespace Tylercd100\Notify\Factories;
4
5
use Monolog\Logger;
6
use Mail;
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
     * @return \Monolog\Handler\HandlerInterface
16
     */
17 21
    public static function create($name, array $config = [], $title = null){
18 21
        return call_user_func([MonologHandlerFactory::class,$name], $config, $title);
19
    }
20
21
    /**
22
     * Returns a PushoverHandler
23
     * @param  array  $config An array of config values to use
24
     * @param  string $title The title/subject to use
25
     * @return \Monolog\Handler\PushoverHandler
26
     */
27 9
    protected static function pushover(array $config = [], $title = null){
28
        $defaults = [
29 9
            "title" => null,
30 9
            "level" => Logger::DEBUG,
31 9
            "bubble" => true,
32 9
            "useSSL" => true,
33 9
            "highPriorityLevel" => Logger::CRITICAL,
34 9
            "emergencyLevel" => Logger::EMERGENCY,
35 9
            "retry" => 30,
36
            "expire" => 25200
37 9
        ];
38
39 9
        $c = array_merge($defaults,$config);
40
41 9
        $c['title'] = $title;
42
43 9
        return new \Monolog\Handler\PushoverHandler(
44 9
            $c['token'], 
45 9
            $c['users'], 
46 9
            $c['title'], 
47 9
            $c['level'], 
48 9
            $c['bubble'], 
49 9
            $c['useSSL'], 
50 9
            $c['highPriorityLevel'], 
51 9
            $c['emergencyLevel'], 
52 9
            $c['retry'], 
53 9
            $c['expire']);
54
    }
55
56
    /**
57
     * Returns a SlackHandler
58
     * @param  array  $config An array of config values to use
59
     * @param  string $title The title/subject to use
60
     * @return \Monolog\Handler\SlackHandler
61
     */
62 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...
63
        $defaults = [
64 9
            'username' => 'Monolog', 
65 9
            'useAttachment' => true, 
66 9
            'iconEmoji' => null, 
67 9
            'level' => Logger::DEBUG, 
68 9
            'bubble' => true, 
69 9
            'useShortAttachment' => false, 
70
            'includeContextAndExtra' => false
71 9
        ];
72
73 9
        $c = array_merge($defaults,$config);
74
75 9
        return new \Monolog\Handler\SlackHandler(
76 9
            $c['token'], 
77 9
            $c['channel'], 
78 9
            $c['username'],
79 9
            $c['useAttachment'],
80 9
            $c['iconEmoji'],
81 9
            $c['level'],
82 9
            $c['bubble'],
83 9
            $c['useShortAttachment'],
84 9
            $c['includeContextAndExtra']);
85
    }
86
87
    /**
88
     * Returns a HipChatHandler
89
     * @param  array  $config An array of config values to use
90
     * @param  string $title The title/subject to use
91
     * @return \Monolog\Handler\HipChatHandler
92
     */
93 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...
94
        $defaults = [
95 9
            'name'    => 'Monolog',
96 9
            'notify'  => false,
97 9
            'level'   => Logger::DEBUG,
98 9
            'bubble'  => true,
99 9
            'useSSL'  => true,
100 9
            'format'  => 'text',
101 9
            'host'    => 'api.hipchat.com',
102
            'version' => 'v1'
103 9
        ];
104
105 9
        $c = array_merge($defaults,$config);
106
107 9
        return new \Monolog\Handler\HipChatHandler(
108 9
            $c['token'],
109 9
            $c['room'],
110 9
            $c['name'],
111 9
            $c['notify'],
112 9
            $c['level'],
113 9
            $c['bubble'],
114 9
            $c['useSSL'],
115 9
            $c['format'],
116 9
            $c['host'],
117 9
            $c['version']);
118
    }
119
120
    /**
121
     * Creates Mail Monolog Handler
122
     * @param  array  $config An array of config values to use
123
     * @param  string $title The title/subject to use
124
     * @return \Monolog\Handler\MailHandler
125
     */
126 6
    protected static function mail(array $config = [], $title = null)
127
    {
128 6
        if (isset($config['smtp']) && $config['smtp']) {
129 3
            return self::swiftMail($config,$title);            
130
        } else {
131 3
            return self::nativeMail($config,$title);
132
        }
133
    }
134
135
    /**
136
     * Creates Mail Monolog Handler
137
     * @param  array  $config An array of config values to use
138
     * @param  string $title The title/subject to use
139
     * @return \Monolog\Handler\SwiftMailerHandler
140
     */
141 3
    protected static function swiftMail(array $config, $title = null)
142
    {
143
        $defaults = [
144 3
            'level' => Logger::DEBUG, 
145
            'bubble' => true
146 3
        ];
147
148 3
        $c = array_merge($defaults,$config);
149
150 3
        $c['title'] = $title;
151
152 3
        return new \Monolog\Handler\SwiftMailerHandler(
153 3
            Mail::getSwiftMailer(),
154 3
            Swift_Message::newInstance($c['title'])->setFrom($c['from'])->setTo($c['to']),
155 3
            $c['level'], 
156 3
            $c['bubble']
157 3
        );
158
    }
159
160
    /**
161
     * Creates Mail Monolog Handler
162
     * @param  array  $config An array of config values to use
163
     * @param  string $title The title/subject to use
164
     * @return \Monolog\Handler\NativeMailerHandler
165
     */
166 3
    protected static function nativeMail(array $config, $title = null)
167
    {
168
        $defaults = [
169 3
            'level' => Logger::DEBUG,
170 3
            'bubble' => true,
171
            'maxColumnWidth' => 70
172 3
        ];
173
174 3
        $c = array_merge($defaults,$config);
175
176 3
        $c['title'] = $title;
177
178 3
        return new \Monolog\Handler\NativeMailerHandler(
179 3
            $c['to'],
180 3
            $c['title'],
181 3
            $c['from'],
182 3
            $c['level'], 
183 3
            $c['bubble'], 
184 3
            $c['maxColumnWidth']
185 3
        );
186
    }
187
}