Completed
Push — master ( 1e949f...87ce65 )
by
unknown
05:29 queued 03:21
created

Builder::database()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkQL\Query;
5
6
use TBolier\RethinkQL\RethinkInterface;
7
8
class Builder implements BuilderInterface
9
{
10
    /**
11
     * @var RethinkInterface
12
     */
13
    private $rethink;
14
15
    /**
16
     * @var TableInterface
17
     */
18
    private $table;
19
20
    /**
21
     * @var DatabaseInterface
22
     */
23
    private $database;
24
25
    /**
26
     * @var MessageInterface
27
     */
28
    private $message;
29
30
    /**
31
     * @param RethinkInterface $rethink
32
     * @param MessageInterface $message
33
     */
34
    public function __construct(RethinkInterface $rethink, MessageInterface $message)
35
    {
36
        $this->rethink = $rethink;
37
        $this->message = $message;
38
    }
39
40
    /**
41
     * @param string $name
42
     * @return TableInterface
43
     */
44
    public function table(string $name): TableInterface
45
    {
46
        if ($this->table) {
47
            unset($this->table);
48
        }
49
50
        $this->table = new Table($name, $this->rethink, $this->message);
51
52
        return $this->table;
53
    }
54
55
    /**
56
     * @return DatabaseInterface
57
     */
58
    public function database(): DatabaseInterface
59
    {
60
        if ($this->database) {
61
            unset($this->database);
62
        }
63
64
        $this->database = new Database($this->rethink, $this->message);
65
66
        return $this->database;
67
    }
68
}
69