PaymentProviders::paymentProviderFactory()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 17
rs 9.9666
1
<?php declare(strict_types=1);
2
3
namespace Getloy;
4
5
use \Exception;
6
use Getloy\PaymentProviders\PaymentProvider;
7
use Getloy\PaymentProviders\PaymentProviderPaywayKh;
8
use Getloy\PaymentProviders\PaymentProviderPipayKh;
9
use Getloy\PaymentProviders\PaymentProviderIpay88Kh;
10
11
/**
12
 * Provides payment provider identifiers and a factory method to instantiate payment method classes.
13
 * @since 1.0.0
14
 */
15
class PaymentProviders
16
{
17
    /* Payment provider identifier for PayWay by ABA Bank */
18
    const PAYWAY_KH = 'payway_kh';
19
    /* Payment provider identifier for Pi Pay */
20
    const PIPAY_KH = 'pipay_kh';
21
    /* Payment provider identifier for iPay88 Cambodia */
22
    const IPAY88_KH = 'ipay88_kh';
23
24
    /**
25
     * Creates a GetloyPaymentProvider object for the specified provider.
26
     * @param string $paymentMethod Payment method identifier.
27
     * @param array $config Configuration for the payment method.
28
     * @return PaymentProvider The payment provider object.
29
     * @throws Exception If the provided payment method is unsupported or the payment method
30
     *                   configuration is incomplete.
31
     * @ignore description
32
     */
33
    public static function paymentProviderFactory(
34
        string $paymentMethod,
35
        array $config
36
    ): PaymentProvider {
37
38
        switch ($paymentMethod) {
39
            case self::PAYWAY_KH:
40
                return new PaymentProviderPaywayKh($config);
41
42
            case self::PIPAY_KH:
43
                return new PaymentProviderPipayKh($config);
44
45
            case self::IPAY88_KH:
46
                return new PaymentProviderIpay88Kh($config);
47
48
            default:
49
                throw new Exception('Unsupported payment method ' . $paymentMethod);
50
        }
51
    }
52
}
53