AuraSqlSlaveDbInterceptor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 10
c 2
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 9 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\Sql\ConnectionLocatorInterface;
8
use Ray\Aop\MethodInterceptor;
9
use Ray\Aop\MethodInvocation;
10
use ReflectionProperty;
11
12
class AuraSqlSlaveDbInterceptor implements MethodInterceptor
13
{
14
    /**
15
     * DB property name
16
     */
17
    public const PROP = 'pdo';
18
19
    private ConnectionLocatorInterface $connectionLocator;
20
21
    public function __construct(ConnectionLocatorInterface $connectionLocator)
22
    {
23
        $this->connectionLocator = $connectionLocator;
24
    }
25
26
    /**
27
     * {@inheritDoc}
28
     */
29
    public function invoke(MethodInvocation $invocation)
30
    {
31
        $object = $invocation->getThis();
32
        $ref = new ReflectionProperty($object, self::PROP);
33
        $ref->setAccessible(true);
34
        $connection = $this->connectionLocator->getRead();
35
        $ref->setValue($object, $connection);
36
37
        return $invocation->proceed();
38
    }
39
}
40