Skip to content

Commit e10670a

Browse files
committed
Remove Sequence type
1 parent 549323a commit e10670a

6 files changed

Lines changed: 20 additions & 32 deletions

File tree

src/Database/Adapter/SQL.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,6 @@ public function getAttributeWidth(Document $collection): int
10031003
}
10041004

10051005
switch ($attribute['type']) {
1006-
case Database::VAR_SEQUENCE:
10071006
case Database::VAR_ID:
10081007
$total += 8; // BIGINT 8 bytes
10091008
break;

src/Database/Database.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ class Database
4141
public const VAR_BOOLEAN = 'boolean';
4242
public const VAR_DATETIME = 'datetime';
4343
public const VAR_ID = 'id';
44-
public const VAR_SEQUENCE = 'sequence';
4544

4645
// VAR_ID types
47-
public const VAR_ID_INT = 'integer_';
48-
public const VAR_ID_MONGO = 'mongo_';
46+
public const VAR_ID_INT = '_integer';
47+
public const VAR_ID_MONGO = '_mongo';
4948

5049
public const INT_MAX = 2147483647;
5150
public const BIG_INT_MAX = PHP_INT_MAX;
@@ -172,7 +171,7 @@ class Database
172171
],
173172
[
174173
'$id' => '$sequence',
175-
'type' => self::VAR_SEQUENCE,
174+
'type' => self::VAR_ID,
176175
'size' => 0,
177176
'required' => true,
178177
'signed' => true,

src/Database/Validator/Queries/Documents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(
4040
$attributes[] = new Document([
4141
'$id' => '$sequence',
4242
'key' => '$sequence',
43-
'type' => Database::VAR_SEQUENCE,
43+
'type' => Database::VAR_ID,
4444
'array' => false,
4545
]);
4646
$attributes[] = new Document([

src/Database/Validator/Query/Filter.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,8 @@ protected function isValidAttributeAndValues(string $attribute, array $values, s
108108
$validator = null;
109109

110110
switch ($attributeType) {
111-
case Database::VAR_SEQUENCE:
112-
$validator = new Sequence($this->idAttributeType, true);
113-
break;
114-
115111
case Database::VAR_ID:
116-
$validator = new Sequence($this->idAttributeType, false);
112+
$validator = new Sequence($this->idAttributeType, $attribute === '$sequence');
117113
break;
118114

119115
case Database::VAR_STRING:

src/Database/Validator/Sequence.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,22 @@ public function isValid($value): bool
4646
return false;
4747
}
4848

49-
if ($this->idAttributeType === Database::VAR_ID_MONGO) {
50-
return preg_match('/^[a-f0-9]{24}$/i', $value) === 1;
51-
} elseif ($this->idAttributeType === Database::VAR_ID_INT) {
52-
$validator = new Integer(loose: true);
53-
if (!$validator->isValid($value)) {
54-
return false;
55-
}
49+
switch ($this->idAttributeType) {
50+
case Database::VAR_ID_MONGO:
51+
return preg_match('/^[a-f0-9]{24}$/i', $value) === 1;
5652

57-
$start = ($this->primary) ? 1 : 0;
53+
case Database::VAR_ID_INT:
54+
$validator = new Integer(loose: true);
55+
if (!$validator->isValid($value)) {
56+
return false;
57+
}
5858

59-
$validator = new Range($start, Database::BIG_INT_MAX, Database::VAR_INTEGER);
60-
if (!$validator->isValid($value)) {
61-
return false;
62-
}
59+
$start = ($this->primary) ? 1 : 0;
60+
$validator = new Range($start, Database::BIG_INT_MAX, Database::VAR_INTEGER);
61+
return $validator->isValid($value);
6362

64-
return true;
63+
default:
64+
return false;
6565
}
66-
67-
return false;
6866
}
6967
}

src/Database/Validator/Structure.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Structure extends Validator
3232
],
3333
[
3434
'$id' => '$sequence',
35-
'type' => Database::VAR_SEQUENCE,
35+
'type' => Database::VAR_ID,
3636
'size' => 0,
3737
'required' => false,
3838
'signed' => true,
@@ -316,12 +316,8 @@ protected function checkForInvalidAttributeValues(array $structure, array $keys)
316316
$validators = [];
317317

318318
switch ($type) {
319-
case Database::VAR_SEQUENCE:
320-
$validators[] = new Sequence($this->idAttributeType, true);
321-
break;
322-
323319
case Database::VAR_ID:
324-
$validators[] = new Sequence($this->idAttributeType, false);
320+
$validators[] = new Sequence($this->idAttributeType, $attribute['$id'] === '$sequence');
325321
break;
326322

327323
case Database::VAR_STRING:

0 commit comments

Comments
 (0)