Passed
Pull Request — master (#105)
by
unknown
07:45
created

ChangePositionPaymentMethodAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
rs 10
c 1
b 0
f 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 Doctrine\Common\Persistence\ObjectManager;
0 ignored issues
show
Bug introduced by
The type Doctrine\Common\Persistence\ObjectManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Sylius\Component\Resource\Repository\RepositoryInterface;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpFoundation\Response;
19
20
final class ChangePositionPaymentMethodAction
21
{
22
    /** @var RepositoryInterface */
23
    private $mollieGatewayRepository;
24
25
    /** @var ObjectManager */
26
    private $mollieGatewayObjectManager;
27
28
    public function __construct(
29
        RepositoryInterface $mollieGatewayRepository,
30
        ObjectManager $mollieGatewayObjectManager
31
    ) {
32
        $this->mollieGatewayRepository = $mollieGatewayRepository;
33
        $this->mollieGatewayObjectManager = $mollieGatewayObjectManager;
34
    }
35
36
    public function __invoke(Request $request): Response
37
    {
38
        $positions = $request->get('positions');
39
40
        foreach ($positions as $position) {
41
            $method = $this->mollieGatewayRepository->findOneBy(['methodId' => $position['name']]);
42
            if ($method instanceof MollieGatewayConfigInterface and isset($position['id'])) {
43
                $method->setPosition($position['id']);
44
45
                $this->mollieGatewayObjectManager->persist($method);
46
            }
47
        }
48
49
        $this->mollieGatewayObjectManager->flush();
50
51
        return new Response('OK');
52
    }
53
}
54