Skip to content

Commit 000d7aa

Browse files
committed
spring cleaning
1 parent 032562f commit 000d7aa

File tree

1 file changed

+78
-79
lines changed

1 file changed

+78
-79
lines changed

src/Webpatser/Countries/Countries.php

Lines changed: 78 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,28 @@
99
*
1010
*/
1111
class Countries extends Model {
12-
13-
/**
14-
* @var string
15-
* Path to the directory containing countries data.
16-
*/
17-
protected $countries;
18-
19-
/**
20-
* @var string
21-
* The table for the countries in the database, is "countries" by default.
22-
*/
23-
protected $table;
24-
12+
13+
/**
14+
* @var array
15+
*/
16+
protected $countries = [];
17+
18+
/**
19+
* @var string
20+
* The table for the countries in the database, is "countries" by default.
21+
*/
22+
protected $table;
23+
2524
/**
2625
* Constructor.
2726
*
2827
* @return void
2928
*/
3029
public function __construct()
3130
{
32-
$this->table = \Config::get('countries.table_name');
31+
$this->table = \Config::get('countries.table_name');
3332
}
34-
33+
3534
/**
3635
* Get the countries from the JSON file, if it hasn't already been loaded.
3736
*
@@ -40,77 +39,77 @@ public function __construct()
4039
protected function getCountries()
4140
{
4241
//Get the countries from the JSON file
43-
if (!$this->countries || sizeof($this->countries) == 0){
42+
if (sizeof($this->countries) == 0) {
4443
$this->countries = json_decode(file_get_contents(__DIR__ . '/Models/countries.json'), true);
4544
}
46-
45+
4746
//Return the countries
4847
return $this->countries;
4948
}
50-
51-
/**
52-
* Returns one country
53-
*
54-
* @param string $id The country id
49+
50+
/**
51+
* Returns one country
5552
*
56-
* @return array
57-
*/
58-
public function getOne($id)
59-
{
53+
* @param string $id The country id
54+
*
55+
* @return array
56+
*/
57+
public function getOne($id)
58+
{
6059
$countries = $this->getCountries();
61-
return $countries[$id];
62-
}
63-
64-
/**
65-
* Returns a list of countries
66-
*
67-
* @param string sort
68-
*
69-
* @return array
70-
*/
71-
public function getList($sort = null)
72-
{
73-
//Get the countries list
74-
$countries = $this->getCountries();
75-
76-
//Sorting
77-
$validSorts = [
78-
'capital',
79-
'citizenship',
80-
'country-code',
81-
'currency',
82-
'currency_code',
83-
'currency_sub_unit',
84-
'full_name',
85-
'iso_3166_2',
86-
'iso_3166_3',
87-
'name',
88-
'region-code',
89-
'sub-region-code',
90-
'eea',
91-
'calling_code',
92-
'currency_symbol',
93-
'flag',
60+
return $countries[$id];
61+
}
62+
63+
/**
64+
* Returns a list of countries
65+
*
66+
* @param string sort
67+
*
68+
* @return array
69+
*/
70+
public function getList($sort = null)
71+
{
72+
//Get the countries list
73+
$countries = $this->getCountries();
74+
75+
//Sorting
76+
$validSorts = [
77+
'capital',
78+
'citizenship',
79+
'country-code',
80+
'currency',
81+
'currency_code',
82+
'currency_sub_unit',
83+
'full_name',
84+
'iso_3166_2',
85+
'iso_3166_3',
86+
'name',
87+
'region-code',
88+
'sub-region-code',
89+
'eea',
90+
'calling_code',
91+
'currency_symbol',
92+
'flag',
9493
];
95-
96-
if (!is_null($sort) && in_array($sort, $validSorts)){
97-
uasort($countries, function($a, $b) use ($sort) {
98-
if (!isset($a[$sort]) && !isset($b[$sort])){
99-
return 0;
100-
} elseif (!isset($a[$sort])){
101-
return -1;
102-
} elseif (!isset($b[$sort])){
103-
return 1;
104-
} else {
105-
return strcasecmp($a[$sort], $b[$sort]);
106-
}
107-
});
108-
}
109-
110-
//Return the countries
111-
return $countries;
112-
}
113-
94+
95+
if (!is_null($sort) && in_array($sort, $validSorts)){
96+
uasort($countries, function($a, $b) use ($sort) {
97+
if (!isset($a[$sort]) && !isset($b[$sort])){
98+
return 0;
99+
} elseif (!isset($a[$sort])){
100+
return -1;
101+
} elseif (!isset($b[$sort])){
102+
return 1;
103+
} else {
104+
return strcasecmp($a[$sort], $b[$sort]);
105+
}
106+
});
107+
}
108+
109+
//Return the countries
110+
return $countries;
111+
}
112+
114113
/**
115114
* Returns a list of countries suitable to use with a select element in Laravelcollective\html
116115
* Will show the value and sort by the column specified in the display attribute
@@ -124,7 +123,7 @@ public function getListForSelect($display = 'name')
124123
foreach ($this->getList($display) as $key => $value) {
125124
$countries[$key] = $value[$display];
126125
}
127-
126+
128127
//return the array
129128
return $countries;
130129
}

0 commit comments

Comments
 (0)