RefundPaymentGeneratedAutoCompleteListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 2
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 2
A __construct() 0 8 1
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\EventListener;
13
14
use BitBag\SyliusMolliePlugin\Factory\MollieGatewayFactory;
15
use BitBag\SyliusMolliePlugin\Repository\PaymentMethodRepositoryInterface;
16
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
17
use Sylius\Component\Core\Model\PaymentMethodInterface;
18
use Sylius\RefundPlugin\Entity\RefundPaymentInterface;
19
use Sylius\RefundPlugin\Event\RefundPaymentGenerated;
20
use Sylius\RefundPlugin\StateResolver\RefundPaymentCompletedStateApplierInterface;
21
22
final class RefundPaymentGeneratedAutoCompleteListener
23
{
24
    /** @var EntityRepository */
25
    private $refundPaymentRepository;
26
27
    /** @var RefundPaymentCompletedStateApplierInterface */
28
    private $refundPaymentCompletedStateApplier;
29
30
    /** @var PaymentMethodRepositoryInterface */
31
    private $paymentMethodRepository;
32
33
    public function __construct(
34
        EntityRepository $refundPaymentInterface,
35
        RefundPaymentCompletedStateApplierInterface $refundPaymentCompletedStateApplier,
36
        PaymentMethodRepositoryInterface $paymentMethodRepository
37
    ) {
38
        $this->refundPaymentRepository = $refundPaymentInterface;
39
        $this->refundPaymentCompletedStateApplier = $refundPaymentCompletedStateApplier;
40
        $this->paymentMethodRepository = $paymentMethodRepository;
41
    }
42
43
    public function __invoke(RefundPaymentGenerated $refundPaymentGenerated): void
44
    {
45
        /** @var PaymentMethodInterface $paymentMethod */
46
        $paymentMethod = $this->paymentMethodRepository->find($refundPaymentGenerated->paymentMethodId());
47
48
        if (MollieGatewayFactory::FACTORY_NAME !== $paymentMethod->getGatewayConfig()->getFactoryName()) {
0 ignored issues
show
Deprecated Code introduced by
The function Payum\Core\Model\Gateway...rface::getFactoryName() has been deprecated: since 1.3.3 will be removed in 2.0. set factory option inside the config ( Ignorable by Annotation )

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

48
        if (MollieGatewayFactory::FACTORY_NAME !== /** @scrutinizer ignore-deprecated */ $paymentMethod->getGatewayConfig()->getFactoryName()) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
49
            return;
50
        }
51
52
        /** @var RefundPaymentInterface $refundPayment */
53
        $refundPayment = $this->refundPaymentRepository->find($refundPaymentGenerated->id());
54
55
        $this->refundPaymentCompletedStateApplier->apply($refundPayment);
56
    }
57
}
58