CreateColumn::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Platine Database
5
 *
6
 * Platine Database is the abstraction layer using PDO with support of query and schema builder
7
 *
8
 * This content is released under the MIT License (MIT)
9
 *
10
 * Copyright (c) 2020 Platine Database
11
 *
12
 * Permission is hereby granted, free of charge, to any person obtaining a copy
13
 * of this software and associated documentation files (the "Software"), to deal
14
 * in the Software without restriction, including without limitation the rights
15
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
 * copies of the Software, and to permit persons to whom the Software is
17
 * furnished to do so, subject to the following conditions:
18
 *
19
 * The above copyright notice and this permission notice shall be included in all
20
 * copies or substantial portions of the Software.
21
 *
22
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
 * SOFTWARE.
29
 */
30
31
/**
32
 *  @file CreateColumn.php
33
 *
34
 *  The create column schema class
35
 *
36
 *  @package    Platine\Database\Schema
37
 *  @author Platine Developers Team
38
 *  @copyright  Copyright (c) 2020
39
 *  @license    http://opensource.org/licenses/MIT  MIT License
40
 *  @link   https://www.platine-php.com
41
 *  @version 1.0.0
42
 *  @filesource
43
 */
44
45
declare(strict_types=1);
46
47
namespace Platine\Database\Schema;
48
49
/**
50
 * @class CreateColumn
51
 * @package Platine\Database\Schema
52
 */
53
class CreateColumn extends BaseColumn
54
{
55
    /**
56
     * The associated table instance
57
     * @var CreateTable
58
     */
59
    protected CreateTable $table;
60
61
    /**
62
     * Class constructor
63
     * @param CreateTable $table
64
     * @param string $name
65
     * @param string|null $type
66
     */
67
    public function __construct(
68
        CreateTable $table,
69
        string $name,
70
        ?string $type = null
71
    ) {
72
        $this->table = $table;
73
        parent::__construct($name, $type);
74
    }
75
76
    /**
77
     *
78
     * @return CreateTable
79
     */
80
    public function getTable(): CreateTable
81
    {
82
        return $this->table;
83
    }
84
85
    /**
86
     * Set the auto increment value
87
     * @param string|null $name
88
     * @return $this
89
     */
90
    public function autoincrement(?string $name = null): self
91
    {
92
        $this->table->autoincrement($this, $name);
93
94
        return $this;
95
    }
96
97
    /**
98
     * Set the primary key
99
     * @param string|null $name
100
     * @return $this
101
     */
102
    public function primary(?string $name = null): self
103
    {
104
        $this->table->primary($this->name, $name);
105
106
        return $this;
107
    }
108
109
    /**
110
     * Set the unique key
111
     * @param string|null $name
112
     * @return $this
113
     */
114
    public function unique(?string $name = null): self
115
    {
116
        $this->table->unique($this->name, $name);
117
118
        return $this;
119
    }
120
121
    /**
122
     * Set the index key
123
     * @param string|null $name
124
     * @return $this
125
     */
126
    public function index(?string $name = null): self
127
    {
128
        $this->table->index($this->name, $name);
129
130
        return $this;
131
    }
132
}
133