Skip to content

Commit 9117bb3

Browse files
committed
Mark schema classes as final
1 parent 0304a7c commit 9117bb3

File tree

5 files changed

+106
-107
lines changed

5 files changed

+106
-107
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ The following classes have been marked as final:
8686

8787
- `StaticServerVersionProvider`
8888
- `ColumnDiff`
89+
- `Table`
8990
- `TableDiff`
91+
- `Sequence`
92+
- `Schema`
9093
- `SchemaDiff`
94+
- `View`
9195

9296
## BC BREAK: Changes in `Index` methods, properties and behavior
9397

src/Schema/Schema.php

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@
5353
* the CREATE/DROP SQL visitors will just filter this queries and do not
5454
* execute them. Only the queries for the currently connected database are
5555
* executed.
56-
*
57-
* @final
5856
*/
59-
class Schema
57+
final class Schema
6058
{
6159
/**
6260
* The namespaces in this schema.
@@ -66,12 +64,12 @@ class Schema
6664
private array $namespaces = [];
6765

6866
/** @var array<string, Table> */
69-
protected array $_tables = [];
67+
private array $tables = [];
7068

7169
/** @var array<string, Sequence> */
72-
protected array $_sequences = [];
70+
private array $sequences = [];
7371

74-
protected SchemaConfig $_schemaConfig;
72+
private SchemaConfig $schemaConfig;
7573

7674
/**
7775
* The default namespace name that the schema will use as a qualifier to resolve unqualified names.
@@ -101,7 +99,7 @@ public function __construct(
10199
) {
102100
$schemaConfig ??= new SchemaConfig();
103101

104-
$this->_schemaConfig = $schemaConfig;
102+
$this->schemaConfig = $schemaConfig;
105103

106104
$this->defaultNamespaceName = $schemaConfig->getName();
107105

@@ -110,42 +108,42 @@ public function __construct(
110108
}
111109

112110
foreach ($tables as $table) {
113-
$this->_addTable($table);
111+
$this->addTable($table);
114112
}
115113

116114
foreach ($sequences as $sequence) {
117-
$this->_addSequence($sequence);
115+
$this->addSequence($sequence);
118116
}
119117
}
120118

121-
protected function _addTable(Table $table): void
119+
private function addTable(Table $table): void
122120
{
123121
$resolvedName = $this->resolveName($table->getObjectName());
124122

125123
$key = $this->getKeyFromResolvedName($resolvedName);
126124

127-
if (isset($this->_tables[$key])) {
125+
if (isset($this->tables[$key])) {
128126
throw TableAlreadyExists::new($resolvedName->toString());
129127
}
130128

131129
$this->registerQualifier($resolvedName->getQualifier());
132130

133-
$this->_tables[$key] = $table;
131+
$this->tables[$key] = $table;
134132
}
135133

136-
protected function _addSequence(Sequence $sequence): void
134+
private function addSequence(Sequence $sequence): void
137135
{
138136
$resolvedName = $this->resolveName($sequence->getObjectName());
139137

140138
$key = $this->getKeyFromResolvedName($resolvedName);
141139

142-
if (isset($this->_sequences[$key])) {
140+
if (isset($this->sequences[$key])) {
143141
throw SequenceAlreadyExists::new($resolvedName->toString());
144142
}
145143

146144
$this->registerQualifier($resolvedName->getQualifier());
147145

148-
$this->_sequences[$key] = $sequence;
146+
$this->sequences[$key] = $sequence;
149147
}
150148

151149
private function registerQualifier(?Identifier $qualifier): void
@@ -186,17 +184,17 @@ public function getNamespaces(): array
186184
*/
187185
public function getTables(): array
188186
{
189-
return array_values($this->_tables);
187+
return array_values($this->tables);
190188
}
191189

192190
public function getTable(string $name): Table
193191
{
194192
$key = $this->getKeyFromName($name);
195-
if (! isset($this->_tables[$key])) {
193+
if (! isset($this->tables[$key])) {
196194
throw TableDoesNotExist::new($name);
197195
}
198196

199-
return $this->_tables[$key];
197+
return $this->tables[$key];
200198
}
201199

202200
/**
@@ -275,30 +273,30 @@ public function hasTable(string $name): bool
275273
{
276274
$key = $this->getKeyFromName($name);
277275

278-
return isset($this->_tables[$key]);
276+
return isset($this->tables[$key]);
279277
}
280278

281279
public function hasSequence(string $name): bool
282280
{
283281
$key = $this->getKeyFromName($name);
284282

285-
return isset($this->_sequences[$key]);
283+
return isset($this->sequences[$key]);
286284
}
287285

288286
public function getSequence(string $name): Sequence
289287
{
290288
$key = $this->getKeyFromName($name);
291-
if (! isset($this->_sequences[$key])) {
289+
if (! isset($this->sequences[$key])) {
292290
throw SequenceDoesNotExist::new($name);
293291
}
294292

295-
return $this->_sequences[$key];
293+
return $this->sequences[$key];
296294
}
297295

298296
/** @return list<Sequence> */
299297
public function getSequences(): array
300298
{
301-
return array_values($this->_sequences);
299+
return array_values($this->sequences);
302300
}
303301

304302
/**
@@ -340,10 +338,10 @@ private function getNamespaceKey(string $name): string
340338
*/
341339
public function createTable(string $name): Table
342340
{
343-
$table = new Table($name, [], [], [], [], [], $this->_schemaConfig->toTableConfiguration());
344-
$this->_addTable($table);
341+
$table = new Table($name, [], [], [], [], [], $this->schemaConfig->toTableConfiguration());
342+
$this->addTable($table);
345343

346-
foreach ($this->_schemaConfig->getDefaultTableOptions() as $option => $value) {
344+
foreach ($this->schemaConfig->getDefaultTableOptions() as $option => $value) {
347345
$table->addOption($option, $value);
348346
}
349347

@@ -365,7 +363,7 @@ public function renameTable(string $oldName, string $newName): self
365363
->create();
366364

367365
$this->dropTable($oldName);
368-
$this->_addTable($table);
366+
$this->addTable($table);
369367

370368
return $this;
371369
}
@@ -378,11 +376,11 @@ public function renameTable(string $oldName, string $newName): self
378376
public function dropTable(string $name): self
379377
{
380378
$key = $this->getKeyFromName($name);
381-
if (! isset($this->_tables[$key])) {
379+
if (! isset($this->tables[$key])) {
382380
throw TableDoesNotExist::new($name);
383381
}
384382

385-
unset($this->_tables[$key]);
383+
unset($this->tables[$key]);
386384

387385
return $this;
388386
}
@@ -393,7 +391,7 @@ public function dropTable(string $name): self
393391
public function createSequence(string $name, int $allocationSize = 1, int $initialValue = 1): Sequence
394392
{
395393
$seq = new Sequence($name, $allocationSize, $initialValue);
396-
$this->_addSequence($seq);
394+
$this->addSequence($seq);
397395

398396
return $seq;
399397
}
@@ -402,7 +400,7 @@ public function createSequence(string $name, int $allocationSize = 1, int $initi
402400
public function dropSequence(string $name): self
403401
{
404402
$key = $this->getKeyFromName($name);
405-
unset($this->_sequences[$key]);
403+
unset($this->sequences[$key]);
406404

407405
return $this;
408406
}
@@ -438,12 +436,12 @@ public function toDropSql(AbstractPlatform $platform): array
438436
*/
439437
public function __clone()
440438
{
441-
foreach ($this->_tables as $k => $table) {
442-
$this->_tables[$k] = clone $table;
439+
foreach ($this->tables as $k => $table) {
440+
$this->tables[$k] = clone $table;
443441
}
444442

445-
foreach ($this->_sequences as $k => $sequence) {
446-
$this->_sequences[$k] = clone $sequence;
443+
foreach ($this->sequences as $k => $sequence) {
444+
$this->sequences[$k] = clone $sequence;
447445
}
448446
}
449447

src/Schema/Sequence.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@
1212
/**
1313
* Sequence structure.
1414
*
15-
* @final
1615
* @extends AbstractNamedObject<OptionallyQualifiedName>
1716
*/
18-
class Sequence extends AbstractNamedObject
17+
final class Sequence extends AbstractNamedObject
1918
{
20-
protected int $allocationSize = 1;
19+
private int $allocationSize = 1;
2120

22-
protected int $initialValue = 1;
21+
private int $initialValue = 1;
2322

2423
public function __construct(
2524
string $name,
2625
int $allocationSize = 1,
2726
int $initialValue = 1,
28-
protected ?int $cache = null,
27+
private ?int $cache = null,
2928
) {
3029
$parser = Parsers::getOptionallyQualifiedNameParser();
3130

0 commit comments

Comments
 (0)