Skip to content

Commit 6acdab4

Browse files
committed
Rename Id to Uuid
1 parent 0e82b3d commit 6acdab4

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

docs/usage/identity.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# Identity
22
This groups Value Objects use for identity, e.g. for auth to users in your project. Or for another Entities.
33

4-
## Id
4+
## Uuid
55
```php
6-
use Myks92\ValueObjects\Identity\Id;
7-
use Ramsey\Uuid\Uuid;
6+
use Myks92\ValueObjects\Identity\Uuid;
87

9-
$id = new Id(Uuid::uuid4()->toString());
10-
$id->getValue(); //UUID4
11-
$id->isEqualTo(new Id(Uuid::uuid4()->toString())); //false
8+
$id = new Uuid('ccf4597-9d46-4bb4-b399-fdaf8db24bf0');
9+
$id->getValue(); //ccf4597-9d46-4bb4-b399-fdaf8db24bf0
10+
$id->isEqualTo(new Uuid('ccf4597-9d46-4bb4-b399-fdaf8db24bf0')); //true
1211
```
1312

1413
## Email
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
use Exception;
1010
use Myks92\ValueObjects\String\StringLiteral;
11-
use Ramsey\Uuid\Uuid;
11+
use Ramsey\Uuid\Uuid as UuidRamsey;
1212
use Webmozart\Assert\Assert;
1313

1414
/**
1515
* Class Id
1616
*
1717
* @author Maxim Vorozhtsov <myks1992@mail.ru>
1818
*/
19-
class Id extends StringLiteral
19+
class Uuid extends StringLiteral
2020
{
2121
/**
2222
* @param string $value
@@ -35,6 +35,6 @@ public function __construct(string $value)
3535
*/
3636
public static function generate(): self
3737
{
38-
return new self(Uuid::uuid4()->toString());
38+
return new self(UuidRamsey::uuid4()->toString());
3939
}
4040
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,45 @@
88

99
use Exception;
1010
use InvalidArgumentException;
11-
use Myks92\ValueObjects\Identity\Id;
11+
use Myks92\ValueObjects\Identity\Uuid;
1212
use PHPUnit\Framework\TestCase;
13-
use Ramsey\Uuid\Uuid;
13+
use Ramsey\Uuid\Uuid as UuidRamsey;
1414

15-
class IdTest extends TestCase
15+
class UuidTest extends TestCase
1616
{
1717
public function testSuccess(): void
1818
{
19-
$id = $this->createId($value = Uuid::uuid4()->toString());
19+
$id = $this->createId($value = UuidRamsey::uuid4()->toString());
2020

2121
self::assertEquals($value, $id->getValue());
2222
}
2323

2424
public function testCase(): void
2525
{
26-
$value = Uuid::uuid4()->toString();
26+
$value = UuidRamsey::uuid4()->toString();
2727
$id = $this->createId(mb_strtoupper($value));
2828

2929
self::assertEquals($value, $id->getValue());
3030
}
3131

3232
public function testGenerate(): void
3333
{
34-
$id = Id::generate();
34+
$id = Uuid::generate();
3535

3636
self::assertNotEmpty($id->getValue());
3737
}
3838

3939
public function testToString(): void
4040
{
41-
$id = $this->createId($value = Uuid::uuid4()->toString());
41+
$id = $this->createId($value = UuidRamsey::uuid4()->toString());
4242

4343
self::assertEquals($value, $id);
4444
}
4545

4646
public function testEqual(): void
4747
{
4848
$id = $this->createId();
49-
$id2 = Id::generate(); //other
49+
$id2 = Uuid::generate(); //other
5050

5151
self::assertTrue($id->isEqualTo($id));
5252
self::assertFalse($id->isEqualTo($id2));
@@ -55,26 +55,26 @@ public function testEqual(): void
5555
public function testIncorrect(): void
5656
{
5757
$this->expectException(InvalidArgumentException::class);
58-
new Id('not-uuid');
58+
new Uuid('not-uuid');
5959
}
6060

6161
public function testEmpty(): void
6262
{
6363
$this->expectException(InvalidArgumentException::class);
64-
new Id('');
64+
new Uuid('');
6565
}
6666

6767
/**
6868
* @param $value
6969
*
70-
* @return Id
70+
* @return Uuid
7171
* @throws Exception
7272
*/
73-
private function createId($value = null): Id
73+
private function createId($value = null): Uuid
7474
{
7575
if (null === $value) {
76-
$value = Uuid::uuid4()->toString();
76+
$value = UuidRamsey::uuid4()->toString();
7777
}
78-
return new Id($value);
78+
return new Uuid($value);
7979
}
8080
}

0 commit comments

Comments
 (0)