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 ( 93cfba...3f64ec )
by Tyler
02:07
created

MailgunHandler::send()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 17
cp 0
rs 8.9713
cc 1
eloc 16
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Tylercd100\Monolog\Handler;
4
5
use Exception;
6
use Monolog\Logger;
7
use Monolog\Handler\MailHandler;
8
9
/**
10
 * MailgunHandler uses cURL to send the emails to the Mailgun API
11
 *
12
 * @author Tyler Arbon <[email protected]>
13
 */
14
class MailgunHandler extends MailHandler
15
{
16
    protected $message;
17
    protected $apiKey;
18
19 6
    public function __construct($to, $subject, $from, $token, $domain, $level = Logger::CRITICAL, $bubble = true, $host = 'api.mailgun.net', $version = 'v3')
20
    {
21 6
        if ($version !== 'v3') {
22 3
            throw new Exception("Version '{$version}' is not supported");
23
        }
24
25 3
        $this->to = $to;
0 ignored issues
show
Bug introduced by
The property to does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26 3
        $this->subject = $subject;
0 ignored issues
show
Bug introduced by
The property subject does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27 3
        $this->from = $from;
0 ignored issues
show
Bug introduced by
The property from does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28 3
        $this->host = $host;
0 ignored issues
show
Bug introduced by
The property host does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29 3
        $this->version = $version;
0 ignored issues
show
Bug introduced by
The property version does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30 3
        $this->domain = $domain;
0 ignored issues
show
Bug introduced by
The property domain does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31 3
        $this->token = $token;
0 ignored issues
show
Bug introduced by
The property token does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
33 3
        parent::__construct($level, $bubble);
34 3
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    protected function send($content, array $records)
40
    {
41
        $auth = base64_encode("api:".$this->token);
42
43
        $fields = http_build_query([
44
            'from'    => $this->from,
45
            'to'      => $this->to,
46
            'subject' => $this->subject,
47
            'text'    => $content
48
        ]);
49
50
        $ch = curl_init();
51
52
        curl_setopt($ch, CURLOPT_URL, "https://{$this->host}/{$this->version}/{$this->domain}/messages");
53
        curl_setopt($ch, CURLOPT_POST, 1);
54
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
55
            "Authorization: Basic ".$auth
56
        ]);
57
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
58
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
59
60
        curl_exec($ch);
61
        curl_close($ch);
62
    }
63
}
64