SimpleTransactionalProxy::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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
 * @author Philip Washington Sorst <[email protected]>
12
 */
13
class SimpleTransactionalProxy
14
{
15
    private $service;
16
17
    /**
18
     * @var TransactionManager
19
     */
20
    private $transactionManager;
21
22
    public function __construct($service, EntityManagerInterface $entityManager)
23
    {
24
        $this->service = $service;
25
        $this->transactionManager = new TransactionManager($entityManager);
26
    }
27
28
    public function __call($method, $args)
29
    {
30
        $callback = [$this->service, $method];
31
32
        return $this->transactionManager->transactional(
33
            function () use ($callback, $args) {
34
                return call_user_func_array($callback, $args);
35
            }
36
        );
37
    }
38
}
39