Completed
Push — 1.1 ( c1f72e...de6a6c )
by Patrick
04:19
created

Table::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Builders;
4
5
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
6
use LaravelDoctrine\Fluent\Buildable;
7
use LaravelDoctrine\Fluent\Builders\Traits\Queueable;
8
9
class Table extends AbstractBuilder implements Buildable
10
{
11
    use Queueable {
12
        build as buildQueued;
13
    }
14
15
    /**
16
     * @var array
17
     */
18
    protected $primaryTable = [];
19
20
    /**
21
     * @param ClassMetadataBuilder $builder
22
     * @param string|callable|null $name
23
     */
24 13
    public function __construct(ClassMetadataBuilder $builder, $name = null)
25
    {
26 13
        parent::__construct($builder);
27
28 13
        if (is_callable($name)) {
29 2
            $name($this);
30 2
        } else {
31 13
            $this->setName($name);
32
        }
33 13
    }
34
35
    /**
36
     * @param string $name
37
     *
38
     * @return $this
39
     */
40 13
    public function setName($name)
41
    {
42 13
        $this->builder->setTable($name);
43
44 13
        return $this;
45
    }
46
47
    /**
48
     * @param string $schema
49
     *
50
     * @return $this
51
     */
52 3
    public function schema($schema)
53
    {
54 3
        $this->primaryTable['schema'] = $schema;
55
56 3
        return $this;
57
    }
58
59
    /**
60
     * @param string $charset
61
     *
62
     * @return $this
63
     */
64 2
    public function charset($charset)
65
    {
66 2
        $this->option('charset', $charset);
67
68 2
        return $this;
69
    }
70
71
    /**
72
     * @param string $collate
73
     *
74
     * @return $this
75
     */
76 2
    public function collate($collate)
77
    {
78 2
        $this->option('collate', $collate);
79
80 2
        return $this;
81
    }
82
83
    /**
84
     * @param array $options
85
     *
86
     * @return $this
87
     */
88 3
    public function options(array $options = [])
89
    {
90 3
        $this->primaryTable['options'] = $options;
91
92 3
        return $this;
93
    }
94
95
    /**
96
     * @param string $name
97
     * @param string $value
98
     *
99
     * @return $this
100
     */
101 3
    public function option($name, $value)
102
    {
103 3
        $this->primaryTable['options'][$name] = $value;
104
105 3
        return $this;
106
    }
107
108
    /**
109
     * Execute the build process
110
     */
111 7
    public function build()
112
    {
113 7
        $this->builder->getClassMetadata()->setPrimaryTable($this->primaryTable);
114 7
    }
115
}
116