Passed
Push — master ( 6adceb...02167b )
by David
49s queued 10s
created

TdbmFluidColumnOptions   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 7
dl 0
loc 160
rs 10
c 0
b 0
f 0

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A notNull() 0 5 1
A null() 0 5 1
A unique() 0 5 1
A index() 0 5 1
A comment() 0 5 1
A autoIncrement() 0 6 1
A primaryKey() 0 5 1
A default() 0 5 1
A then() 0 4 1
A column() 0 4 1
A graphqlField() 0 5 1
A jsonSerialize() 0 4 1
A protectedGetter() 0 5 1
A protectedSetter() 0 5 1
A protectedOneToMany() 0 5 1
A getComment() 0 6 1
A saveComment() 0 5 1
A addAnnotation() 0 6 1
A removeAnnotation() 0 6 1
1
<?php
2
3
4
namespace TheCodingMachine\FluidSchema;
5
6
7
class TdbmFluidColumnOptions
8
{
9
    /**
10
     * @var TdbmFluidTable
11
     */
12
    private $tdbmFluidTable;
13
    /**
14
     * @var FluidColumn
15
     */
16
    private $fluidColumn;
17
    /**
18
     * @var FluidColumnOptions
19
     */
20
    private $fluidColumnOptions;
21
22
    public function __construct(TdbmFluidTable $tdbmFluidTable, FluidColumn $fluidColumn, FluidColumnOptions $fluidColumnOptions)
23
    {
24
        $this->tdbmFluidTable = $tdbmFluidTable;
25
        $this->fluidColumn = $fluidColumn;
26
        $this->fluidColumnOptions = $fluidColumnOptions;
27
    }
28
29
    /**
30
     * Makes the column not nullable.
31
     * @return FluidColumnOptions
32
     */
33
    public function notNull(): self
34
    {
35
        $this->fluidColumnOptions->notNull();
36
        return $this;
37
    }
38
39
    /**
40
     * Makes the column nullable.
41
     * @return self
42
     */
43
    public function null(): self
44
    {
45
        $this->fluidColumnOptions->null();
46
        return $this;
47
    }
48
49
    /**
50
     * Automatically add a unique constraint for the column.
51
     *
52
     * @return self
53
     */
54
    public function unique(): self
55
    {
56
        $this->fluidColumnOptions->unique();
57
        return $this;
58
    }
59
60
    /**
61
     * Automatically add an index for the column.
62
     *
63
     * @return self
64
     */
65
    public function index(): self
66
    {
67
        $this->fluidColumnOptions->index();
68
        return $this;
69
    }
70
    public function comment(string $comment): self
71
    {
72
        $this->fluidColumnOptions->comment($comment);
73
        return $this;
74
    }
75
76
    public function autoIncrement(): self
77
    {
78
        $this->fluidColumnOptions->autoIncrement();
79
        $this->addAnnotation('Autoincrement');
80
        return $this;
81
    }
82
83
    public function primaryKey(?string $indexName = null): self
84
    {
85
        $this->fluidColumnOptions->primaryKey($indexName);
86
        return $this;
87
    }
88
89
    public function default($defaultValue): self
90
    {
91
        $this->fluidColumnOptions->default($defaultValue);
92
        return $this;
93
    }
94
95
    public function then(): TdbmFluidTable
96
    {
97
        return $this->tdbmFluidTable;
98
    }
99
100
    public function column(string $name): TdbmFluidColumn
101
    {
102
        return $this->tdbmFluidTable->column($name);
103
    }
104
105
    public function graphqlField(): TdbmFluidColumnGraphqlOptions
106
    {
107
        $this->tdbmFluidTable->graphqlType();
108
        return new TdbmFluidColumnGraphqlOptions($this, $this->fluidColumn);
109
    }
110
111
    public function jsonSerialize(): TdbmFluidColumnJsonOptions
112
    {
113
        return new TdbmFluidColumnJsonOptions($this);
114
    }
115
116
    public function protectedGetter(): self
117
    {
118
        $this->addAnnotation('TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedGetter');
119
        return $this;
120
    }
121
122
    public function protectedSetter(): self
123
    {
124
        $this->addAnnotation('TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedSetter');
125
        return $this;
126
    }
127
128
    public function protectedOneToMany(): self
129
    {
130
        $this->addAnnotation('TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedOneToMany');
131
        return $this;
132
    }
133
134
    private function getComment(): Comment
135
    {
136
        $comment = $this->fluidColumn->getDbalColumn()->getComment();
137
138
        return new Comment($comment ?? '');
139
    }
140
141
    private function saveComment(Comment $comment): self
142
    {
143
        $this->fluidColumn->getDbalColumn()->setComment($comment->getComment());
144
        return $this;
145
    }
146
147
    /**
148
     * @param string $annotation
149
     * @param mixed $content
150
     * @param bool $replaceExisting
151
     * @return TdbmFluidColumnOptions
152
     */
153
    public function addAnnotation(string $annotation, $content = null, bool $replaceExisting = true, bool $explicitNull = false): self
154
    {
155
        $comment = $this->getComment()->addAnnotation($annotation, $content, $replaceExisting, $explicitNull);
156
        $this->saveComment($comment);
157
        return $this;
158
    }
159
160
    public function removeAnnotation(string $annotation): self
161
    {
162
        $comment = $this->getComment()->removeAnnotation($annotation);
163
        $this->saveComment($comment);
164
        return $this;
165
    }
166
}
167