PDOConnector::make()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace MuhmdRaouf\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
        $driver = $configs['driver'];
17
        $host = $configs['host'] ?? '127.0.0.1';
18
        $username = $configs['username'];
19
        $password = $configs['password'];
20
21
        $host = "$driver:host=$host";
22
        $pdo = new PDO($host, $username, $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