Issues (590)

src/Schema/Builder/TableBuilderInterface.php (2 issues)

1
<?php
2
3
namespace Bdf\Prime\Schema\Builder;
4
5
use Bdf\Prime\Platform\PlatformTypeInterface;
6
use Bdf\Prime\Schema\Constraint\ForeignKeyInterface;
7
use Bdf\Prime\Schema\IndexInterface;
8
use Bdf\Prime\Schema\TableInterface;
9
10
/**
11
 * Interface for building tables
12
 *
13
 * This builder is low level.
14
 * To build table with high level, use @see TypesHelperTableBuilder
15
 *
16
 * /!\ The columns types should be @see PlatformTypeInterface
17
 *     Call of add() will returns @see ColumnBuilderInterface
18
 *
19
 * <code>
20
 * $builder->add('id', new SqlStringType(TypeInterface::BIGINT));
21
 * $builder->primary();
22
 * $builder->add('name', new SqlStringType(TypeInterface::STRING))->unique();
23
 * </code>
24
 */
25
interface TableBuilderInterface
26
{
27
    /**
28
     * Set the table name
29
     *
30
     * @param string $name
31
     *
32
     * @return $this
33
     */
34
    public function name(string $name);
35
36
    /**
37
     * Set table options
38
     *
39
     * @param  array  $options
40
     *
41
     * @return $this
42
     */
43
    public function options(array $options);
44
45
    /**
46
     * Set the indexes of the table
47
     *
48
     * <code>
49
     * $table->indexes([
50
     *     'index_name' => 'field',
51
     *     'index_name' => ['field1', 'field2'],
52
     *     'field2',
53
     *     'with_options' => [
54
     *         'fields' => ['first_name', 'address' => ['length' => 32]],
55
     *         'type' => IndexInterface::TYPE_UNIQUE,
56
     *         'options' => ['opt' => 'val'],
57
     *     ]
58
     * ]);
59
     * </code>
60
     *
61
     * @param array $indexes
62
     *
63
     * @return $this
64
     */
65
    public function indexes(array $indexes);
66
67
    /**
68
     * Add a new index on the table
69
     *
70
     * <code>
71
     * $builder
72
     *     ->index('name') // Add simple index of field "name"
73
     *     ->index('email', IndexInterface::TYPE_UNIQUE) // Add unique index on "email"
74
     *     ->index('description', IndexInterface::TYPE_SIMPLE, 'descr_search', ['fulltext' => true]) // Add fulltext index on field "description"
75
     *     ->index(['type', 'date']) // Add index on fields "type" and "date"
76
     *     ->index(['reference' => ['length' => 24]], IndexInterface::TYPE_UNIQUE) // Add unique index on first 12 chars of "reference"
77
     * ;
78
     * </code>
79
     *
80
     * @param string|array<int,string>|array<string,array> $columns The columns composed the index. If a string is passed, it will be transformed to an array with single column
81
     * @param IndexInterface::TYPE_* $type The index type (one of the IndexInterface::TYPE_* constant)
82
     * @param string|null $name The index name. If not specified, it will be generated
83
     * @param array $options Options of the index
84
     *
85
     * @return $this
86
     */
87
    public function index($columns, int $type = IndexInterface::TYPE_SIMPLE, ?string $name = null, array $options = []);
88
89
    /**
90
     * Specify the primary key(s) for the table.
91
     *
92
     * @param  string|list<string>|null $columns   The name of columns. Null to select the current one
0 ignored issues
show
The type Bdf\Prime\Schema\Builder\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
93
     * @param  string|null $name The name of the index. Null to generate one
94
     *
95
     * @return $this
96
     */
97
    public function primary($columns = null, ?string $name = null);
98
99
    /**
100
     * Add a new column to the table
101
     *
102
     * @param string $column The column name
103
     * @param PlatformTypeInterface $type The column type
104
     * @param array $options Array fof column options
105
     *
106
     * Allowed options:
107
     *   * autoincrement        :
108
     *   * columnDefinition     :
109
     *   * comment              :
110
     *   * customSchemaOptions  :
111
     *   * default              :
112
     *   * fixed                :
113
     *   * length               :
114
     *   * nillable             :
115
     *   * notnull              : Negation of nillable
116
     *   * platformOptions      :
117
     *   * precision            :
118
     *   * primary              :
119
     *   * scale                :
120
     *   * unique               :
121
     *   * unsigned             :
122
     *
123
     * @return ColumnBuilderInterface The new created column
124
     */
125
    public function add(string $column, PlatformTypeInterface $type, array $options = []);
126
127
    /**
128
     * Get a column by its name
129
     *
130
     * @param  string|null $name The column name, or null to get the last added column
131
     *
132
     * @return ColumnBuilderInterface
133
     */
134
    public function column(?string $name = null);
135
136
    /**
137
     * Adds a foreign key constraint.
138
     *
139
     * Name is inferred from the local columns.
140
     *
141
     * @param TableInterface|string $foreignTable Table schema instance or table name
142
     * @param array $localColumnNames
143
     * @param array $foreignColumnNames
144
     * @param array{onDelete?: ForeignKeyInterface::MODE_*, onUpdate?: ForeignKeyInterface::MODE_*, match?: ForeignKeyInterface::MATCH_*} $options
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{onDelete?: Foreign...nKeyInterface::MATCH_*} at position 4 could not be parsed: Expected '}' at position 4, but found 'ForeignKeyInterface'.
Loading history...
145
     * @param string|null $constraintName
146
     *
147
     * @return $this
148
     */
149
    public function foreignKey($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], ?string $constraintName = null);
150
151
    /**
152
     * Build the table object
153
     *
154
     * @return TableInterface
155
     */
156
    public function build(): TableInterface;
157
}
158