Passed
Pull Request — master (#130)
by
unknown
02:57
created

MailgunAdapter::sendMail()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 16
rs 9.8333
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.0
13
 */
14
15
namespace Quantum\Libraries\Mailer\Adapters;
16
17
use Quantum\Libraries\Mailer\MailerInterface;
18
use Quantum\Libraries\Curl\HttpClient;
19
20
class MailgunAdapter implements MailerInterface
21
{
22
    /**
23
     * Send mail by using Mailgun
24
     * @param  string $data
25
     * @return bool
26
     */
27
    public function sendMail($data)
28
    {
29
        try {
30
            $httpClient = new HttpClient();
31
            $httpClient->createMultiRequest()
32
                ->createRequest('https://api.mailgun.net/v3/' . config()->get('mailer.mailgun.domain') . '/messages')
33
                ->setMethod('POST')
34
                ->setHeaders([
0 ignored issues
show
Bug introduced by
The method setHeaders() does not exist on Quantum\Libraries\Curl\HttpClient. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
                ->/** @scrutinizer ignore-call */ setHeaders([
Loading history...
35
                    "Authorization" => "Basic " . base64_encode("api:" . config()->get('mailer.mailgun.api_key')),
36
                    "Content-Type" => "application/x-www-form-urlencoded"
37
                ])
38
                ->setData($data)
39
                ->start();
40
            return true;
41
        } catch (\Exception $e) {
42
            return false;
43
        }
44
    }
45
}
46