Skip to content

Commit 8ca4377

Browse files
committed
Merge branch 'release/2.2.1'
2 parents 3d19256 + 49d65f4 commit 8ca4377

File tree

8 files changed

+30
-15
lines changed

8 files changed

+30
-15
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [8.1, 8.2, 8.3]
14+
php: [8.1, 8.2, 8.3, 8.4]
1515
dependency-version: [prefer-stable]
1616
os: [ubuntu-latest]
1717

1818
name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
1919

2020
steps:
2121
- name: Checkout code
22-
uses: actions/checkout@v2
22+
uses: actions/checkout@v4
2323

2424
- name: Setup PHP
2525
uses: shivammathur/setup-php@v2
@@ -42,7 +42,7 @@ jobs:
4242

4343
steps:
4444
- name: Checkout code
45-
uses: actions/checkout@v2
45+
uses: actions/checkout@v4
4646
with:
4747
fetch-depth: 0
4848

@@ -71,7 +71,7 @@ jobs:
7171

7272
steps:
7373
- name: Checkout code
74-
uses: actions/checkout@v2
74+
uses: actions/checkout@v4
7575

7676
- name: Setup PHP
7777
uses: shivammathur/setup-php@v2

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
2626
- Nothing
2727

2828

29+
## 2.2.1 - 2024-11-22
30+
31+
### Added
32+
- Full support for PHP 8.4
33+
34+
### Changed
35+
- Improved error message for invalid meta
36+
37+
2938
## 2.2.0 - 2024-11-19
3039

3140
### Added

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ enum BackedEnum: int
138138

139139
The above enum defines 3 meta for each case: `color`, `shape` and `isOdd`. The `#[Meta]` attributes are ideal to declare static information, whilst public non-static methods are ideal to declare dynamic information.
140140

141+
To access a case meta, we can simply call the method having the same name of the wanted meta:
142+
143+
```php
144+
BackedEnum::Two->color(); // green
145+
```
146+
141147
`#[Meta]` attributes can also be attached to the enum itself to provide default values when a case does not declare its own meta values:
142148

143149
```php

src/CasesCollection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ public function toArray(): array
112112
/**
113113
* Retrieve the first case.
114114
*
115-
* @param (callable(TValue, array-key): bool)|null $callback
115+
* @param ?callable(TValue, array-key): bool $callback
116116
* @return ?TValue
117117
*/
118-
public function first(callable $callback = null): mixed
118+
public function first(?callable $callback = null): mixed
119119
{
120120
$callback ??= fn() => true;
121121

@@ -159,7 +159,7 @@ public function values(): array
159159
* @param (callable(TValue): array-key)|string|null $key
160160
* @return array<array-key, TPluckValue>
161161
*/
162-
public function pluck(callable|string $value, callable|string $key = null): array
162+
public function pluck(callable|string $value, callable|string|null $key = null): array
163163
{
164164
$result = [];
165165

src/Concerns/CollectsCases.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public static function count(): int
3030
/**
3131
* Retrieve the first case.
3232
*
33-
* @param (callable(self, array-key): bool)|null $callback
33+
* @param ?callable(self, array-key): bool $callback
3434
*/
35-
public static function first(callable $callback = null): ?self
35+
public static function first(?callable $callback = null): ?self
3636
{
3737
return self::collect()->first($callback);
3838
}
@@ -66,7 +66,7 @@ public static function values(): array
6666
* @param (callable(self): array-key)|string|null $key
6767
* @return array<array-key, TPluckValue>
6868
*/
69-
public static function pluck(callable|string $value, callable|string $key = null): array
69+
public static function pluck(callable|string $value, callable|string|null $key = null): array
7070
{
7171
return self::collect()->pluck($value, $key);
7272
}

src/Concerns/SelfAware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function resolveMetaAttribute(string $meta): mixed
147147
}
148148
}
149149

150-
throw new ValueError(sprintf('"%s" is not a valid meta for enum "%s"', $meta, self::class));
150+
throw new ValueError(sprintf('The case %s::%s has no "%s" meta set', self::class, $this->name, $meta));
151151
}
152152

153153
/**

tests/BackedEnumTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@
394394
});
395395

396396
it('handles the call to an inaccessible case method', fn() => BackedEnum::one->unknownMethod())
397-
->throws(Error::class, '"unknownMethod" is not a valid meta for enum "Cerbero\Enum\BackedEnum"');
397+
->throws(Error::class, 'The case Cerbero\Enum\BackedEnum::one has no "unknownMethod" meta set');
398398

399399
it('runs custom logic when calling an inaccessible case method', function() {
400400
Enums::onCall(function(object $case, string $name, array $arguments) {
@@ -450,7 +450,7 @@
450450
->toBe('red');
451451

452452
it('throws a value error when attempting to retrieve an invalid item', fn() => BackedEnum::one->resolveItem('invalid'))
453-
->throws(ValueError::class, '"invalid" is not a valid meta for enum "Cerbero\Enum\BackedEnum"');
453+
->throws(ValueError::class, 'The case Cerbero\Enum\BackedEnum::one has no "invalid" meta set');
454454

455455
it('retrieves the value of a backed case or the name of a pure case', function() {
456456
expect(BackedEnum::one->value())->toBe(1);

tests/PureEnumTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@
403403
});
404404

405405
it('handles the call to an inaccessible case method', fn() => PureEnum::one->unknownMethod())
406-
->throws(Error::class, '"unknownMethod" is not a valid meta for enum "Cerbero\Enum\PureEnum"');
406+
->throws(Error::class, 'The case Cerbero\Enum\PureEnum::one has no "unknownMethod" meta set');
407407

408408
it('runs custom logic when calling an inaccessible case method', function() {
409409
Enums::onCall(function(object $case, string $name, array $arguments) {
@@ -458,7 +458,7 @@
458458
->toBe('red');
459459

460460
it('throws a value error when attempting to retrieve an invalid item', fn() => PureEnum::one->resolveItem('invalid'))
461-
->throws(ValueError::class, '"invalid" is not a valid meta for enum "Cerbero\Enum\PureEnum"');
461+
->throws(ValueError::class, 'The case Cerbero\Enum\PureEnum::one has no "invalid" meta set');
462462

463463
it('retrieves the value of a backed case or the name of a pure case', function() {
464464
expect(PureEnum::one->value())->toBe('one');

0 commit comments

Comments
 (0)