-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
49 lines (37 loc) · 1.49 KB
/
index.php
File metadata and controls
49 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace App;
use App\Api\RestCountriesApi;
use App\Client\GuzzleClient;
use App\Factory\CountryFactory;
use App\Validator\ArrayPropertiesValidator;
use GuzzleHttp\Client;
require __DIR__ . '/vendor/autoload.php';
$client = new GuzzleClient(new Client());
$countryFactory = new CountryFactory(new ArrayPropertiesValidator());
$restCountriesApi = new RestCountriesApi($client, $countryFactory );
if ($argc > 2) {
$countryA = $restCountriesApi->getCountryByName($argv[1]);
$countriesA = $restCountriesApi->getCountriesByIsoCode($countryA->getCountryIso639());
$countryB = $restCountriesApi->getCountryByName($argv[2]);
$matches = 0;
foreach ($countriesA as $country) {
if ($countryB->getName() == $country->getName()) {
$matches ++;
}
}
if ($matches >= 1) {
echo $countryA->getName() . " and " . $countryB->getName() . " speaks the same language";
} else {
echo $countryA->getName() . " and " . $countryB->getName() . " do not speak the same language";
}
} else {
$countryObj = $restCountriesApi->getCountryByName($argv[1]);
$countries = $restCountriesApi->getCountriesByIsoCode($countryObj->getCountryIso639());
echo "Country language code: " . $countryObj->getCountryIso() . "
" . $countryObj->getName() . " speaks same language with these countries: ";
foreach ($countries as $country) {
if ($countryObj->getName() != $country->getName()) {
echo $country->getName() . ', ';
}
}
}