Completed
Pull Request — master (#66)
by Shingo
01:49 queued 28s
created

SendGrid   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 3
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(new \Swift_Image($params, SendgridTransport::SMTP_API_NAME));
0 ignored issues
show
Bug introduced by
It seems like $params defined by parameter $params on line 16 can also be of type array; however, Swift_Image::__construct() does only seem to accept string|object<Swift_OutputByteStream>|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

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