Skip to content

Commit

Permalink
Merge 513894f into b01aa7f
Browse files Browse the repository at this point in the history
  • Loading branch information
slavcodev committed Sep 4, 2020
2 parents b01aa7f + 513894f commit 612795d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 16 deletions.
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@ Fixed - for any bug fixes.
Security - in case of vulnerabilities.
-->

## [Unreleased]
## 1.1.0 (2020-09-04)

_TBD_
### Added

- Added countries aliases for additional known names

### Changed

- Upgrade minimum PHP version to 7.3
- Updated currencies list

### Deprecated

- Deprecated `findByOfficialName` and `findByCommonName` of `CountryRepository`

### Fixed

- Fixed the region of Canada to North America

## 1.0.0 (2018-12-08)

Expand Down
33 changes: 19 additions & 14 deletions src/CountryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,14 @@ class CountryRepository
'isoAlpha2' => 'MO',
],
'MK' => [
'commonName' => 'Macedonia',
'officialName' => 'Republic of Macedonia',
'commonName' => 'North Macedonia',
'officialName' => 'North Macedonia',
'knownNames' => [
'Macedonia',
'Republic of Macedonia',
'The Former Yugoslav Republic of Macedonia',
'Macedonia, The former Yugoslav Republic of',
],
'continent' => 'Europe',
'isoAlpha3' => 'MKD',
'longDistancePrefix' => 389,
Expand Down Expand Up @@ -2915,22 +2921,21 @@ private function findCountryByCode(string $property, $value): ?Country
: null;
}

private function findCountryByName(string $name): ?Country
private function findCountryByName(string $value): ?Country
{
$name = mb_strtolower($name);
$value = mb_strtolower($value);

foreach (self::COUNTRIES as $code => $countryData) {
if ($name === mb_strtolower($countryData['officialName'])) {
return $this->findByIsoAlpha2($code);
}
if ($name === mb_strtolower(iconv('utf8', 'ASCII//TRANSLIT', $countryData['officialName']))) {
return $this->findByIsoAlpha2($code);
}
if ($name === mb_strtolower($countryData['commonName'])) {
return $this->findByIsoAlpha2($code);
$names = [$countryData['officialName'], $countryData['commonName']];

if (isset($countryData['knownNames'])) {
$names = array_unique(array_merge($names, $countryData['knownNames']));
}
if ($name === mb_strtolower(iconv('utf8', 'ASCII//TRANSLIT', $countryData['commonName']))) {
return $this->findByIsoAlpha2($code);

foreach ($names as $name) {
if ($value === mb_strtolower($name) || $value === mb_strtolower(iconv('utf8', 'ASCII//TRANSLIT', $name))) {
return $this->findByIsoAlpha2($code);
}
}
}

Expand Down
37 changes: 37 additions & 0 deletions tests/CountryRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public function findByIsoAlpha2WithInvalidIsoAlpha2ThrowsException(): void
$this->getCountryRepository()->findByIsoAlpha2('XY');
}

/**
* @test
*/
public function hasWithIsoAlpha2(): void
{
self::assertTrue($this->getCountryRepository()->hasWithIsoAlpha2('US'));
self::assertFalse($this->getCountryRepository()->hasWithIsoAlpha2('XY'));
}

/**
* @test
*/
Expand Down Expand Up @@ -64,6 +73,25 @@ public function findByNameIgnoresAccentsAndCases(): void
self::assertSame('ax', $country->getTopLevelDomain());
}

/**
* @test
*/
public function findByAliases(): void
{
$country = $this->getCountryRepository()->findByName('North Macedonia');
self::assertSame('North Macedonia', $country->getCommonName());

$aliases = [
'Macedonia',
'Republic of Macedonia',
'The Former Yugoslav Republic of Macedonia',
'Macedonia, The former Yugoslav Republic of',
];
foreach ($aliases as $alias) {
$this->getCountryRepository()->findByName($alias)->equals($country);
}
}

/**
* @test
*/
Expand Down Expand Up @@ -145,6 +173,15 @@ public function findByIsoNumericReturnsCorrectCountry(): void
self::assertSame('us', $country->getTopLevelDomain());
}

/**
* @test
*/
public function hasWithIsoNumeric(): void
{
self::assertTrue($this->getCountryRepository()->hasWithIsoNumeric(840));
self::assertFalse($this->getCountryRepository()->hasWithIsoNumeric(0));
}

/**
* @test
*/
Expand Down

0 comments on commit 612795d

Please sign in to comment.