OrderStatus::fromValue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 8
rs 10
1
<?php
2
namespace Stadem\VivaPayments\Enums;
3
enum OrderStatus : int
4
{
5
    case PENDING  = 0;
6
    case EXPIRED = 1;
7
    case CANCELED = 2;
8
    case PAID = 3;
9
10
    
11
    
12
    public function type(): int
13
    {
14
        return match($this) 
15
        {
16
            OrderStatus::PENDING => 'Pending',
17
            OrderStatus::EXPIRED => 'Expired', 
18
            OrderStatus::CANCELED => 'Canceled',   
19
            OrderStatus::PAID => 'Paid', 
20
        };
21
    }
22
23
    public static function fromValue(int $value): string
24
    {
25
        foreach (self::cases() as $status) {
26
            if( $value === $status->value ){
27
                return $status->name;
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Stadem\VivaPayments\Enums\OrderStatus. Did you maybe forget to declare it?
Loading history...
28
            }
29
        }
30
        throw new \ValueError("$value is not a valid backing value for enum " . self::class );
31
    }
32
33
}
34
35
// https://developer.viva.com/apis-for-payments/payment-api/#tag/Payments/paths/~1api~1orders~1{orderCode}/get
36