PaymentLinkEmailPreparer::prepare()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 2
nc 2
nop 2
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\Preparer;
13
14
use BitBag\SyliusMolliePlugin\EmailSender\PaymentLinkEmailSenderInterface;
15
use BitBag\SyliusMolliePlugin\Entity\TemplateMollieEmailTranslationInterface;
16
use Liip\ImagineBundle\Exception\Config\Filter\NotFoundException;
17
use Sylius\Component\Core\Model\OrderInterface;
18
use Sylius\Component\Resource\Repository\RepositoryInterface;
19
20
final class PaymentLinkEmailPreparer implements PaymentLinkEmailPreparerInterface
21
{
22
    /** @var RepositoryInterface */
23
    private $templateRepository;
24
25
    /** @var PaymentLinkEmailSenderInterface */
26
    private $emailSender;
27
28
    public function __construct(RepositoryInterface $templateRepository, PaymentLinkEmailSenderInterface $emailSender)
29
    {
30
        $this->templateRepository = $templateRepository;
31
        $this->emailSender = $emailSender;
32
    }
33
34
    public function prepare(OrderInterface $order, string $templateName): void
35
    {
36
        $locale = $order->getLocaleCode();
37
38
        /** @var TemplateMollieEmailTranslationInterface $template */
39
        $template = $this->templateRepository->findOneByLocaleCodeAdnType(
0 ignored issues
show
Bug introduced by
The method findOneByLocaleCodeAdnType() does not exist on Sylius\Component\Resourc...ory\RepositoryInterface. Did you maybe mean findOneBy()? ( Ignorable by Annotation )

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

39
        /** @scrutinizer ignore-call */ 
40
        $template = $this->templateRepository->findOneByLocaleCodeAdnType(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
            $locale,
41
            $templateName
42
        );
43
44
        if (null === $template) {
45
            throw new NotFoundException(\sprintf('Not payment link template found, or not translation added'));
46
        }
47
48
        $this->emailSender->sendConfirmationEmail($order, $template);
49
    }
50
}
51