Skip to content

Commit 57d1b75

Browse files
committed
refactor: remove previously deprecated list of errors features
1 parent 94fd7a9 commit 57d1b75

5 files changed

Lines changed: 11 additions & 61 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
All notable changes to this project will be documented in this file. This project adheres to
44
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
55

6+
## Next Major
7+
8+
### Removed
9+
10+
- Removed the deprecated `contains()` method from the `ListOfErrors` interface. Use `any()` instead.
11+
- The `first()` method on the `ListOfErrors` interface no longer accepts arguments. Use `find()` instead.
12+
613
## Unreleased
714

815
## [5.1.0] - 2026-01-01

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/>

src/Contracts/Toolkit/Result/ListOfErrors.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ interface ListOfErrors extends ListIterator
2323
{
2424
/**
2525
* Get the first error in the list, or the first matching error.
26-
*
27-
* @param (Closure(Error): bool)|UnitEnum|null $matcher
2826
*/
29-
public function first(Closure|UnitEnum|null $matcher = null): ?Error;
27+
public function first(): ?Error;
3028

3129
/**
3230
* Find the first matching error in the list.
@@ -42,14 +40,6 @@ public function find(Closure|UnitEnum $matcher): ?Error;
4240
*/
4341
public function sole(Closure|UnitEnum|null $matcher = null): Error;
4442

45-
/**
46-
* Does the list contain a matching error?
47-
*
48-
* @param (Closure(Error): bool)|UnitEnum $matcher
49-
* @deprecated 6.0 use any() instead.
50-
*/
51-
public function contains(Closure|UnitEnum $matcher): bool;
52-
5343
/**
5444
* Does the list contain at least one matching error?
5545
*

src/Toolkit/Result/ListOfErrors.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use CloudCreativity\Modules\Contracts\Toolkit\Result\Error as IError;
1717
use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors as IListOfErrors;
1818
use CloudCreativity\Modules\Toolkit\Iterables\IsList;
19-
use Deprecated;
2019
use LogicException;
2120
use UnitEnum;
2221

@@ -46,18 +45,9 @@ public function __construct(IError ...$errors)
4645
$this->stack = array_values($errors);
4746
}
4847

49-
public function first(Closure|UnitEnum|null $matcher = null): ?IError
48+
public function first(): ?IError
5049
{
51-
if ($matcher === null) {
52-
return $this->stack[0] ?? null;
53-
}
54-
55-
trigger_error(
56-
'Calling first() with a matcher is deprecated and will be removed in 6.0; use find() instead.',
57-
E_USER_DEPRECATED,
58-
);
59-
60-
return $this->find($matcher);
50+
return $this->stack[0] ?? null;
6151
}
6252

6353
public function find(Closure|UnitEnum $matcher): ?IError
@@ -85,12 +75,6 @@ public function sole(Closure|UnitEnum|null $matcher = null): IError
8575
));
8676
}
8777

88-
#[Deprecated(message: 'use any() instead', since: '5.0.0-rc.2')]
89-
public function contains(Closure|UnitEnum $matcher): bool
90-
{
91-
return $this->any($matcher);
92-
}
93-
9478
public function any(Closure|UnitEnum $matcher): bool
9579
{
9680
return array_any($this->stack, $this->where($matcher));

tests/Unit/Toolkit/Result/ListOfErrorsTest.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,6 @@ public function testFirst(): void
9696
$this->assertSame($a, $errors->first());
9797
}
9898

99-
public function testFirstWithMatcher(): void
100-
{
101-
$errors = new ListOfErrors(
102-
new Error(null, 'Message A'),
103-
new Error(null, 'Message B'),
104-
$c = new Error(null, 'Message C'),
105-
new Error(null, 'Message D'),
106-
$e = new Error(code: TestUnitEnum::Bat),
107-
);
108-
109-
$this->assertSame($c, $errors->first(fn (IError $error) => 'Message C' === $error->message()));
110-
$this->assertSame($e, $errors->first(TestUnitEnum::Bat));
111-
$this->assertNull($errors->first(fn (IError $error) => 'Message E' === $error->message()));
112-
$this->assertNull($errors->first(TestUnitEnum::Baz));
113-
}
114-
11599
public function testFind(): void
116100
{
117101
$errors = new ListOfErrors(
@@ -128,21 +112,6 @@ public function testFind(): void
128112
$this->assertNull($errors->find(TestUnitEnum::Baz));
129113
}
130114

131-
public function testContains(): void
132-
{
133-
$errors = new ListOfErrors(
134-
new Error(message: 'Message A'),
135-
new Error(message: 'Message B'),
136-
new Error(message: 'Message C'),
137-
new Error(code: TestUnitEnum::Baz, message: 'Message D'),
138-
);
139-
140-
$this->assertTrue($errors->contains(fn (IError $error) => 'Message C' === $error->message()));
141-
$this->assertTrue($errors->contains(TestUnitEnum::Baz));
142-
$this->assertFalse($errors->contains(fn (IError $error) => 'Message E' === $error->message()));
143-
$this->assertFalse($errors->contains(TestUnitEnum::Bat));
144-
}
145-
146115
public function testAny(): void
147116
{
148117
$errors = new ListOfErrors(

0 commit comments

Comments
 (0)