Completed
Push — master ( 5a0a25...383c62 )
by Matteo
02:38
created

Database   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 2
cbo 4
dl 0
loc 72
rs 10
ccs 0
cts 23
cp 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A collection() 0 4 1
A getOrCreateCollection() 0 8 2
A createCollection() 0 6 1
A dropCollection() 0 7 1
A getParser() 0 4 1
A initializeParser() 0 5 1
1
<?php
2
3
namespace Mattbit\Flat;
4
5
use Mattbit\Flat\Query\Expression\Factory;
6
use Mattbit\Flat\Query\Parser;
7
use Mattbit\Flat\Storage\Engine;
8
9
class Database
10
{
11
    /**
12
     * The storage engine.
13
     *
14
     * @var Engine
15
     */
16
    protected $engine;
17
18
    protected $parser;
19
20
    /**
21
     * An array of the registered collections.
22
     *
23
     * @var array
24
     */
25
    protected $collections;
26
27
    public function __construct(Engine $engine)
28
    {
29
        $this->engine = $engine;
30
31
        $this->initializeParser();
32
    }
33
34
    /**
35
     * Select an existing collection or create a new one.
36
     *
37
     * @param string $name
38
     *
39
     * @return Collection
40
     */
41
    public function collection($name)
42
    {
43
        return $this->getOrCreateCollection($name);
44
    }
45
46
    public function getOrCreateCollection($name)
47
    {
48
        if (isset($this->collections[$name])) {
49
            return $this->collections[$name];
50
        }
51
52
        return $this->createCollection($name);
53
    }
54
55
    public function createCollection($name)
56
    {
57
        $store = $this->engine->createDocumentStore($name);
58
59
        return $this->collections[$name] = new Collection($this, $store, $name);
60
    }
61
62
    public function dropCollection($name)
63
    {
64
        $this->engine->removeCollection($name);
0 ignored issues
show
Bug introduced by
The method removeCollection() does not exist on Mattbit\Flat\Storage\Engine. Did you maybe mean remove()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
65
        unset($this->collections[$name]);
66
67
        return true;
68
    }
69
70
    public function getParser()
71
    {
72
        return $this->parser;
73
    }
74
    
75
    protected function initializeParser()
76
    {
77
        $factory = new Factory();
78
        $this->parser = new Parser($factory);
79
    }
80
}
81