Completed
Push — 1.x ( 77936e...e60590 )
by Akihito
27:35 queued 25:37
created

AuraSqlReplicationDbProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the Ray.AuraSqlModule package
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\AuraSqlModule;
8
9
use Aura\Sql\ConnectionLocatorInterface;
10
use Ray\Di\InjectorInterface;
11
use Ray\Di\ProviderInterface;
12
use Ray\Di\SetContextInterface;
13
14
class AuraSqlReplicationDbProvider implements ProviderInterface, SetContextInterface
15
{
16
    /**
17
     * @var InjectorInterface
18
     */
19
    private $injector;
20
21
    /**
22
     * @var ConnectionLocatorInterface
23
     */
24
    private $connectionLocator;
25
26
    /**
27
     * @param ConnectionLocatorInterface $connectionLocator
0 ignored issues
show
Bug introduced by
There is no parameter named $connectionLocator. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     */
29 9
    public function __construct(InjectorInterface $injector)
30
    {
31 9
        $this->injector = $injector;
32 9
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 9
    public function setContext($context)
38
    {
39 9
        $this->connectionLocator = $this->injector->getInstance(ConnectionLocatorInterface::class, $context);
40 9
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 9
    public function get()
0 ignored issues
show
Coding Style introduced by
get uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
46
    {
47 9
        $isGetRequest = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET';
48 9
        $pdo = $isGetRequest ? $this->connectionLocator->getRead() : $this->connectionLocator->getWrite();
49
50 9
        return $pdo;
51
    }
52
}
53