Passed
Push — support-php-8.2-8.3 ( ae3b12...8c2247 )
by Akihito
01:21
created

AuraSqlSlaveDbInterceptor::invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
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
     * {@inheritDoc}
26
     */
27
    #[Override]
28
    public function invoke(MethodInvocation $invocation)
29
    {
30
        $object = $invocation->getThis();
31
        $ref = new ReflectionProperty($object, self::PROP);
32
        $connection = $this->connectionLocator->getRead();
33
        $ref->setValue($object, $connection);
34
35
        return $invocation->proceed();
36
    }
37
}
38