These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace PeterColes\Countries; |
||
4 | |||
5 | class Maker |
||
6 | { |
||
7 | 3 | public function lookup($locale = 'en', $flip = false) |
|
8 | { |
||
9 | 3 | $this->prep($locale); |
|
10 | |||
11 | 3 | if ($flip) { |
|
12 | 1 | return $this->countries->flip(); |
|
0 ignored issues
–
show
|
|||
13 | } |
||
14 | |||
15 | 2 | return $this->countries; |
|
16 | } |
||
17 | |||
18 | 3 | public function keyValue($locale = 'en', $key = 'key', $value = 'value') |
|
19 | { |
||
20 | 3 | $this->prep($locale); |
|
21 | |||
22 | 3 | $key = $key ?: 'key'; |
|
23 | 3 | $value = $value ?: 'value'; |
|
24 | |||
25 | 3 | return $this->countries->transform(function($item, $index) use ($key, $value) { |
|
26 | 3 | return (object) [ $key => $index, $value =>$item ]; |
|
27 | 3 | })->values(); |
|
28 | } |
||
29 | |||
30 | 6 | protected function prep($locale) |
|
31 | { |
||
32 | 6 | $locale = $locale ?: 'en'; |
|
33 | 6 | $this->countries = collect(require realpath(__DIR__."/../data/$locale.php")); |
|
34 | 6 | } |
|
35 | } |
||
36 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: