Completed
Push — master ( 78b797...accf5c )
by Shingo
11s
created

SendGrid::mailDriver()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
namespace Sichikawa\LaravelSendgridDriver;
4
5
use Illuminate\Mail\Mailable;
6
use Sichikawa\LaravelSendgridDriver\Transport\SendgridTransport;
7
use Swift_Message;
8
9
trait SendGrid
10
{
11
12
    /**
13
     * @param null|array $params
14
     * @return $this
15
     */
16
    public function sendgrid($params)
17
    {
18
        if ($this instanceof Mailable && $this->mailDriver() == "sendgrid") {
19
            $this->withSwiftMessage(function (Swift_Message $message) use ($params) {
20
                $message->embed(\Swift_Image::newInstance($params, SendgridTransport::SMTP_API_NAME));
0 ignored issues
show
Bug introduced by
The method newInstance() does not seem to exist on object<Swift_Image>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
            });
22
        }
23
        return $this;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    private function mailDriver()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
30
    {
31
        return function_exists('config') ? config('mail.driver') : env('MAIL_DRIVER');
32
    }
33
}
34