PDOConnector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A make() 0 12 1
A exec() 0 4 1
1
<?php
2
3
namespace Tonysm\LaravelParatest\Database;
4
5
use PDO;
6
7
class PDOConnector implements Connector
8
{
9
    public function __construct(PDO $pdo)
10
    {
11
        $this->pdo = $pdo;
0 ignored issues
show
Bug introduced by
The property pdo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
12
    }
13
14
    public static function make(array $configs): PDOConnector
15
    {
16
        $host = sprintf(
17
            '%s:host=%s',
18
            $configs['driver'],
19
            $configs['host'] ?? '127.0.0.1'
20
        );
21
22
        $pdo = new PDO($host, $configs['username'], $configs['password']);
23
24
        return new static($pdo);
25
    }
26
27
    /**
28
     * @param string $sql
29
     *
30
     * @return mixed whatever the actual implementation returns, depending on the connector
31
     */
32
    public function exec(string $sql)
33
    {
34
        return $this->pdo->exec($sql);
35
    }
36
}
37
38