Issues (56)

src/AuraSqlReplicationDbProvider.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\Sql\ConnectionLocatorInterface;
8
use Aura\Sql\ExtendedPdoInterface;
9
use Override;
0 ignored issues
show
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Ray\Di\InjectorInterface;
11
use Ray\Di\ProviderInterface;
12
use Ray\Di\SetContextInterface;
13
14
/** @implements ProviderInterface<ExtendedPdoInterface> */
15
final class AuraSqlReplicationDbProvider implements ProviderInterface, SetContextInterface
16
{
17
    private string $context = '';
18
19
    public function __construct(private readonly InjectorInterface $injector)
20
    {
21
    }
22
23
    /**
24
     * {@inheritDoc}
25
     *
26
     * @param string $context
27
     */
28
    #[Override]
29
    public function setContext($context): void
30
    {
31
        $this->context = $context;
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    #[Override]
38
    public function get(): ExtendedPdoInterface
39
    {
40
        $connectionLocator = $this->injector->getInstance(ConnectionLocatorInterface::class, $this->context);
41
        $isGetRequest = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET';
42
43
        return $isGetRequest ? $connectionLocator->getRead() : $connectionLocator->getWrite();
44
    }
45
}
46