Skip to content

Commit 1331328

Browse files
authored
Add relation between countries and languages (#103)
1 parent dc93080 commit 1331328

File tree

9 files changed

+362
-28
lines changed

9 files changed

+362
-28
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ In the Country, Currency and language specifications, there is also a relation b
3636

3737
All specifications in this package are closely related, except for the Http status code and methods. Not all relations are bidirectional though. For example, a language tag is build up of a language and optionally a country, but only a country cannot be converted to a language tag.
3838

39-
Below you can find an overview of all the relationships between specifications. As not all relationships are implemented yet, a dotted line indicates when there is a relationship, but that has not yet been implemented in this package.
39+
Below you can find an overview of all the relationships between specifications.
4040

4141
```mermaid
4242
erDiagram
@@ -100,8 +100,7 @@ erDiagram
100100
101101
GeographicRegion }|--o{ Country: ""
102102
GeographicRegion ||--o{ GeographicRegion: ""
103-
Language }o..o{ Country: ""
104-
Language }o..|{ Script: ""
103+
Language }o--o{ Country: ""
105104
Country }|--o{ CountryGroup: ""
106105
Country }|--o{ CountryCallingCode: ""
107106
Country }o--o{ Currency: ""
@@ -152,8 +151,9 @@ CountryAlpha3::from('NLD')->getInternationalCallPrefix()->value; // '00'
152151

153152
CountryAlpha3::from('NLD')->getFlagEmoji(); // '🇳🇱' (This might not be displayed correctly in this readme if you're on windows, see 'https://prinsfrank.nl/2021/01/25/Non-existing-flag-emojis-on-windows to make these flag emojis visible for Windows users.')
154153
CountryAlpha3::from('NLD')->getCurrenciesAlpha3(); // [CurrencyAlpha3::Euro]
154+
CountryAlpha3::from('NLD')->getOfficialAndDeFactoLanguages(); // [LanguageAlpha2::Dutch_Flemish]
155155

156-
public function foo(CountryAlpha2 $countryAlpha2) {} // Use spec as typehint to enforce valid value
156+
public function foo(CountryAlpha2 $countryAlpha2) {} // Use spec as typehint to enforce valid value
157157

158158
```
159159

@@ -219,6 +219,8 @@ $valueAlpha2->getInternationalCallPrefix()->value; // '00'
219219
$valueAlpha2::from('NLD')->getFlagEmoji(); // '🇳🇱' (This might not be displayed correctly in this readme if you're on windows, see 'https://prinsfrank.nl/2021/01/25/Non-existing-flag-emojis-on-windows to make these flag emojis visible for Windows users.')
220220

221221
$valueAlpha2->getCurrenciesAlpha3(); // [CurrencyAlpha3::Euro]
222+
223+
$valueAlpha2->getOfficialAndDeFactoLanguages(); // [LanguageAlpha2::Dutch_Flemish]
222224
```
223225

224226
### CountryAlpha3
@@ -245,6 +247,8 @@ $valueAlpha3->getInternationalCallPrefix()->value; // '00'
245247
$valueAlpha3->getFlagEmoji(); // '🇳🇱' (This might not be displayed correctly in this readme if you're on windows, see 'https://prinsfrank.nl/2021/01/25/Non-existing-flag-emojis-on-windows to make these flag emojis visible for Windows users.')
246248

247249
$valueAlpha3->getCurrenciesAlpha3(); // [CurrencyAlpha3::Euro]
250+
251+
$valueAlpha3->getOfficialAndDeFactoLanguages(); // [LanguageAlpha2::Dutch_Flemish]
248252
```
249253

250254
### CountryNumeric
@@ -272,6 +276,8 @@ $valueNumeric->getInternationalCallPrefix()->value; // '00'
272276
$valueNumeric->getFlagEmoji(); // '🇳🇱' (This might not be displayed correctly in this readme if you're on windows, see 'https://prinsfrank.nl/2021/01/25/Non-existing-flag-emojis-on-windows to make these flag emojis visible for Windows users.')
273277

274278
$valueNumeric->getCurrenciesAlpha3(); // [CurrencyAlpha3::Euro]
279+
280+
$valueNumeric->getOfficialAndDeFactoLanguages(); // [LanguageAlpha2::Dutch_Flemish]
275281
```
276282

277283
### CountryName
@@ -296,6 +302,8 @@ $valueName->getInternationalCallPrefix()->value; // '00'
296302
$valueName->getFlagEmoji(); // '🇳🇱' (This might not be displayed correctly in this readme if you're on windows, see 'https://prinsfrank.nl/2021/01/25/Non-existing-flag-emojis-on-windows to make these flag emojis visible for Windows users.')
297303

298304
$valueName->getCurrenciesAlpha3(); // [CurrencyAlpha3::Euro]
305+
306+
$valueName->getOfficialAndDeFactoLanguages(); // [LanguageAlpha2::Dutch_Flemish]
299307
```
300308

301309
</details>

src/Country/CountryAlpha2.php

Lines changed: 259 additions & 0 deletions
Large diffs are not rendered by default.

src/Country/CountryAlpha3.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use PrinsFrank\Standards\Currency\CurrencyAlpha3;
1010
use PrinsFrank\Standards\InternationalCallPrefix\InternationalCallPrefix;
1111
use PrinsFrank\Standards\InvalidArgumentException;
12+
use PrinsFrank\Standards\Language\LanguageAlpha2;
13+
use PrinsFrank\Standards\Language\LanguageAlpha3Extensive;
14+
use PrinsFrank\Standards\Language\LanguageAlpha3Terminology;
1215

1316
/**
1417
* @source https://www.iso.org/obp/ui/#search/code/
@@ -321,4 +324,10 @@ public function getCurrenciesAlpha3(): array
321324
{
322325
return $this->toCountryAlpha2()->getCurrenciesAlpha3();
323326
}
327+
328+
/** @return list<LanguageAlpha2|LanguageAlpha3Terminology|LanguageAlpha3Extensive> */
329+
public function getOfficialAndDeFactoLanguages(): array
330+
{
331+
return $this->toCountryAlpha2()->getOfficialAndDeFactoLanguages();
332+
}
324333
}

src/Country/CountryName.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use PrinsFrank\Standards\Currency\CurrencyAlpha3;
1010
use PrinsFrank\Standards\InternationalCallPrefix\InternationalCallPrefix;
1111
use PrinsFrank\Standards\InvalidArgumentException;
12+
use PrinsFrank\Standards\Language\LanguageAlpha2;
13+
use PrinsFrank\Standards\Language\LanguageAlpha3Extensive;
14+
use PrinsFrank\Standards\Language\LanguageAlpha3Terminology;
1215

1316
/**
1417
* @source https://www.iso.org/obp/ui/#search/code/
@@ -316,4 +319,10 @@ public function getCurrenciesAlpha3(): array
316319
{
317320
return $this->toCountryAlpha2()->getCurrenciesAlpha3();
318321
}
322+
323+
/** @return list<LanguageAlpha2|LanguageAlpha3Terminology|LanguageAlpha3Extensive> */
324+
public function getOfficialAndDeFactoLanguages(): array
325+
{
326+
return $this->toCountryAlpha2()->getOfficialAndDeFactoLanguages();
327+
}
319328
}

src/Country/CountryNumeric.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use PrinsFrank\Standards\Currency\CurrencyAlpha3;
1010
use PrinsFrank\Standards\InternationalCallPrefix\InternationalCallPrefix;
1111
use PrinsFrank\Standards\InvalidArgumentException;
12+
use PrinsFrank\Standards\Language\LanguageAlpha2;
13+
use PrinsFrank\Standards\Language\LanguageAlpha3Extensive;
14+
use PrinsFrank\Standards\Language\LanguageAlpha3Terminology;
1215

1316
/**
1417
* @source https://www.iso.org/obp/ui/#search/code/
@@ -331,4 +334,10 @@ public function getCurrenciesAlpha3(): array
331334
{
332335
return $this->toCountryAlpha2()->getCurrenciesAlpha3();
333336
}
337+
338+
/** @return list<LanguageAlpha2|LanguageAlpha3Terminology|LanguageAlpha3Extensive> */
339+
public function getOfficialAndDeFactoLanguages(): array
340+
{
341+
return $this->toCountryAlpha2()->getOfficialAndDeFactoLanguages();
342+
}
334343
}

tests/Unit/Country/CountryAlpha2Test.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,14 @@ public function testGetCurrenciesAlpha3(): void
133133
static::assertNotEmpty($currencies, 'No currencies for "' . $countryAlpha2->name . '"');
134134
}
135135
}
136+
137+
/** @covers ::getOfficialAndDeFactoLanguages */
138+
public function testGetOfficialAndDeFactoLanguages(): void
139+
{
140+
foreach (CountryAlpha2::cases() as $countryAlpha2) {
141+
$countryAlpha2->getOfficialAndDeFactoLanguages();
142+
143+
$this->addToAssertionCount(1);
144+
}
145+
}
136146
}

tests/Unit/Country/CountryAlpha3Test.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public function testIsMemberOf(): void
9696
*/
9797
public function testGetCountryCallingCodes(): void
9898
{
99-
foreach (CountryAlpha3::cases() as $countryAlpha2) {
100-
static::assertNotEmpty($countryAlpha2->getCountryCallingCodes());
99+
foreach (CountryAlpha3::cases() as $countryAlpha3) {
100+
static::assertNotEmpty($countryAlpha3->getCountryCallingCodes());
101101
}
102102
}
103103

@@ -106,8 +106,8 @@ public function testGetCountryCallingCodes(): void
106106
*/
107107
public function testGetInternationalCallPrefix(): void
108108
{
109-
foreach (CountryAlpha3::cases() as $countryAlpha2) {
110-
$countryAlpha2->getInternationalCallPrefix();
109+
foreach (CountryAlpha3::cases() as $countryAlpha3) {
110+
$countryAlpha3->getInternationalCallPrefix();
111111

112112
$this->addToAssertionCount(1);
113113
}
@@ -122,15 +122,25 @@ public function testGetFlagEmoji(): void
122122
/** @covers ::getCurrenciesAlpha3 */
123123
public function testGetCurrenciesAlpha3(): void
124124
{
125-
foreach (CountryAlpha3::cases() as $countryAlpha2) {
126-
$currencies = $countryAlpha2->getCurrenciesAlpha3();
127-
if (in_array($countryAlpha2, [CountryAlpha3::Antarctica, CountryAlpha3::Palestine, CountryAlpha3::South_Georgia_South_Sandwich_Islands], true)) {
125+
foreach (CountryAlpha3::cases() as $countryAlpha3) {
126+
$currencies = $countryAlpha3->getCurrenciesAlpha3();
127+
if (in_array($countryAlpha3, [CountryAlpha3::Antarctica, CountryAlpha3::Palestine, CountryAlpha3::South_Georgia_South_Sandwich_Islands], true)) {
128128
$this->addToAssertionCount(1);
129129

130130
continue;
131131
}
132132

133-
static::assertNotEmpty($currencies, 'No currencies for "' . $countryAlpha2->name . '"');
133+
static::assertNotEmpty($currencies, 'No currencies for "' . $countryAlpha3->name . '"');
134+
}
135+
}
136+
137+
/** @covers ::getOfficialAndDeFactoLanguages */
138+
public function testGetOfficialAndDeFactoLanguages(): void
139+
{
140+
foreach (CountryAlpha3::cases() as $countryAlpha2) {
141+
$countryAlpha2->getOfficialAndDeFactoLanguages();
142+
143+
$this->addToAssertionCount(1);
134144
}
135145
}
136146
}

tests/Unit/Country/CountryNameTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public function testIsMemberOf(): void
8888
*/
8989
public function testGetCountryCallingCodes(): void
9090
{
91-
foreach (CountryName::cases() as $countryAlpha2) {
92-
static::assertNotEmpty($countryAlpha2->getCountryCallingCodes());
91+
foreach (CountryName::cases() as $countryName) {
92+
static::assertNotEmpty($countryName->getCountryCallingCodes());
9393
}
9494
}
9595

@@ -98,8 +98,8 @@ public function testGetCountryCallingCodes(): void
9898
*/
9999
public function testGetInternationalCallPrefix(): void
100100
{
101-
foreach (CountryName::cases() as $countryAlpha2) {
102-
$countryAlpha2->getInternationalCallPrefix();
101+
foreach (CountryName::cases() as $countryName) {
102+
$countryName->getInternationalCallPrefix();
103103

104104
$this->addToAssertionCount(1);
105105
}
@@ -114,15 +114,25 @@ public function testGetFlagEmoji(): void
114114
/** @covers ::getCurrenciesAlpha3 */
115115
public function testGetCurrenciesAlpha3(): void
116116
{
117-
foreach (CountryName::cases() as $countryAlpha2) {
118-
$currencies = $countryAlpha2->getCurrenciesAlpha3();
119-
if (in_array($countryAlpha2, [CountryName::Antarctica, CountryName::Palestine, CountryName::South_Georgia_South_Sandwich_Islands], true)) {
117+
foreach (CountryName::cases() as $countryName) {
118+
$currencies = $countryName->getCurrenciesAlpha3();
119+
if (in_array($countryName, [CountryName::Antarctica, CountryName::Palestine, CountryName::South_Georgia_South_Sandwich_Islands], true)) {
120120
$this->addToAssertionCount(1);
121121

122122
continue;
123123
}
124124

125-
static::assertNotEmpty($currencies, 'No currencies for "' . $countryAlpha2->name . '"');
125+
static::assertNotEmpty($currencies, 'No currencies for "' . $countryName->name . '"');
126+
}
127+
}
128+
129+
/** @covers ::getOfficialAndDeFactoLanguages */
130+
public function testGetOfficialAndDeFactoLanguages(): void
131+
{
132+
foreach (CountryName::cases() as $countryName) {
133+
$countryName->getOfficialAndDeFactoLanguages();
134+
135+
$this->addToAssertionCount(1);
126136
}
127137
}
128138
}

tests/Unit/Country/CountryNumericTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ public function testIsMemberOf(): void
123123
*/
124124
public function testGetCountryCallingCodes(): void
125125
{
126-
foreach (CountryNumeric::cases() as $countryAlpha2) {
127-
static::assertNotEmpty($countryAlpha2->getCountryCallingCodes());
126+
foreach (CountryNumeric::cases() as $countryNumeric) {
127+
static::assertNotEmpty($countryNumeric->getCountryCallingCodes());
128128
}
129129
}
130130

@@ -133,8 +133,8 @@ public function testGetCountryCallingCodes(): void
133133
*/
134134
public function testGetInternationalCallPrefix(): void
135135
{
136-
foreach (CountryNumeric::cases() as $countryAlpha2) {
137-
$countryAlpha2->getInternationalCallPrefix();
136+
foreach (CountryNumeric::cases() as $countryNumeric) {
137+
$countryNumeric->getInternationalCallPrefix();
138138

139139
$this->addToAssertionCount(1);
140140
}
@@ -149,15 +149,25 @@ public function testGetFlagEmoji(): void
149149
/** @covers ::getCurrenciesAlpha3 */
150150
public function testGetCurrenciesAlpha3(): void
151151
{
152-
foreach (CountryNumeric::cases() as $countryAlpha2) {
153-
$currencies = $countryAlpha2->getCurrenciesAlpha3();
154-
if (in_array($countryAlpha2, [CountryNumeric::Antarctica, CountryNumeric::Palestine, CountryNumeric::South_Georgia_South_Sandwich_Islands], true)) {
152+
foreach (CountryNumeric::cases() as $countryNumeric) {
153+
$currencies = $countryNumeric->getCurrenciesAlpha3();
154+
if (in_array($countryNumeric, [CountryNumeric::Antarctica, CountryNumeric::Palestine, CountryNumeric::South_Georgia_South_Sandwich_Islands], true)) {
155155
$this->addToAssertionCount(1);
156156

157157
continue;
158158
}
159159

160-
static::assertNotEmpty($currencies, 'No currencies for "' . $countryAlpha2->name . '"');
160+
static::assertNotEmpty($currencies, 'No currencies for "' . $countryNumeric->name . '"');
161+
}
162+
}
163+
164+
/** @covers ::getOfficialAndDeFactoLanguages */
165+
public function testGetOfficialAndDeFactoLanguages(): void
166+
{
167+
foreach (CountryNumeric::cases() as $countryNumeric) {
168+
$countryNumeric->getOfficialAndDeFactoLanguages();
169+
170+
$this->addToAssertionCount(1);
161171
}
162172
}
163173
}

0 commit comments

Comments
 (0)