Database::getSchema()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace mindplay\sql\model;
4
5
use mindplay\sql\model\query\SQLQuery;
6
use mindplay\sql\model\schema\Schema;
7
8
/**
9
 * This class implements the primary public API of the database model.
10
 */
11
abstract class Database
12
{
13
    protected DatabaseContainer $container;
14
15
    /**
16
     * The typical use-case is to omit the `$factory` argument - it exists primarily for
17
     * mocking and dependency-injection under test.
18
     *
19
     * @param DatabaseContainerFactory|null $factory custom factory instance (typically omitted)
20
     */
21 1
    public function __construct(DatabaseContainerFactory|null $factory = null)
22
    {
23 1
        if ($factory === null) {
24 1
            $factory = new DatabaseContainerFactory();
25
        }
26
27 1
        $this->bootstrap($factory);
28
29 1
        $this->container = $factory->createContainer();
30
    }
31
32
    abstract protected function bootstrap(DatabaseContainerFactory $factory): void;
33
34
    /**
35
     * @param class-string $schema Schema class type-name
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
36
     */
37 1
    public function getSchema(string $schema): Schema
38
    {
39 1
        return $this->container->getSchema($schema);
40
    }
41
    
42 1
    public function sql(string $sql): SQLQuery
43
    {
44 1
        return $this->container->create(SQLQuery::class, ['sql' => $sql]);
45
    }
46
}
47