File tree Expand file tree Collapse file tree 3 files changed +28
-53
lines changed
Expand file tree Collapse file tree 3 files changed +28
-53
lines changed Original file line number Diff line number Diff line change 22
33namespace ProgrammatorDev \OpenWeatherMap \Language ;
44
5+ use ProgrammatorDev \OpenWeatherMap \Util \ClassConstantsTrait ;
6+
57class Language
68{
9+ use ClassConstantsTrait;
10+
711 public const AFRIKAANS = 'af ' ;
812 public const ALBANIAN = 'al ' ;
913 public const ARABIC = 'ar ' ;
@@ -53,53 +57,6 @@ class Language
5357
5458 public static function getList (): array
5559 {
56- return [
57- self ::AFRIKAANS ,
58- self ::ALBANIAN ,
59- self ::ARABIC ,
60- self ::AZERBAIJANI ,
61- self ::BULGARIAN ,
62- self ::CATALAN ,
63- self ::CZECH ,
64- self ::DANISH ,
65- self ::GERMAN ,
66- self ::GREEK ,
67- self ::ENGLISH ,
68- self ::SPANISH ,
69- self ::BASQUE ,
70- self ::PERSIAN_FARSI ,
71- self ::FINNISH ,
72- self ::FRENCH ,
73- self ::GALICIAN ,
74- self ::HEBREW ,
75- self ::HINDI ,
76- self ::CROATIAN ,
77- self ::HUNGARIAN ,
78- self ::INDONESIAN ,
79- self ::ITALIAN ,
80- self ::JAPANESE ,
81- self ::KOREAN ,
82- self ::LATVIAN ,
83- self ::LITHUANIAN ,
84- self ::MACEDONIAN ,
85- self ::NORWEGIAN ,
86- self ::DUTCH ,
87- self ::POLISH ,
88- self ::PORTUGUESE ,
89- self ::PORTUGUESE_BRAZIL ,
90- self ::ROMANIAN ,
91- self ::RUSSIAN ,
92- self ::SWEDISH ,
93- self ::SLOVAK ,
94- self ::SLOVENIAN ,
95- self ::SERBIAN ,
96- self ::THAI ,
97- self ::TURKISH ,
98- self ::UKRAINIAN ,
99- self ::VIETNAMESE ,
100- self ::CHINESE_SIMPLIFIED ,
101- self ::CHINESE_TRADITIONAL ,
102- self ::ZULU
103- ];
60+ return (new Language )->getClassConstants (self ::class);
10461 }
10562}
Original file line number Diff line number Diff line change 22
33namespace ProgrammatorDev \OpenWeatherMap \UnitSystem ;
44
5+ use ProgrammatorDev \OpenWeatherMap \Util \ClassConstantsTrait ;
6+
57class UnitSystem
68{
9+ use ClassConstantsTrait;
10+
711 public const METRIC = 'metric ' ;
812 public const IMPERIAL = 'imperial ' ;
913 public const STANDARD = 'standard ' ;
1014
1115 public static function getList (): array
1216 {
13- return [
14- self ::METRIC ,
15- self ::IMPERIAL ,
16- self ::STANDARD
17- ];
17+ return (new UnitSystem )->getClassConstants (self ::class);
1818 }
1919}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace ProgrammatorDev \OpenWeatherMap \Util ;
4+
5+ trait ClassConstantsTrait
6+ {
7+ private function getClassConstants (string $ className ): array
8+ {
9+ $ reflection = new \ReflectionClass ($ className );
10+ $ constants = $ reflection ->getConstants ();
11+
12+ // Sort by alphabetical order
13+ // to be more intuitive when listing values for error messages
14+ \asort ($ constants );
15+
16+ return $ constants ;
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments