InvoiceEmailManager::sendInvoiceEmail()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitBag\SyliusInvoicingPlugin\EmailManager;
6
7
use BitBag\SyliusInvoicingPlugin\Repository\InvoiceRepositoryInterface;
8
use Sylius\Component\Core\Model\OrderInterface;
9
use Sylius\Component\Core\Model\PaymentInterface;
10
use Sylius\Component\Mailer\Sender\SenderInterface;
11
12
final class InvoiceEmailManager implements InvoiceEmailManagerInterface
13
{
14
    /** @var SenderInterface */
15
    private $emailSender;
16
17
    /** @var InvoiceRepositoryInterface */
18
    private $invoiceRepository;
19
20
    public function __construct(SenderInterface $emailSender, InvoiceRepositoryInterface $invoiceRepository)
21
    {
22
        $this->emailSender = $emailSender;
23
        $this->invoiceRepository = $invoiceRepository;
24
    }
25
26
    public function sendInvoiceEmail(PaymentInterface $payment): void
27
    {
28
        /** @var OrderInterface $order */
29
        $order = $payment->getOrder();
30
31
        if (!$this->invoiceRepository->findByOrderId($order->getId())) {
32
            return;
33
        }
34
35
        $email = $order->getCustomer()->getEmail();
36
37
        $this->emailSender->send(self::INVOICE_EMAIL, [$email], ['order' => $order]);
38
    }
39
}
40