SimpleTransactionalProxy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 26
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __call() 0 10 1
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