Passed
Push — master ( 5cf396...db4681 )
by
unknown
11:56 queued 04:44
created

MolliePaymentMethodPurifier   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 23
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A removeAllNoLongerSupportedMethods() 0 4 2
A removeMethod() 0 6 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\Purifier;
13
14
use BitBag\SyliusMolliePlugin\Creator\MollieMethodsCreatorInterface;
15
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface;
16
use Sylius\Component\Resource\Repository\RepositoryInterface;
17
18
final class MolliePaymentMethodPurifier implements MolliePaymentMethodPurifierInterface
19
{
20
    /** @var RepositoryInterface */
21
    private $repository;
22
23
    public function __construct(RepositoryInterface $repository)
24
    {
25
        $this->repository = $repository;
26
    }
27
28
    public function removeAllNoLongerSupportedMethods(): void
29
    {
30
        foreach (MollieMethodsCreatorInterface::UNSUPPORTED_METHODS as $methodId) {
31
            $this->removeMethod($methodId);
32
        }
33
    }
34
35
    public function removeMethod(string $methodId): void
36
    {
37
        $methodConfig = $this->repository->findOneBy(['methodId' => $methodId]);
38
39
        if ($methodConfig instanceof MollieGatewayConfigInterface) {
40
            $this->repository->remove($methodConfig);
41
        }
42
    }
43
}
44