Skip to content

Commit 267e90f

Browse files
committed
store redundant regex part in a constant
1 parent b153bcf commit 267e90f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/ArangoDBClient/Document.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ class Document implements \JsonSerializable
129129
* keepNull option index
130130
*/
131131
const OPTION_KEEPNULL = 'keepNull';
132+
133+
/**
134+
* regular expression used for key validation
135+
*/
136+
const KEY_REGEX_PART = '[a-zA-Z0-9_:.@\\-()+,=;$!*\'%]{1,254}';
132137

133138
/**
134139
* Constructs an empty document
@@ -299,25 +304,21 @@ public function set($key, $value)
299304
if ($key[0] === '_') {
300305
if ($key === self::ENTRY_ID) {
301306
$this->setInternalId($value);
302-
303307
return;
304308
}
305309

306310
if ($key === self::ENTRY_KEY) {
307311
$this->setInternalKey($value);
308-
309312
return;
310313
}
311314

312315
if ($key === self::ENTRY_REV) {
313316
$this->setRevision($value);
314-
315317
return;
316318
}
317319

318320
if ($key === self::ENTRY_ISNEW) {
319321
$this->setIsNew($value);
320-
321322
return;
322323
}
323324
}
@@ -638,7 +639,7 @@ public function setInternalId($id)
638639
}
639640

640641

641-
if (!preg_match('/^[a-zA-Z0-9_-]{1,64}\/[a-zA-Z0-9_:.@\-()+,=;$!*\'%]{1,254}$/', $id)) {
642+
if (!preg_match('/^[a-zA-Z0-9_-]{1,64}\/' . self::KEY_REGEX_PART . '$/', $id)) {
642643
throw new ClientException('Invalid format for document id');
643644
}
644645

@@ -662,7 +663,7 @@ public function setInternalKey($key)
662663
throw new ClientException('Should not update the key of an existing document');
663664
}
664665

665-
if (!preg_match('/^[a-zA-Z0-9_:.@\-()+,=;$!*\'%]{1,254}$/', $key)) {
666+
if (!preg_match('/^' . self::KEY_REGEX_PART . '$/', $key)) {
666667
throw new ClientException('Invalid format for document key');
667668
}
668669

0 commit comments

Comments
 (0)