Skip to content

Commit 7534cc0

Browse files
import php functions explicitly
1 parent 27cb194 commit 7534cc0

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

composer.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
{
22
"name": "slime-systems/object-id",
3-
"description": "BSON's ObjectId for PHP",
3+
"description": "A feature-packed, BSON-compatible ObjectId implementation for PHP, similar to MongoDB's ObjectId, providing unique ID generation, conversions, and comparison utilities.",
44
"type": "library",
55
"license": "BSD-2-Clause",
66
"keywords": [
7-
"BSON",
8-
"ObjectId",
9-
"MongoDB",
10-
"UUID",
11-
"bson-objectid",
12-
"unique-identifier"
7+
"objectid",
8+
"object-id",
9+
"id",
10+
"unique-id",
11+
"unique-identifier",
12+
"bson",
13+
"mongodb",
14+
"timestamp",
15+
"identifier",
16+
"generation",
17+
"sortable-id"
1318
],
1419
"scripts": {
1520
"test": "vendor/bin/pest"

src/ObjectId.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
use DateTime;
77
use SlimeSystems\ObjectId\Exception\Invalid;
88
use SlimeSystems\ObjectIdInternal\Generator;
9+
use function bin2hex;
10+
use function hex2bin;
11+
use function is_string;
12+
use function preg_match;
13+
use function strlen;
14+
use function substr;
15+
use function unpack;
916

1017
/**
1118
* Represents BSON ObjectId data (12 bytes).

src/_internal/Generator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
namespace SlimeSystems\ObjectIdInternal;
44

5+
use function pack;
6+
use function random_bytes;
7+
use function random_int;
8+
use function substr;
9+
use function time;
10+
511
/**
612
* @internal The class that encapsulates the behaviour of actually generating each
713
* part of the ObjectId.
@@ -39,7 +45,7 @@ public function __construct()
3945
public function nextObjectId(?int $time = null): string
4046
{
4147
$time ??= time();
42-
$count = $this->counter = ($this->counter + 1) & self::COUNTER_MAX;
48+
$count = $this->counter = $this->counter + 1 & self::COUNTER_MAX;
4349

4450
return $this->generate($time, $count);
4551
}
@@ -66,6 +72,6 @@ public function generate(int $time, int $counter = 0): string
6672

6773
// Concatenate the pieces:
6874
// Time (4) | PID (5) | Counter (3)
69-
return $timeBytes . $this->processId . $counter_bytes;
75+
return "{$timeBytes}{$this->processId}{$counter_bytes}";
7076
}
7177
}

0 commit comments

Comments
 (0)