Skip to content

Commit 0c64c24

Browse files
iron out binary interfaces
1 parent e0c73f1 commit 0c64c24

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/ObjectId.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(?string $rawData = null)
5454
* @return ObjectId
5555
* @throws Invalid if $rawData is not 12 bytes.
5656
*/
57-
public static function fromData(string $data): ObjectId
57+
public static function fromBinary(string $data): ObjectId
5858
{
5959
return new self($data);
6060
}
@@ -71,7 +71,7 @@ public static function fromString(string $string): ObjectId
7171
if (!self::legal($string)) {
7272
throw new Invalid("'$string' is an invalid ObjectId.");
7373
}
74-
return self::fromData(hex2bin($string));
74+
return self::fromBinary(hex2bin($string));
7575
}
7676

7777
/**
@@ -92,7 +92,7 @@ public static function fromTime(int|DateTime $time, bool $unique = true): Object
9292
$data = pack('N', $timestamp) . "\x00\x00\x00\x00\x00\x00\x00\x00";
9393
}
9494

95-
return self::fromData($data);
95+
return self::fromBinary($data);
9696
}
9797

9898
/**

tests/Unit/ObjectIdTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
it('creates an ObjectId from raw data', function () {
1616
$rawId = random_bytes(12);
17-
$objectId = ObjectId::fromData($rawId);
17+
$objectId = ObjectId::fromBinary($rawId);
1818
expect($objectId)->toBeInstanceOf(ObjectId::class);
1919
expect($objectId->toBinary())->toBe($rawId);
2020
});
2121

2222
it('throws Invalid exception for invalid raw data', function () {
2323
foreach ([10, 14] as $length) {
24-
expect(fn() => ObjectId::fromData(random_bytes($length)))->toThrow(
24+
expect(fn() => ObjectId::fromBinary(random_bytes($length)))->toThrow(
2525
Invalid::class,
2626
);
2727
}

0 commit comments

Comments
 (0)