Completed
Push — master ( 8e0025...04518a )
by
05:55
created

Currency::getMinMaxs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpMob\Omise;
13
14
/**
15
 * @author Ishmael Doss <[email protected]>
16
 */
17
final class Currency
18
{
19
    const THB = 'thb';
20
    const JPY = 'jpy';
21
    const SGD = 'sgd';
22
    const USD = 'usd';
23
    const EUR = 'eur';
24
25
    private function __construct()
26
    {
27
    }
28
29
    /**
30
     * @param string $countryCode
31
     *
32
     * @return array
33
     */
34
    public static function getSupporteds($countryCode)
35
    {
36
        return [
37
            Country::JP => [
38
                self::JPY,
39
            ],
40
            Country::SG => [
41
                self::SGD,
42
            ],
43
            Country::TH => [
44
                self::THB,
45
                self::JPY,
46
                self::SGD,
47
                self::USD,
48
                self::EUR,
49
            ],
50
        ][strtolower($countryCode)];
51
    }
52
53
    /**
54
     * @param string $code
55
     *
56
     * @return array
57
     */
58
    public static function getMinMaxs($code)
59
    {
60
        return [
61
            self::JPY => [100, 2000000],
62
            self::SGD => [100, 2000000],
63
            self::THB => [100, 100000000],
64
        ][strtolower($code)];
65
    }
66
67
    /**
68
     * @param string $code
69
     *
70
     * @return int
71
     */
72 View Code Duplication
    public static function getDivisionOffset($code)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        return [
75
            self::JPY => 1,
76
            self::SGD => 100,
77
            self::THB => 100,
78
        ][strtolower($code)];
79
    }
80
81
    /**
82
     * @param string $code
83
     *
84
     * @return int
85
     */
86 View Code Duplication
    public static function getSymblo($code)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        return [
89
            self::JPY => '¥',
90
            self::SGD => '$',
91
            self::THB => '฿',
92
        ][strtolower($code)];
93
    }
94
95
    /**
96
     * @param int $amount
97
     * @param string $code
98
     *
99
     * @return int
100
     */
101
    public static function convert($amount, $code)
102
    {
103
        return $amount * self::getDivisionOffset($code);
104
    }
105
106
    /**
107
     * @param int $amount
108
     * @param string $code
109
     *
110
     * @return int
111
     */
112
    public static function format($amount, $code)
113
    {
114
        if ($amount) {
115
            return $amount / self::getDivisionOffset($code);
116
        }
117
118
        return $amount;
119
    }
120
}
121