1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Someshwer\WorldCountries\Lib; |
4
|
|
|
|
5
|
|
|
use Illuminate\Encryption\Encrypter; |
|
|
|
|
6
|
|
|
use Someshwer\WorldCountries\Data\DataRepository; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Author: Someshwer Bandapally |
10
|
|
|
* Date: 18-07-2018. |
11
|
|
|
* |
12
|
|
|
* This class provides STD codes data |
13
|
|
|
* |
14
|
|
|
* Class StdCodes |
15
|
|
|
*/ |
16
|
|
|
class StdCodes extends States |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var DataRepository |
20
|
|
|
*/ |
21
|
|
|
private $data; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $en_key = 'Someshwer1@2#BandapallySomeshwer'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private $cipher = 'AES-256-CBC'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* StdCodes constructor. |
35
|
|
|
* |
36
|
|
|
* @param DataRepository $dataRepository |
37
|
|
|
*/ |
38
|
|
|
public function __construct(DataRepository $dataRepository) |
39
|
|
|
{ |
40
|
|
|
parent::__construct($dataRepository); |
41
|
|
|
$this->data = $dataRepository; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Optimize STD codes data. |
46
|
|
|
* |
47
|
|
|
* @param $all_std_codes_data |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
private function optimizeStdCodesData($all_std_codes_data) |
52
|
|
|
{ |
53
|
|
|
$str_length = strlen($all_std_codes_data) - 4; |
54
|
|
|
$all_std_codes_trimmed_data = substr($all_std_codes_data, 0, 2).substr($all_std_codes_data, 3, $str_length); |
55
|
|
|
$hash = new Encrypter($this->en_key, $this->cipher); |
56
|
|
|
|
57
|
|
|
return $hash->decrypt($all_std_codes_trimmed_data); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Fetch optimized std codes data. |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
private function getOptimizedStdCodesData() |
66
|
|
|
{ |
67
|
|
|
$all_std_codes__data = $this->data->stdCodes(); |
68
|
|
|
$std_codes_data = $this->optimizeStdCodesData($all_std_codes__data); |
69
|
|
|
// $std_codes_data = json_decode($std_codes_data, true); |
70
|
|
|
return $std_codes_data; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns all std codes. |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function stdCodes() |
79
|
|
|
{ |
80
|
|
|
return $this->getOptimizedStdCodesData(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Search STD codes. |
85
|
|
|
* |
86
|
|
|
* @param null $search_string |
|
|
|
|
87
|
|
|
* |
88
|
|
|
* @return array|static |
89
|
|
|
*/ |
90
|
|
|
public function searchStdCodes($search_string = null) |
91
|
|
|
{ |
92
|
|
|
if (is_null($search_string)) { |
|
|
|
|
93
|
|
|
return []; |
94
|
|
|
} |
95
|
|
|
$std_codes = $this->getOptimizedStdCodesData(); |
96
|
|
|
|
97
|
|
|
return collect($std_codes)->filter(function ($item) use ($search_string) { |
|
|
|
|
98
|
|
|
return (substr(strtolower($item['country_name']), 0, strlen($search_string)) == strtolower($search_string)) || |
99
|
|
|
(strtolower($item['country_code']) == strtolower($search_string)) || |
100
|
|
|
(strpos(strtolower($item['std_code']), strtolower($search_string)) !== false); |
101
|
|
|
})->transform(function ($value) { |
102
|
|
|
return array_except($value, 'id'); |
|
|
|
|
103
|
|
|
})->values(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Search STD code by country name. |
108
|
|
|
* |
109
|
|
|
* @param null $country_name |
|
|
|
|
110
|
|
|
* |
111
|
|
|
* @return array|static |
112
|
|
|
*/ |
113
|
|
|
public function stdCodeByCountryName($country_name = null) |
114
|
|
|
{ |
115
|
|
|
if (is_null($country_name)) { |
|
|
|
|
116
|
|
|
return []; |
117
|
|
|
} |
118
|
|
|
$std_codes = $this->getOptimizedStdCodesData(); |
119
|
|
|
|
120
|
|
|
return collect($std_codes)->filter(function ($item) use ($country_name) { |
|
|
|
|
121
|
|
|
return substr(strtolower($item['country_name']), 0, strlen($country_name)) == strtolower($country_name); |
122
|
|
|
})->transform(function ($value) { |
123
|
|
|
return array_except($value, 'id'); |
|
|
|
|
124
|
|
|
})->values(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Search STD code by country code. |
129
|
|
|
* |
130
|
|
|
* @param null $country_code |
|
|
|
|
131
|
|
|
* |
132
|
|
|
* @return array|static |
133
|
|
|
*/ |
134
|
|
|
public function stdCodeByCountryCode($country_code = null) |
135
|
|
|
{ |
136
|
|
|
if (is_null($country_code)) { |
|
|
|
|
137
|
|
|
return []; |
138
|
|
|
} |
139
|
|
|
$std_codes = $this->getOptimizedStdCodesData(); |
140
|
|
|
|
141
|
|
|
return collect($std_codes)->filter(function ($item) use ($country_code) { |
|
|
|
|
142
|
|
|
return strtolower($item['country_code']) == strtolower($country_code); |
143
|
|
|
})->transform(function ($value) { |
144
|
|
|
return array_except($value, 'id'); |
|
|
|
|
145
|
|
|
})->values(); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths