Skip to content

Commit 5878811

Browse files
committed
Refactor
1 parent eb8036b commit 5878811

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/BrowserLocale.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ class BrowserLocale
1212
*/
1313
protected $locales = [];
1414

15+
/**
16+
* Supported filters for getLocales().
17+
*
18+
* @var array
19+
*/
20+
protected $filters = ['full', 'language', 'country', 'weight'];
21+
1522
/**
1623
* Create a new BrowserLocale instance.
1724
*
@@ -32,7 +39,7 @@ public function __construct($httpAcceptLanguages)
3239
*/
3340
public function getLocale()
3441
{
35-
return isset($this->locales[0]) ? $this->locales[0] : null;
42+
return $this->locales[0] ?? null;
3643
}
3744

3845
/**
@@ -41,7 +48,7 @@ public function getLocale()
4148
* If a property filter is specified, a flattened array of locale information,
4249
* containing only the requested property values will be returned instead.
4350
*
44-
* @param string $propertyFilter full|language|country|weight
51+
* @param string $propertyFilter
4552
*
4653
* @return array
4754
*/
@@ -142,7 +149,7 @@ protected function splitAcceptLanguage($httpAcceptLanguage)
142149
*/
143150
protected function getLanguage($locale)
144151
{
145-
return strtolower(substr($locale, 0, 2));
152+
return substr($locale, 0, 2);
146153
}
147154

148155
/**
@@ -160,7 +167,7 @@ protected function getCountry($locale)
160167
return '';
161168
}
162169

163-
return strtoupper(substr($locale, $divider + 1, 2));
170+
return substr($locale, $divider + 1, 2);
164171
}
165172

166173
/**
@@ -210,10 +217,9 @@ protected function sortLocales()
210217
*/
211218
protected function filterLocaleInfo($property)
212219
{
213-
$filters = ['full', 'language', 'country', 'weight'];
214220
$locales = $this->locales;
215221

216-
if ( ! in_array($property, $filters)) {
222+
if ( ! in_array($property, $this->filters)) {
217223
return $locales;
218224
}
219225

0 commit comments

Comments
 (0)