Currency::getMinMaxs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 2
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
declare(strict_types=1);
13
14
namespace PhpMob\Omise;
15
16
/**
17
 * @author Ishmael Doss <[email protected]>
18
 */
19
final class Currency
20
{
21
    const THB = 'thb';
22
    const JPY = 'jpy';
23
    const SGD = 'sgd';
24
    const USD = 'usd';
25
    const EUR = 'eur';
26
27
    private function __construct()
28
    {
29
    }
30
31
    /**
32
     * @param string $countryCode
33
     *
34
     * @return array
35
     */
36 4
    public static function getSupporteds($countryCode)
37
    {
38
        return [
39 4
            Country::JP => [
40 4
                self::JPY,
41
            ],
42 4
            Country::SG => [
43 4
                self::SGD,
44
            ],
45 4
            Country::TH => [
46 4
                self::THB,
47 4
                self::JPY,
48 4
                self::SGD,
49 4
                self::USD,
50 4
                self::EUR,
51
            ],
52 4
        ][strtolower($countryCode)];
53
    }
54
55
    /**
56
     * @param string $code
57
     *
58
     * @return array
59
     */
60
    public static function getMinMaxs($code)
61
    {
62
        return [
63
            self::JPY => [100, 2000000],
64
            self::SGD => [100, 2000000],
65
            self::THB => [2000, 100000000],
66
        ][strtolower($code)];
67
    }
68
69
    /**
70
     * @param string $code
71
     *
72
     * @return int
73
     */
74 4 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...
75
    {
76
        return [
77 4
            self::JPY => 1,
78 4
            self::SGD => 100,
79 4
            self::THB => 100,
80 4
        ][strtolower($code)];
81
    }
82
83
    /**
84
     * @param string $code
85
     *
86
     * @return int
87
     */
88 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...
89
    {
90
        return [
91
            self::JPY => '¥',
92
            self::SGD => '$',
93
            self::THB => '฿',
94
        ][strtolower($code)];
95
    }
96
97
    /**
98
     * @param int $amount
99
     * @param string $code
100
     *
101
     * @return int
102
     */
103
    public static function convert($amount, $code)
104
    {
105
        return $amount * self::getDivisionOffset($code);
106
    }
107
108
    /**
109
     * @param int $amount
110
     * @param string $code
111
     *
112
     * @return int
113
     */
114
    public static function format($amount, $code)
115
    {
116
        if ($amount) {
117
            return $amount / self::getDivisionOffset($code);
118
        }
119
120
        return $amount;
121
    }
122
}
123