Skip to content

Commit e88a707

Browse files
authored
Release/3.0.0 (#13)
1 parent 5886b32 commit e88a707

11 files changed

Lines changed: 94 additions & 201 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ With the implementation of the `ValueObject` interface, and the `ValueObjectAdap
4747
namespace Example;
4848

4949
use TinyBlocks\Vo\ValueObject;
50-
use TinyBlocks\Vo\ValueObjectAdapter;
50+
use TinyBlocks\Vo\ValueObjectBehavior;
5151

5252
final class TransactionId implements ValueObject
5353
{
54-
use ValueObjectAdapter;
54+
use ValueObjectBehavior;
5555

5656
public function __construct(private readonly string $value)
5757
{
@@ -67,7 +67,7 @@ The `equals` method compares the value of two VOs, and checks if they are equal.
6767
$transactionId = new TransactionId(value: 'e6e2442f-3bd8-421f-9ac2-f9e26ac4abd2');
6868
$otherTransactionId = new TransactionId(value: 'e6e2442f-3bd8-421f-9ac2-f9e26ac4abd2');
6969

70-
$transactionId->equals(other: $otherTransactionId); # 1 (true)
70+
$transactionId->equals(other: $otherTransactionId); # true
7171
```
7272

7373
<div id='license'></div>

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
}
4040
},
4141
"require": {
42-
"php": "^8.2"
42+
"php": "^8.2",
43+
"tiny-blocks/immutable-object": "^1"
4344
},
4445
"require-dev": {
4546
"phpmd/phpmd": "^2.15",
@@ -68,6 +69,9 @@
6869
"tests-no-coverage": [
6970
"@test-no-coverage",
7071
"@test-mutation-no-coverage"
72+
],
73+
"tests-file-no-coverage": [
74+
"@test-no-coverage"
7175
]
7276
}
7377
}

src/Immutable.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/Internal/Exceptions/InvalidProperty.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Internal/Exceptions/PropertyCannotBeChanged.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Internal/Exceptions/PropertyCannotBeDeactivated.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/ValueObject.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace TinyBlocks\Vo;
66

7+
use TinyBlocks\Immutable\Immutable;
8+
79
/**
810
* A Value Object is an immutable type that is only distinguishable by the state of its properties, that is,
911
* unlike an entity, which has a unique identifier and remains distinct even if its properties are
@@ -14,15 +16,11 @@
1416
interface ValueObject extends Immutable
1517
{
1618
/**
17-
* Returns object values.
18-
* @return array
19-
*/
20-
public function values(): array;
21-
22-
/**
23-
* Compare two ValueObjects, and tell if they are equal.
24-
* @param ValueObject $other
25-
* @return bool
19+
* Compares this ValueObject with another to determine if they are equal.
20+
* Two ValueObjects are considered equal if their properties have the same values.
21+
*
22+
* @param ValueObject $other The ValueObject to compare with.
23+
* @return bool True if the objects are equal, false otherwise.
2624
*/
2725
public function equals(ValueObject $other): bool;
2826
}

src/ValueObjectAdapter.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/ValueObjectBehavior.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TinyBlocks\Vo;
6+
7+
use TinyBlocks\Immutable\Immutability;
8+
9+
trait ValueObjectBehavior
10+
{
11+
use Immutability;
12+
13+
public function equals(ValueObject $other): bool
14+
{
15+
return get_object_vars($this) == get_object_vars($other);
16+
}
17+
}

tests/Models/Order.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
namespace TinyBlocks\Vo\Models;
66

77
use TinyBlocks\Vo\ValueObject;
8-
use TinyBlocks\Vo\ValueObjectAdapter;
8+
use TinyBlocks\Vo\ValueObjectBehavior;
99

1010
final readonly class Order implements ValueObject
1111
{
12-
use ValueObjectAdapter;
12+
use ValueObjectBehavior;
1313

1414
public function __construct(public int $id, public iterable $products = [])
1515
{

0 commit comments

Comments
 (0)