Completed
Branch 7-dev (bf2895)
by Oscar
03:53
created

Scheme::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace SimpleCrud\Scheme;
5
6
use PDO;
7
8
/**
9
 * Class to autodetect the scheme
10
 */
11
final class Scheme implements SchemeInterface
12
{
13
    private $engine;
14
15
    public function __construct(PDO $pdo)
16
    {
17
        $engine = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
18
19
        switch ($engine) {
20
            case 'mysql':
21
                $this->scheme = new Mysql($pdo);
0 ignored issues
show
Bug introduced by
The property scheme 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...
22
                break;
23
            case 'sqlite':
24
                $this->scheme = new Sqlite($pdo);
25
                break;
26
            default:
27
                throw new RuntimeException(sprintf('Invalid engine type: %s', $engine));
28
        }
29
    }
30
31
    public function getTables(): array
32
    {
33
        return $this->scheme->getTables();
34
    }
35
36
    public function getTableFields(string $table): array
37
    {
38
        return $this->scheme->getTableFields($table);
39
    }
40
}
41