Passed
Push — master ( 66351d...335aef )
by Hirofumi
20:01
created

EmailGateway::sendsToDestination()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Infrastructure\Domain\Model;
5
6
use Shippinno\Email\EmailNotSentException;
7
use Shippinno\Email\SendEmail;
8
use Shippinno\Notification\Domain\Model\Destination;
9
use Shippinno\Notification\Domain\Model\EmailDestination;
10
use Shippinno\Notification\Domain\Model\Gateway;
11
use Shippinno\Notification\Domain\Model\Notification;
12
use Shippinno\Notification\Domain\Model\NotificationNotSentException;
13
use Tanigami\ValueObjects\Web\Email;
14
use Tanigami\ValueObjects\Web\EmailAddress;
15
use Verraes\ClassFunctions\ClassFunctions;
16
17
class EmailGateway extends Gateway
18
{
19
    /**
20
     * @var SendEmail
21
     */
22
    private $sendEmail;
23
24
    /**
25
     * @var EmailAddress
26
     */
27
    private $from;
28
29
    /**
30
     * @param SendEmail $sendEmail
31
     * @param EmailAddress $from
32
     */
33 3
    public function __construct(SendEmail $sendEmail, EmailAddress $from)
34
    {
35 3
        $this->sendEmail = $sendEmail;
36 3
        $this->from = $from;
37 3
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 2
    protected function doSend(Notification $notification): void
43
    {
44
        /** @var EmailDestination $destination */
45 2
        $destination = $notification->destination();
46 2
        $email = new Email(
47 2
            $notification->subject()->subject(),
48 2
            $notification->body()->body(),
49 2
            $this->from,
50 2
            $destination->to(),
51 2
            $destination->cc(),
52 2
            $destination->bcc()
53
        );
54
        try {
55 2
            $this->sendEmail->execute($email);
56 1
        } catch (EmailNotSentException $e) {
57 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...
58
        }
59 1
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 3
    public function sendsToDestination(Destination $destination): bool
65
    {
66 3
        return $destination instanceof EmailDestination;
67
    }
68
}
69