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

ChargeBackReason   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromName() 0 8 3
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