|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | use Careship\Functional\Either\Either;
|
10 |
| -use Careship\Functional\Either\No; |
11 | 10 | use Careship\Functional\Either\Reason;
|
12 |
| -use Careship\Functional\Either\Yes; |
13 | 11 | use Careship\Functional\Maybe\Maybe;
|
| 12 | +use Careship\Functional\Result\ExceptionStack; |
14 | 13 | use Careship\Functional\Result\Result;
|
| 14 | +use function Careship\Functional\Either\handle_either; |
15 | 15 | use function Careship\Functional\Either\no;
|
16 | 16 | use function Careship\Functional\Either\yes;
|
17 | 17 | use function Careship\Functional\extract_some_or_fail;
|
| 18 | +use function Careship\Functional\Result\handle_result; |
18 | 19 | use function Careship\Functional\Result\result;
|
19 |
| -use function Careship\Functional\success_or_fail; |
20 | 20 |
|
21 | 21 | final class Customer {
|
22 | 22 | /** @var bool */
|
@@ -68,18 +68,20 @@ public function verifyEmail(string $customerId): Result
|
68 | 68 |
|
69 | 69 | $customerService = new CustomerService();
|
70 | 70 |
|
71 |
| -/** @var Either $wasCustomerVerified */ |
72 |
| -$wasCustomerVerified = success_or_fail( |
| 71 | +return handle_result( |
73 | 72 | $customerService->verifyEmail('some_customer_id'),
|
74 |
| - 'Cannot verify customer email' |
| 73 | + function (Either $wasCustomerVerified) { |
| 74 | + return handle_either( |
| 75 | + $wasCustomerVerified, |
| 76 | + function() { |
| 77 | + return 'Customer successfully verified'; |
| 78 | + }, |
| 79 | + function (Reason $reason) { |
| 80 | + return $reason->toString(); |
| 81 | + } |
| 82 | + ); |
| 83 | + }, |
| 84 | + function (ExceptionStack $exceptionStack) { |
| 85 | + $exceptionStack->toString(); |
| 86 | + } |
75 | 87 | );
|
76 |
| - |
77 |
| -switch (true) { |
78 |
| - case $wasCustomerVerified instanceof Yes: |
79 |
| - echo 'customer successfully verified'; |
80 |
| - break; |
81 |
| - case $wasCustomerVerified instanceof No: |
82 |
| - /** @var Reason $reason */ |
83 |
| - $reason = $wasCustomerVerified->extract(); |
84 |
| - echo $reason->toString(); |
85 |
| -} |
|
0 commit comments