Total Complexity | 5 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | trait SelfAware |
||
14 | { |
||
15 | use BaseSelfAware { |
||
16 | BaseSelfAware::resolveItem as baseResolveItem; |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * Retrieve the given item of this case. |
||
21 | * |
||
22 | * @template TItemValue |
||
23 | * |
||
24 | * @param (callable(self): TItemValue)|string $item |
||
|
|||
25 | * @return TItemValue |
||
26 | * @throws ValueError |
||
27 | */ |
||
28 | 2 | public function resolveItem(callable|string $item): mixed |
|
29 | { |
||
30 | try { |
||
31 | 2 | return $this->baseResolveItem($item); |
|
32 | 2 | } catch (ValueError $e) { |
|
33 | try { |
||
34 | /** @var string $item */ |
||
35 | 2 | return $this->resolveTranslation($item); |
|
36 | 1 | } catch (ValueError) { |
|
37 | 1 | throw $e; |
|
38 | } |
||
39 | } |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Retrieve the translation of the given key for this case. |
||
44 | * |
||
45 | * @throws ValueError |
||
46 | */ |
||
47 | 2 | public function resolveTranslation(string $key): string |
|
58 | } |
||
59 | } |
||
60 |