Completed
Push — master ( d8dd7c...fad061 )
by Rasmus
03:55 queued 01:13
created

Database   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 49
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
bootstrap() 0 1 ?
A getSchema() 0 4 1
A sql() 0 4 1
1
<?php
2
3
namespace mindplay\sql\model;
4
5
use mindplay\sql\model\query\SQLQuery;
6
use mindplay\sql\model\schema\Schema;
7
use UnexpectedValueException;
8
9
/**
10
 * This class implements the primary public API of the database model.
11
 */
12
abstract class Database
13
{
14
    /**
15
     * @var DatabaseContainer
16
     */
17
    protected $container;
18
19
    /**
20
     * The typical use-case is to omit the `$factory` argument - it exists primarily for
21
     * mocking and dependency-injection under test.
22
     *
23
     * @param DatabaseContainerFactory|null $factory custom factory instance (typically omitted)
24
     */
25 1
    public function __construct(DatabaseContainerFactory $factory = null)
26
    {
27 1
        if ($factory === null) {
28 1
            $factory = new DatabaseContainerFactory();
29
        }
30
31 1
        $this->bootstrap($factory);
32
33 1
        $this->container = $factory->createContainer();
34 1
    }
35
36
    /**
37
     * @return DatabaseContainer
38
     */
39
    abstract protected function bootstrap(DatabaseContainerFactory $factory);
40
41
    /**
42
     * @param string Schema class-name
43
     *
44
     * @return Schema
45
     */
46 1
    public function getSchema($schema)
47
    {
48 1
        return $this->container->getSchema($schema);
49
    }
50
    
51
    /**
52
     * @param string $sql
53
     * 
54
     * @return SQLQuery
55
     */
56 1
    public function sql($sql)
57
    {
58 1
        return $this->container->create(SQLQuery::class, ['sql' => $sql]);
59
    }
60
}
61