Passed
Push — master ( b9ffdf...6f7a22 )
by Hirofumi
04:56
created

EmailGateway::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Shippinno\Notification\Infrastructure\Domain\Model;
4
5
use InvalidArgumentException;
6
use Shippinno\Email\EmailNotSentException;
7
use Shippinno\Email\SendEmail;
8
use Shippinno\Notification\Domain\Model\EmailDestination;
9
use Shippinno\Notification\Domain\Model\Gateway;
10
use Shippinno\Notification\Domain\Model\Notification;
11
use Shippinno\Notification\Domain\Model\NotificationNotSentException;
12
use Tanigami\ValueObjects\Web\Email;
13
use Tanigami\ValueObjects\Web\EmailAddress;
14
15
class EmailGateway extends Gateway
16
{
17
    /**
18
     * @var SendEmail
19
     */
20
    private $sendEmail;
21
22
    /**
23
     * @var EmailAddress
24
     */
25
    private $from;
26
27
    /**
28
     * @param SendEmail $sendEmail
29
     * @param EmailAddress $from
30
     */
31 3
    public function __construct(SendEmail $sendEmail, EmailAddress $from)
32
    {
33 3
        $this->sendEmail = $sendEmail;
34 3
        $this->from = $from;
35 3
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 2
    protected function doSend(Notification $notification): void
41
    {
42
        /** @var EmailDestination $destination */
43 2
        $destination = $notification->destination();
44 2
        $email = new Email(
45 2
            $notification->subject()->subject(),
46 2
            $notification->body()->body(),
47 2
            $this->from,
48 2
            $destination->to(),
49 2
            $destination->cc(),
50 2
            $destination->bcc()
51
        );
52
        try {
53 2
            $this->sendEmail->execute($email);
54 1
        } catch (EmailNotSentException $e) {
55 1
            throw new NotificationNotSentException($notification, $e);
1 ignored issue
show
Documentation introduced by
$e is of type object<Shippinno\Email\EmailNotSentException>, but the function expects a null|object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        }
57 1
    }
58
59
    /**
60
     * @return string
61
     */
62 3
    public function destinationType(): string
63
    {
64 3
        return EmailDestination::class;
65
    }
66
}
67