| 1 |  |  | <?php | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 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 convertToText($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 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 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 |  |  |         } 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 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 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 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 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) | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |         switch (true) { | 
            
                                                                        
                            
            
                                    
            
            
                | 79 | 1 |  |             case $value === 0: | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |                 return ""; | 
            
                                                                        
                            
            
                                    
            
            
                | 81 | 1 |  |             case isset(self::$trans[self::$lang][$value]) : | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 82 | 1 |  |                 return self::$trans[self::$lang][$value]; | 
            
                                                                        
                            
            
                                    
            
            
                | 83 | 1 |  |             case $value < 100: | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 84 | 1 |  |                 $module = $value % 10; | 
            
                                                                        
                            
            
                                    
            
            
                | 85 | 1 |  |                 $division = floor($value / 10); | 
            
                                                                        
                            
            
                                    
            
            
                | 86 | 1 |  |                 if (self::LANG_BG === self::$lang) { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 | 1 |  |                     if (isset(self::$trans[self::$lang][$value])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |                         return self::$trans[self::$lang][$value]; | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |                     } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 90 | 1 |  |                         return self::$trans[self::$lang][$division] . self::$trans[self::$lang]['tens'] . self::$trans[self::$lang]['and'] . self::$trans[self::$lang][$module]; | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |                     } | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |                 } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 93 | 1 |  |                     return self::$trans[self::$lang][$value - $module] . '-' . self::$trans[self::$lang][$module]; | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 95 | 1 |  |             case $value < 1000: | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 96 | 1 |  |                 $module = $value % 100; | 
            
                                                                        
                            
            
                                    
            
            
                | 97 | 1 |  |                 $division = floor($value / 100); | 
            
                                                                        
                            
            
                                    
            
            
                | 98 | 1 |  |                 $and = $module <= 20 || $module % 10 === 0 ? self::$trans[self::$lang]['and'] : ' '; | 
            
                                                                        
                            
            
                                    
            
            
                | 99 | 1 |  |                 if (self::LANG_BG === self::$lang) { | 
            
                                                                        
                            
            
                                    
            
            
                | 100 | 1 |  |                     return (isset(self::$trans[self::$lang][$value - $module]) ? self::$trans[self::$lang][$value - $module] : self::$trans[self::$lang][$division] . self::$trans[self::$lang]['hundreds']) . $and . self::normalize($module); | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |                 } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 102 | 1 |  |                     return self::$trans[self::$lang][$division] . ' ' . self::$trans[self::$lang]['hundreds'] . $and . self::normalize($module); | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |             case $value < 1000000: | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |                 $module = $value % 1000; | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |                 $division = $value / 1000; | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |                 return self::normalize($division) . ' ' . self::$trans[self::$lang]['thousands'] . ' ' . self::normalize($module); | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |             case $value < 1000000000: | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |                 $module = $value % 1000000; | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |                 $division = $value / 1000000; | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |                 $millions = floor($value / 1000000); | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |                 return self::normalize($division) . ' ' . ($millions == 1 ? self::$trans[self::$lang]['million'] : self::$trans[self::$lang]['millions']) . ' ' . self::normalize($module); | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |             default: | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |                 throw new InvalidArgumentException("$value is greeater than 1000000000"); | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |      *  | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |      * @param string $value | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |      *  | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 1 |  |     public static function standartize($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 1 |  |         $original = array('един стотинка', 'два стотинки'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 1 |  |         $standartize = array('една стотинка', 'две стотинки'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 1 |  |         return str_replace($original, $standartize, $value); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 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.