DoctrineODMMongoDBSession   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A executeAtomically() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorUser\CarlosBuenosvinosDddBridge\Infrastructure\Application\Service;
14
15
use Ddd\Application\Service\TransactionalSession;
16
use Doctrine\Common\Persistence\ObjectManager;
17
18
/**
19
 * Class Doctrine ODM MongoDB session class.
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class DoctrineODMMongoDBSession implements TransactionalSession
24
{
25
    /**
26
     * The document manager.
27
     *
28
     * @var ObjectManager
29
     */
30
    private $documentManager;
31
32
    /**
33
     * Constructor.
34
     *
35
     * @param ObjectManager $documentManager The document manager
36
     */
37
    public function __construct(ObjectManager $documentManager)
38
    {
39
        $this->documentManager = $documentManager;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function executeAtomically(callable $operation)
46
    {
47
        $result = call_user_func($operation);
48
        $this->documentManager->flush();
49
50
        return $result;
51
    }
52
}
53