1 | <?php |
||
3 | class Currency |
||
4 | { |
||
5 | |||
6 | const LANG_BG = 'bg'; |
||
7 | const LANG_EN = 'en'; |
||
8 | |||
9 | /** |
||
10 | * |
||
11 | * @var string |
||
12 | */ |
||
13 | private static $lang; |
||
14 | |||
15 | /** |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | private static $trans; |
||
20 | |||
21 | /** |
||
22 | * |
||
23 | * @param int $amount |
||
24 | * @param string $lang |
||
25 | * |
||
26 | * @return string |
||
27 | * |
||
28 | * @throws Exception |
||
29 | */ |
||
30 | 2 | public static function normalize($amount, $lang = self::LANG_BG) |
|
31 | { |
||
32 | |||
33 | 2 | self::$lang = $lang; |
|
34 | |||
35 | 2 | if (null === self::$trans) { |
|
36 | 1 | self::$trans = parse_ini_file(__DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'lang.ini', true); |
|
37 | 1 | } |
|
38 | |||
39 | 2 | if (!isset(self::$trans[self::$lang])) { |
|
40 | 1 | throw new InvalidArgumentException('Invalid lang specified'); |
|
41 | } |
||
42 | |||
43 | 1 | if (strchr($amount, '.')) { |
|
44 | 1 | list($sum, $cents) = array_map(function($value) { |
|
45 | 1 | settype($value, 'int'); |
|
46 | 1 | return $value; |
|
47 | 1 | }, explode('.', $amount)); |
|
48 | 1 | } else { |
|
49 | $sum = intval($amount); |
||
50 | $cents = 00; |
||
51 | } |
||
52 | |||
53 | $results = array( |
||
54 | 1 | self::normalize($sum), |
|
55 | 1 | $sum == 1 ? self::$trans[self::$lang]['amount'] : self::$trans[self::$lang]['amounts'] |
|
56 | 1 | ); |
|
57 | |||
58 | 1 | if ($cents !== 0) { |
|
59 | 1 | $results[] = trim(self::$trans[self::$lang]['and']); |
|
60 | 1 | $results[] = self::normalize($cents); |
|
61 | 1 | $results[] = $cents == 1 ? self::$trans[self::$lang]['cent'] : self::$trans[self::$lang]['cents']; |
|
62 | 1 | } |
|
63 | |||
64 | 1 | return self::standartize(implode(' ', $results)); |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * |
||
69 | * @param int $value |
||
70 | * |
||
71 | * @return string |
||
72 | * |
||
73 | * @throws Exception |
||
74 | */ |
||
75 | 1 | public static function normalize($value) |
|
117 | |||
118 | /** |
||
119 | * |
||
120 | * @param string $value |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | 1 | public static function standartize($value) |
|
130 | |||
131 | } |
||
132 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.