Completed
Push — master ( 8fee6e...874644 )
by Philip
24:56
created

SimpleTransactionalProxy::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Dontdrinkandroot\Service;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Dontdrinkandroot\Repository\TransactionManager;
7
8
/**
9
 * Quick'n'Dirty Proxy.
10
 */
11
class SimpleTransactionalProxy
12
{
13
14
    private $service;
15
16
    /**
17
     * @var TransactionManager
18
     */
19
    private $transactionManager;
20
21
    public function __construct($service, EntityManagerInterface $entityManager)
22
    {
23
        $this->service = $service;
24
        $this->transactionManager = new TransactionManager($entityManager);
25
    }
26
27
    public function __call($method, $args)
28
    {
29
        $callback = array($this->service, $method);
30
31
        return $this->transactionManager->transactional(
32
            function () use ($callback, $args) {
33
                return call_user_func_array($callback, $args);
34
            }
35
        );
36
    }
37
}
38