| Total Complexity | 11 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 |
||
| 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; |
||
|
|
|||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | public function __toString(): string |
||
| 72 | } |
||
| 73 | } |
||
| 74 |