File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -46,13 +46,18 @@ public function getCountry(): string {
4646 $ reader = new Reader (__DIR__ . '/../vendor/GeoLite2-Country.mmdb ' );
4747 $ record = $ reader ->get ($ this ->request ->getRemoteAddress ());
4848 } catch (\Exception $ e ) {
49- return ' -- ' ;
49+ return CountryMapper:: GLOBAL ;
5050 }
5151
52- if ($ this ->countryMapper ->isValidCountry ($ record ['country ' ]['iso_code ' ])) {
52+ if ($ record === null ) {
53+ // No match found, e.g. for local address like 127.0.0.1
54+ return CountryMapper::GLOBAL ;
55+ }
56+
57+ if ($ this ->countryMapper ->isValidCountry ($ record ['country ' ]['iso_code ' ])) {
5358 return $ record ['country ' ]['iso_code ' ];
5459 }
5560
56- return ' -- ' ;
61+ return CountryMapper:: GLOBAL ;
5762 }
5863}
Original file line number Diff line number Diff line change 2424use OCP \IL10N ;
2525
2626class CountryMapper {
27+
28+ public const GLOBAL = '-- ' ;
29+
2730 /** @var IL10N */
2831 private $ l ;
2932
@@ -48,7 +51,7 @@ public function isValidCountry($countryCode): bool {
4851 */
4952 public function getCountries (): array {
5053 $ countries = [
51- ' -- ' => $ this ->l ->t ('Global ' ),
54+ self :: GLOBAL => $ this ->l ->t ('Global ' ),
5255 'AF ' => $ this ->l ->t ('Afghanistan ' ),
5356 'AX ' => $ this ->l ->t ('Åland Islands ' ),
5457 'AL ' => $ this ->l ->t ('Albania ' ),
Original file line number Diff line number Diff line change @@ -55,8 +55,8 @@ public function getTermsForCountryCode(string $countryCode): array {
5555 }
5656 $ result ->closeCursor ();
5757
58- if (empty ($ entities ) && $ countryCode !== ' -- ' ) {
59- return $ this ->getTermsForCountryCode (' -- ' );
58+ if (empty ($ entities ) && $ countryCode !== CountryMapper:: GLOBAL ) {
59+ return $ this ->getTermsForCountryCode (CountryMapper:: GLOBAL );
6060 }
6161
6262 return $ entities ;
You can’t perform that action at this time.
0 commit comments