Passed
Pull Request — 1.x (#88)
by Akihito
01:23
created

AuraSqlMasterDbInterceptor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A invoke() 0 9 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 AuraSqlMasterDbInterceptor implements MethodInterceptor
14
{
15
    public const PROP = 'pdo';
16
17
    public function __construct(private ConnectionLocatorInterface $connectionLocator)
18
    {
19
    }
20
21
    /**
22
     * {@inheritDoc}
23
     */
24
    #[Override]
25 3
    public function invoke(MethodInvocation $invocation)
26
    {
27 3
        $object = $invocation->getThis();
28 3
        $ref = new ReflectionProperty($object, self::PROP);
29
        $connection = $this->connectionLocator->getWrite();
30
        $ref->setValue($object, $connection);
31
32
        return $invocation->proceed();
33 2
    }
34
}
35