DoctrinePersistActionExecutor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 48
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getEntityManagerByName() 0 4 1
A execute() 0 19 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