Skip to content

Commit ef2bb44

Browse files
committed
Merge branch 'release/4.0.0'
2 parents e040aab + 676c719 commit ef2bb44

File tree

229 files changed

+719
-3733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+719
-3733
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: [ 8.1, 8.2, 8.3, 8.4 ]
17+
php: [ 8.2, 8.3, 8.4 ]
1818

1919
steps:
2020
- name: Checkout Code

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,43 @@ All notable changes to this project will be documented in this file. This projec
55

66
## Unreleased
77

8+
## [4.0.0] - 2025-09-12
9+
10+
### Added
11+
12+
- **BREAKING**: Added `code()` method to the `ListOfErrors` interface. This returns the first error code in the list, or
13+
`null` if there are no error codes.
14+
15+
### Changed
16+
17+
- **BREAKING**: The constructor argument order for the `Error` class has changed. The new order is `code`, `message`,
18+
`key`. Previously it was `key`, `message`, `code` because code was added later. However, in most instances `code` is
19+
the most important property as it is used to programmatically detect specific error scenarios. This hopefully will not
20+
be breaking, as the docs specified that named arguments should be used when constructing error objects.
21+
- **BREAKING** The error and error list interfaces now accept `UnitEnum` instead of `BackedEnum` for error codes.
22+
Although technically breaking, this will only affect your implementation if you have implemented these interfaces. All
23+
concrete classes provided by this package have been updated.
24+
- **BREAKING**: The key of an error can now be a enum - previously only strings were accepted. This is only breaking if
25+
you have implemented the interface yourself.
26+
- Updated `KeyedSetOfErrors` to handle error keys now being strings or enums.
27+
- **BREAKING**: The `Guid::make()` method will now convert a string that is a UUID to a UUID GUID. Previously it would
28+
use a string id.
29+
- **BREAKING**: Updated the `GuidTypeMap` class so that it now supports enum aliases, enum types, and UUID identifiers.
30+
This means the `type()` method now returns a string or enum, whereas previously it returned just a string.
31+
- Object log context now casts Ramsey UUIDs and enums to strings.
32+
33+
### Removed
34+
35+
- Package no longer supports PHP 8.1. The minimum supported version is now PHP 8.2.
36+
- **BREAKING**: Removed the `Guid::type()` method - use `enum_value($guid->type)` or `enum_string($guid->type)` instead.
37+
- Removed the following classes that were deprecated in 3.4:
38+
- `LazyListOfGuids`
39+
- `LazyListOfIdentifiers`
40+
- `LazyListOfIntegerIds`
41+
- `LazyListOfStringIds`
42+
- `LazyListOfUuids`
43+
- `ListOfIdentifiers`
44+
845
## [3.4.0] - 2025-09-09
946

1047
### Deprecated
@@ -445,6 +482,12 @@ All notable changes to this project will be documented in this file. This projec
445482

446483
Initial release.
447484

485+
[4.0.0]: https://github.com/cloudcreativity/ddd-modules/compare/v3.4.0...v4.0.0
486+
487+
[3.4.0]: https://github.com/cloudcreativity/ddd-modules/compare/v3.3.1...v3.4.0
488+
489+
[3.3.1]: https://github.com/cloudcreativity/ddd-modules/compare/v3.3.0...v3.3.1
490+
448491
[3.3.0]: https://github.com/cloudcreativity/ddd-modules/compare/v3.2.0...v3.3.0
449492

450493
[3.2.0]: https://github.com/cloudcreativity/ddd-modules/compare/v3.1.0...v3.2.0

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^8.1",
24+
"php": "^8.2",
2525
"ext-json": "*",
26-
"psr/log": "^1.0.1 || ^2.0 || ^3.0",
26+
"psr/log": "^2.0 || ^3.0",
2727
"ramsey/uuid": "^4.7",
2828
"symfony/polyfill-php84": "^1.33"
2929
},
3030
"require-dev": {
31-
"deptrac/deptrac": "^3.0",
31+
"deptrac/deptrac": "^4.2",
3232
"laravel/pint": "^1.19",
3333
"phpstan/phpstan": "^2.1",
34-
"phpunit/phpunit": "^10.5"
34+
"phpunit/phpunit": "^11.5"
3535
},
3636
"autoload": {
3737
"files": [
@@ -61,8 +61,8 @@
6161
},
6262
"extra": {
6363
"branch-alias": {
64-
"dev-develop": "3.x-dev",
65-
"dev-next": "4.x-dev"
64+
"dev-develop": "4.x-dev",
65+
"dev-next": "5.x-dev"
6666
}
6767
},
6868
"minimum-stability": "stable",

deptrac.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ deptrac:
3838
value: ^Deprecated$
3939
ruleset:
4040
Toolkit:
41-
- Attributes
4241
Domain:
4342
- Toolkit
4443
Application:

docs/guide/toolkit/results.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ Alternatively, you can provide the `failed()` method with an error object or a l
125125

126126
The error object provided by this package has the following properties:
127127

128+
- `code`: an enum that identifies the error and can be used to programmatically detect and handle specific errors. It
129+
is intentionally an enum, because to programmatically detect specific errors, the codes need to be a defined list of
130+
values.
128131
- `message`: a string message that describes the error.
129-
- `code`: a backed enum that identifies error and can be used to programmatically detect and handle specific errors. It
130-
is intentionally an enum, because if you need to detect specific errors, the codes need to be a defined list of
131-
values - which is an enum.
132-
- `key`: optionally, a key for the error. This can be used to group errors by keys, for example to group errors by
133-
properties that exist on a command message.
132+
- `key`: optionally, a key for the error. Use this to group errors by keys, for example to group errors by
133+
properties that exist on a command message. The key can be a string or enum.
134134

135135
Error objects _must_ be instantiated with either a code or a message. They are immutable, so you cannot change their
136136
properties after they have been created.
@@ -181,7 +181,7 @@ The error list class is iterable, countable and has `isEmpty()` and `isNotEmpty(
181181
### Keyed Error Sets
182182

183183
If you are using the `key` property on error objects, we provide a keyed set of errors class that groups errors by their
184-
key.
184+
key. Keys can be strings or enums.
185185

186186
To create one, provide error objects to its constructor:
187187

@@ -243,6 +243,16 @@ if ($errors->contains(CancelAttendeeTicketError::AlreadyCancelled)) {
243243
}
244244
```
245245

246+
If you only want to handle one error code at once, use the `code()` method on the errors list. This will return the first error code, or `null` if there are no error codes.
247+
248+
```php
249+
$explanation = match ($errors->code()) {
250+
CancelAttendeeTicketError::AlreadyCancelled => 'The ticket has already been cancelled.',
251+
CancelAttendeeTicketError::NotFound => 'The ticket was not found.',
252+
default => null,
253+
};
254+
```
255+
246256
## Exception
247257

248258
We provide a `FailedResultException` that you can use to throw a result object:

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ parameters:
33
paths:
44
- src
55
- tests
6-
excludePaths:
7-
- tests/Unit/Domain/TestReadOnlyEntity.php
86
treatPhpDocTypesAsCertain: false

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
cacheDirectory=".phpunit.cache"
1212
backupStaticProperties="false"
1313
failOnWarning="true"
14-
failOnDeprecation="false"
14+
failOnDeprecation="true"
1515
failOnNotice="true"
1616
>
1717
<coverage/>

pint.json

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
{
22
"preset": "psr12",
33
"rules": {
4+
"array_syntax": true,
5+
"assign_null_coalescing_to_coalesce_equal": true,
6+
"clean_namespace": true,
47
"declare_strict_types": true,
8+
"list_syntax": true,
9+
"no_empty_phpdoc": true,
10+
"no_superfluous_elseif": true,
11+
"no_superfluous_phpdoc_tags": {
12+
"remove_inheritdoc": true
13+
},
14+
"no_unneeded_braces": true,
15+
"no_useless_nullsafe_operator": true,
16+
"no_whitespace_before_comma_in_array": true,
17+
"normalize_index_brace": true,
18+
"nullable_type_declaration": true,
19+
"nullable_type_declaration_for_default_null_value": true,
20+
"ordered_attributes": true,
21+
"ordered_traits": true,
22+
"ordered_types": {
23+
"null_adjustment": "always_last"
24+
},
25+
"phpdoc_summary": true,
26+
"phpdoc_trim": true,
27+
"phpdoc_types": true,
28+
"phpdoc_types_order": {
29+
"null_adjustment": "always_last"
30+
},
31+
"simple_to_complex_string_variable": true,
32+
"ternary_to_null_coalescing": true,
533
"trailing_comma_in_multiline": {
634
"elements": ["arguments", "arrays", "match", "parameters"]
7-
},
8-
"nullable_type_declaration": true
9-
},
10-
"notPath": [
11-
"tests/Unit/Domain/TestReadOnlyEntity.php"
12-
]
13-
}
35+
}
36+
}
37+
}

src/Application/Bus/CommandDispatcher.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@
2323
class CommandDispatcher implements ICommandDispatcher
2424
{
2525
/**
26-
* @var array<string|callable>
26+
* @var array<callable|string>
2727
*/
2828
private array $pipes = [];
2929

30-
/**
31-
* CommandDispatcher constructor.
32-
*
33-
* @param CommandHandlerContainer $handlers
34-
* @param PipeContainer|null $middleware
35-
*/
3630
public function __construct(
3731
private readonly CommandHandlerContainer $handlers,
3832
private readonly ?PipeContainer $middleware = null,
@@ -42,8 +36,7 @@ public function __construct(
4236
/**
4337
* Dispatch messages through the provided pipes.
4438
*
45-
* @param array<string|callable> $pipes
46-
* @return void
39+
* @param array<callable|string> $pipes
4740
*/
4841
public function through(array $pipes): void
4942
{
@@ -52,9 +45,6 @@ public function through(array $pipes): void
5245
$this->pipes = $pipes;
5346
}
5447

55-
/**
56-
* @inheritDoc
57-
*/
5848
public function dispatch(Command $command): Result
5949
{
6050
$pipeline = PipelineBuilder::make($this->middleware)
@@ -71,7 +61,6 @@ public function dispatch(Command $command): Result
7161
}
7262

7363
/**
74-
* @param Command $command
7564
* @return Result<mixed>
7665
*/
7766
private function execute(Command $command): Result

src/Application/Bus/CommandHandler.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@
1717
use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command;
1818
use CloudCreativity\Modules\Contracts\Toolkit\Result\Result;
1919

20-
final class CommandHandler implements ICommandHandler
20+
final readonly class CommandHandler implements ICommandHandler
2121
{
22-
/**
23-
* CommandHandler constructor.
24-
*
25-
* @param object $handler
26-
*/
27-
public function __construct(private readonly object $handler)
22+
public function __construct(private object $handler)
2823
{
2924
}
3025

31-
/**
32-
* @inheritDoc
33-
*/
3426
public function __invoke(Command $command): Result
3527
{
3628
assert(method_exists($this->handler, 'execute'), sprintf(
@@ -46,9 +38,6 @@ public function __invoke(Command $command): Result
4638
return $result;
4739
}
4840

49-
/**
50-
* @inheritDoc
51-
*/
5241
public function middleware(): array
5342
{
5443
if ($this->handler instanceof DispatchThroughMiddleware) {

0 commit comments

Comments
 (0)