Completed
Pull Request — master (#66)
by Shingo
01:49 queued 28s
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(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