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

SendGrid   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 2
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendgrid() 0 9 3
A mailDriver() 0 4 2
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