MonnifyPaymentMethod::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Created By: Henry Ejemuta
4
 * Project: laravel-monnify
5
 * Class Name: MonnifyPaymentMethod.php
6
 * Date Created: 7/15/20
7
 * Time Created: 12:05 AM
8
 */
9
10
namespace HenryEjemuta\LaravelMonnify\Classes;
11
12
13
class MonnifyPaymentMethod
14
{
15
    private $id;
16
    private $method;
17
18
    private static $cache = [];
19
    private const CARD = "CARD";
20
    private const ACCOUNT_TRANSFER = "ACCOUNT_TRANSFER";
21
22
    /**
23
     * MonnifyPaymentMethod constructor.
24
     * @param int $id
25
     * @param string $method
26
     */
27
    private function __construct(int $id, string $method)
28
    {
29
        $this->id = $id;
30
        $this->method = $method;
31
    }
32
33
    public static function CARD(): MonnifyPaymentMethod
34
    {
35
        if (!key_exists(self::CARD, self::$cache))
36
            self::$cache[self::CARD] = new MonnifyPaymentMethod(1, self::CARD);
37
        return self::$cache[self::CARD];
38
    }
39
40
    public static function ACCOUNT_TRANSFER(): MonnifyPaymentMethod
41
    {
42
        if (!key_exists(self::ACCOUNT_TRANSFER, self::$cache))
43
            self::$cache[self::ACCOUNT_TRANSFER] = new MonnifyPaymentMethod(2, self::ACCOUNT_TRANSFER);
44
        return self::$cache[self::ACCOUNT_TRANSFER];
45
    }
46
47
    public function getID(): int
48
    {
49
        return $this->id;
50
    }
51
52
    public function getMethod(): string
53
    {
54
        return $this->method;
55
    }
56
57
    public static function findPaymentMethod(int $id): MonnifyPaymentMethod
58
    {
59
        switch ($id) {
60
            case 1:
61
                return self::CARD();
62
            case 2:
63
                return self::ACCOUNT_TRANSFER();
64
            default:
65
                return null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return null returns the type null which is incompatible with the type-hinted return HenryEjemuta\LaravelMonn...es\MonnifyPaymentMethod.
Loading history...
66
        }
67
    }
68
69
    public function __toString(): string
70
    {
71
        return $this->getMethod();
72
    }
73
}
74