DoctrinePersistActionExecutor::execute()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.4286
cc 3
eloc 10
nc 4
nop 1
crap 3
1
<?php
2
3
namespace Thruster\Bundle\DoctrineActionsBundle;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\Bundle\DoctrineBundle\Registry;
7
use Thruster\Action\DoctrineActions\DoctrinePersistActionExecutor as BaseDoctrinePersistActionExecutor;
8
9
/**
10
 * Class DoctrinePersistActionExecutor
11
 *
12
 * @package Thruster\Bundle\DoctrineActionsBundle
13
 * @author  Aurimas Niekis <[email protected]>
14
 */
15
class DoctrinePersistActionExecutor extends BaseDoctrinePersistActionExecutor
16
{
17
    /**
18
     * @var Registry
19
     */
20
    protected $registry;
21
22
    /**
23
     * @param Registry $registry
24
     */
25 2
    public function __construct(Registry $registry)
26
    {
27 2
        $this->registry = $registry;
28 2
    }
29
30
    /**
31
     * @param string $name
32
     *
33
     * @return EntityManager
34
     */
35 2
    public function getEntityManagerByName(string $name) : EntityManager
36
    {
37 2
        return $this->registry->getManager($name);
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 2
    public function execute(array $arguments) : array
44
    {
45 2
        $entityManagerName = 'default';
46 2
        $firstArgument     = reset($arguments);
47
48 2
        if (is_string($firstArgument)) {
49 1
            $entityManagerName = array_shift($arguments);
50
        }
51
52 2
        $entityManager = $this->getEntityManagerByName($entityManagerName);
53
54 2
        foreach ($arguments as $argument) {
55 2
            $entityManager->persist($argument);
56
        }
57
58 2
        $entityManager->flush();
59
60 2
        return $arguments;
61
    }
62
}
63