DeletePaymentMethodImage   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A __invoke() 0 19 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\Controller\Action\Admin;
13
14
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface;
15
use BitBag\SyliusMolliePlugin\Entity\MollieMethodImageInterface;
16
use BitBag\SyliusMolliePlugin\Logger\MollieLoggerActionInterface;
17
use BitBag\SyliusMolliePlugin\Uploader\PaymentMethodLogoUploaderInterface;
18
use Doctrine\ORM\EntityManagerInterface;
19
use Sylius\Component\Resource\Repository\RepositoryInterface;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22
23
final class DeletePaymentMethodImage
24
{
25
    /** @var PaymentMethodLogoUploaderInterface */
26
    private $logoUploader;
27
28
    /** @var RepositoryInterface */
29
    private $logoRepository;
30
31
    /** @var EntityManagerInterface */
32
    private $entityManager;
33
34
    /** @var MollieLoggerActionInterface */
35
    private $loggerAction;
36
37
    public function __construct(
38
        PaymentMethodLogoUploaderInterface $logoUploader,
39
        RepositoryInterface $logoRepository,
40
        EntityManagerInterface $entityManager,
41
        MollieLoggerActionInterface $loggerAction
42
    ) {
43
        $this->logoUploader = $logoUploader;
44
        $this->logoRepository = $logoRepository;
45
        $this->entityManager = $entityManager;
46
        $this->loggerAction = $loggerAction;
47
    }
48
49
    public function __invoke(Request $request): Response
50
    {
51
        $methodName = $request->request->get('method');
52
53
        /** @var MollieGatewayConfigInterface $mollieGateway */
54
        $mollieGateway = $this->logoRepository->findOneBy(['name' => $methodName]);
55
56
        /** @var MollieMethodImageInterface $customizeMethodImage */
57
        $customizeMethodImage = $mollieGateway->getCustomizeMethodImage();
58
59
        $this->logoUploader->remove($customizeMethodImage->getPath());
0 ignored issues
show
Bug introduced by
It seems like $customizeMethodImage->getPath() can also be of type null; however, parameter $path of BitBag\SyliusMolliePlugi...aderInterface::remove() 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

59
        $this->logoUploader->remove(/** @scrutinizer ignore-type */ $customizeMethodImage->getPath());
Loading history...
60
        $mollieGateway->setCustomizeMethodImage(null);
61
62
        $this->entityManager->persist($mollieGateway);
63
        $this->entityManager->flush();
64
65
        $this->loggerAction->addLog(sprintf('Deleted image from method'));
66
67
        return new Response(Response::$statusTexts[Response::HTTP_OK], Response::HTTP_OK);
68
    }
69
}
70