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

Table::option()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
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 10
    public function __construct(ClassMetadataBuilder $builder, $name = null)
20
    {
21 10
        parent::__construct($builder);
22
23 10
        if (is_callable($name)) {
24 2
            $name($this);
25 2
        } else {
26 10
            $this->setName($name);
27
        }
28 10
    }
29
30
    /**
31
     * @param string $name
32
     *
33
     * @return $this
34
     */
35 10
    public function setName($name)
36
    {
37 10
        $this->builder->setTable($name);
38
39 10
        return $this;
40
    }
41
42
    /**
43
     * @param string $schema
44
     *
45
     * @return $this
46
     */
47 2
    public function schema($schema)
48
    {
49 2
        $this->primaryTable['schema'] = $schema;
50
51 2
        return $this;
52
    }
53
54
    /**
55
     * @param string $charset
56
     *
57
     * @return $this
58
     */
59
    public function charset($charset)
60
    {
61
        $this->option('charset', $charset);
62
63
        return $this;
64
    }
65
66
    /**
67
     * @param string $collate
68
     *
69
     * @return $this
70
     */
71
    public function collate($collate)
72
    {
73
        $this->option('collate', $collate);
74
75
        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
    public function option($name, $value)
97
    {
98
        $this->primaryTable['options'][$name] = $value;
99
100
        return $this;
101
    }
102
103
    /**
104
     * Execute the build process
105
     */
106 4
    public function build()
107
    {
108 4
        $this->builder->getClassMetadata()->setPrimaryTable($this->primaryTable);
109 4
    }
110
}
111