Completed
Push — 1.x ( 249f8e...9ce618 )
by Akihito
11s
created

AuraSqlSlaveDbInterceptor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 23
ccs 5
cts 5
cp 1
rs 10
wmc 2

2 Methods

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