Passed
Push — main ( ecb15a...097c61 )
by Iain
04:34
created

ChargeBackReason::fromName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Iain Cambridge 2020-2023.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Billing\Enum;
16
17
enum ChargeBackReason: string
18
{
19
    case BANK_CANNOT_PROCESS = 'bank_cannot_process';
20
    case CHECK_RETURNED = 'check_returned';
21
    case CREDIT_NOT_PROCESSED = 'credit_not_processed';
22
    case CUSTOMER_INITIATED = 'customer_initiated';
23
    case DEBIT_NOT_AUTHORISED = 'debit_not_authorised';
24
    case DUPLICATE = 'duplicate';
25
    case FRAUDULENT = 'fraudulent';
26
    case GENERAL = 'general';
27
    case INCORRECT_ACCOUNT_DETAILS = 'incorrect_account_details';
28
    case INSUFFICIENT_FUNDS = 'insufficient_funds';
29
    case PRODUCT_NOT_RECEIVED = 'product_not_received';
30
    case PRODUCT_UNACCEPTABLE = 'product_unacceptable';
31
    case SUBSCRIPTION_CANCELED = 'subscription_canceled';
32
    case UNRECOGNIZED = 'unrecognized';
33
34
    public static function fromName(string $name): self
35
    {
36
        foreach (self::cases() as $status) {
37
            if ($name === $status->value) {
38
                return $status;
39
            }
40
        }
41
        throw new \ValueError("$name is not a valid backing value for enum ".self::class);
42
    }
43
}
44