Issues (220)

src/EmailSender/PaymentLinkEmailSender.php (1 issue)

Labels
Severity
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\EmailSender;
13
14
use BitBag\SyliusMolliePlugin\Entity\TemplateMollieEmailTranslationInterface;
15
use BitBag\SyliusMolliePlugin\Mailer\Emails;
16
use BitBag\SyliusMolliePlugin\Twig\Parser\ContentParserInterface;
17
use Sylius\Component\Core\Model\CustomerInterface;
18
use Sylius\Component\Core\Model\OrderInterface;
19
use Sylius\Component\Core\Model\PaymentInterface;
20
use Sylius\Component\Mailer\Sender\SenderInterface;
21
22
final class PaymentLinkEmailSender implements PaymentLinkEmailSenderInterface
23
{
24
    /** @var SenderInterface */
25
    private $emailSender;
26
27
    /** @var ContentParserInterface */
28
    private $contentParser;
29
30
    public function __construct(
31
        SenderInterface $emailSender,
32
        ContentParserInterface $contentParser
33
    ) {
34
        $this->emailSender = $emailSender;
35
        $this->contentParser = $contentParser;
36
    }
37
38
    public function sendConfirmationEmail(OrderInterface $order, TemplateMollieEmailTranslationInterface $template): void
39
    {
40
        /** @var PaymentInterface $payment */
41
        $payment = $order->getPayments()->last();
42
43
        if (empty($payment->getDetails())) {
44
            return;
45
        }
46
47
        $paymentLink = $payment->getDetails()['payment_mollie_link'];
48
        $content = $this->contentParser->parse($template->getContent(), $paymentLink);
0 ignored issues
show
It seems like $template->getContent() can also be of type null; however, parameter $input of BitBag\SyliusMolliePlugi...arserInterface::parse() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
        $content = $this->contentParser->parse(/** @scrutinizer ignore-type */ $template->getContent(), $paymentLink);
Loading history...
49
50
        /** @var CustomerInterface $customer */
51
        $customer = $order->getCustomer();
52
53
        $this->emailSender->send(Emails::PAYMENT_LINK, [$customer->getEmail()], [
54
            'order' => $order,
55
            'template' => $template,
56
            'content' => $content,
57
        ]);
58
    }
59
}
60