Completed
Pull Request — 1.1 (#35)
by Hidde
04:56
created

Table::option()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

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