AuraSqlMasterDbInterceptor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A invoke() 0 10 1
1
<?php
2
/**
3
 * This file is part of the Ray.AuraSqlModule package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\AuraSqlModule;
8
9
use Aura\Sql\ConnectionLocatorInterface;
10
use Ray\Aop\MethodInterceptor;
11
use Ray\Aop\MethodInvocation;
12
13
class AuraSqlMasterDbInterceptor implements MethodInterceptor
14
{
15
    const PROP = 'pdo';
16
17
    /**
18
     * @var ConnectionLocatorInterface
19
     */
20
    private $connectionLocator;
21
22
    /**
23
     * @param ConnectionLocatorInterface $connectionLocator
24
     */
25 3
    public function __construct(ConnectionLocatorInterface $connectionLocator)
26
    {
27 3
        $this->connectionLocator = $connectionLocator;
28 3
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 2
    public function invoke(MethodInvocation $invocation)
34
    {
35 2
        $object = $invocation->getThis();
36 2
        $ref = new \ReflectionProperty($object, self::PROP);
37 2
        $ref->setAccessible(true);
38 2
        $connection = $this->connectionLocator->getWrite();
39 2
        $ref->setValue($object, $connection);
40
41 2
        return $invocation->proceed();
42
    }
43
}
44