Completed
Push — master ( d07036...3c918f )
by Mikołaj
04:05
created

InvoiceEmailManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A sendInvoiceEmail() 0 13 2
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