These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Recca0120\LoDash\JString\Extensions; |
||
4 | |||
5 | use ArrayObject; |
||
6 | |||
7 | class Converter |
||
8 | { |
||
9 | /** |
||
10 | * $instance. |
||
11 | * |
||
12 | * @var static |
||
13 | */ |
||
14 | protected static $instance; |
||
15 | |||
16 | /** |
||
17 | * $default. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $default = 'zh-tw'; |
||
22 | |||
23 | /** |
||
24 | * __construct. |
||
25 | */ |
||
26 | 2 | private function __construct() |
|
27 | { |
||
28 | // $this->table = [ |
||
29 | // 'zh-hans' => new ArrayObject(\MediaWiki\Languages\Data\ZhConversion::$zh2Hans), |
||
30 | // 'zh-hant' => new ArrayObject(\MediaWiki\Languages\Data\ZhConversion::$zh2Hant), |
||
31 | // 'zh-cn' => new ArrayObject(\MediaWiki\Languages\Data\ZhConversion::$zh2CN), |
||
32 | // 'zh-hk' => new ArrayObject(\MediaWiki\Languages\Data\ZhConversion::$zh2HK), |
||
33 | // 'zh-mo' => new ArrayObject(\MediaWiki\Languages\Data\ZhConversion::$zh2HK), |
||
34 | // 'zh-my' => new ArrayObject(\MediaWiki\Languages\Data\ZhConversion::$zh2CN), |
||
35 | // 'zh-sg' => new ArrayObject(\MediaWiki\Languages\Data\ZhConversion::$zh2CN), |
||
36 | // 'zh-tw' => new ArrayObject(\MediaWiki\Languages\Data\ZhConversion::$zh2TW), |
||
37 | // 'zh' => new ArrayObject([]), |
||
38 | // ]; |
||
39 | |||
40 | 2 | $path = __DIR__.'/../../../resources/Mediawiki/Languages/Data/'; |
|
41 | |||
42 | 2 | $this->table = [ |
|
0 ignored issues
–
show
|
|||
43 | 2 | 'zh-hans' => new ArrayObject(require($path.'/zh2Hans.php')), |
|
44 | 2 | 'zh-hant' => new ArrayObject(require($path.'/zh2Hant.php')), |
|
45 | 2 | 'zh-cn' => new ArrayObject(require($path.'/zh2CN.php')), |
|
46 | 2 | 'zh-hk' => new ArrayObject(require($path.'/zh2HK.php')), |
|
47 | 2 | 'zh-tw' => new ArrayObject(require($path.'/zh2TW.php')), |
|
48 | 2 | 'zh' => new ArrayObject([]), |
|
49 | ]; |
||
50 | |||
51 | 2 | $this->table['zh-mo'] = $this->table['zh-hk']; |
|
52 | 2 | $this->table['zh-my'] = $this->table['zh-cn']; |
|
53 | 2 | $this->table['zh-sg'] = $this->table['zh-cn']; |
|
54 | |||
55 | 2 | $this->table['zh-cn'] = new ArrayObject( |
|
56 | 2 | $this->table['zh-cn']->getArrayCopy() + $this->table['zh-hans']->getArrayCopy() |
|
57 | 2 | ); |
|
58 | |||
59 | 2 | $this->table['zh-hk'] = new ArrayObject( |
|
60 | 2 | $this->table['zh-hk']->getArrayCopy() + $this->table['zh-hant']->getArrayCopy() |
|
61 | 2 | ); |
|
62 | |||
63 | 2 | $this->table['zh-my'] = new ArrayObject( |
|
64 | 2 | $this->table['zh-my']->getArrayCopy() + $this->table['zh-hans']->getArrayCopy() |
|
65 | 2 | ); |
|
66 | |||
67 | 2 | $this->table['zh-sg'] = new ArrayObject( |
|
68 | 2 | $this->table['zh-sg']->getArrayCopy() + $this->table['zh-hans']->getArrayCopy() |
|
69 | 2 | ); |
|
70 | |||
71 | 2 | $this->table['zh-tw'] = new ArrayObject( |
|
72 | 2 | $this->table['zh-tw']->getArrayCopy() + $this->table['zh-hant']->getArrayCopy() |
|
73 | 2 | ); |
|
74 | 2 | } |
|
75 | |||
76 | /** |
||
77 | * convertTo. |
||
78 | * |
||
79 | * @param string $str |
||
80 | * @param string $variant |
||
81 | * @return string |
||
82 | */ |
||
83 | 2 | public function convertTo($str, $variant = 'zh-TW') |
|
84 | { |
||
85 | 2 | $variant = strtolower($variant); |
|
86 | 2 | $arrayObject = isset($this->table[$variant]) === true ? $this->table[$variant] : $this->table[$this->default]; |
|
87 | 2 | $data = $arrayObject->getArrayCopy(); |
|
88 | |||
89 | 2 | return strtr($str, $data); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * instance. |
||
94 | * |
||
95 | * @return static |
||
96 | */ |
||
97 | 2 | public static function instance() |
|
98 | { |
||
99 | 2 | return static::$instance ?: new static(); |
|
100 | } |
||
101 | } |
||
102 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: