bsomeshwer /
world-countries
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Someshwer\WorldCountries\Lib; |
||||
| 4 | |||||
| 5 | use Illuminate\Encryption\Encrypter; |
||||
|
0 ignored issues
–
show
|
|||||
| 6 | use Someshwer\WorldCountries\Data\DataRepository; |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | * Author: Someshwer Bandapally |
||||
| 10 | * Date: 25-05-2018. |
||||
| 11 | * |
||||
| 12 | * This class gives all currency names |
||||
| 13 | * |
||||
| 14 | * Class Currencies |
||||
| 15 | */ |
||||
| 16 | class Currencies extends StdCodes |
||||
| 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 | public function __construct(DataRepository $dataRepository) |
||||
| 34 | { |
||||
| 35 | parent::__construct($dataRepository); |
||||
| 36 | $this->data = $dataRepository; |
||||
| 37 | } |
||||
| 38 | |||||
| 39 | /** |
||||
| 40 | * Optimizes currency data. |
||||
| 41 | * |
||||
| 42 | * @param $all_currencies_data |
||||
| 43 | * |
||||
| 44 | * @return string |
||||
| 45 | */ |
||||
| 46 | private function optimizeCurrenciesData($all_currencies_data) |
||||
| 47 | { |
||||
| 48 | $str_length = strlen($all_currencies_data) - 4; |
||||
| 49 | $all_currencies_trimmed_data = substr($all_currencies_data, 0, 2).substr($all_currencies_data, 3, $str_length); |
||||
| 50 | $hash = new Encrypter($this->en_key, $this->cipher); |
||||
| 51 | |||||
| 52 | return $hash->decrypt($all_currencies_trimmed_data); |
||||
| 53 | } |
||||
| 54 | |||||
| 55 | /** |
||||
| 56 | * Getting optimized currency data. |
||||
| 57 | * |
||||
| 58 | * @return mixed|string |
||||
| 59 | */ |
||||
| 60 | private function getOptimizedCurrenciesData() |
||||
| 61 | { |
||||
| 62 | $all_currencies_data = $this->data->currencies(); |
||||
| 63 | $currencies_data = $this->optimizeCurrenciesData($all_currencies_data); |
||||
| 64 | $currencies_data = json_decode($currencies_data, true); |
||||
| 65 | |||||
| 66 | return $currencies_data; |
||||
| 67 | } |
||||
| 68 | |||||
| 69 | /** |
||||
| 70 | * All currencies data. |
||||
| 71 | * |
||||
| 72 | * @return mixed|string |
||||
| 73 | */ |
||||
| 74 | public function currencies() |
||||
| 75 | { |
||||
| 76 | return $this->getOptimizedCurrenciesData(); |
||||
| 77 | } |
||||
| 78 | |||||
| 79 | /** |
||||
| 80 | * Search currency by either currency name or country name. |
||||
| 81 | * |
||||
| 82 | * @param $search_key |
||||
| 83 | * |
||||
| 84 | * @return static |
||||
| 85 | */ |
||||
| 86 | public function searchCurrency($search_key = null) |
||||
| 87 | { |
||||
| 88 | if (!$search_key) { |
||||
| 89 | return []; |
||||
|
0 ignored issues
–
show
|
|||||
| 90 | } |
||||
| 91 | |||||
| 92 | return collect($this->getOptimizedCurrenciesData())->filter(function ($item) use ($search_key) { |
||||
|
0 ignored issues
–
show
The function
collect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 93 | return (strpos(strtolower($item['currency_name']), strtolower($search_key)) !== false) || |
||||
| 94 | (strpos(strtolower($item['country_name']), strtolower($search_key)) !== false); |
||||
| 95 | })->values(); |
||||
| 96 | } |
||||
| 97 | |||||
| 98 | /** |
||||
| 99 | * Get currency by country name. |
||||
| 100 | * |
||||
| 101 | * @param $country_name |
||||
| 102 | * |
||||
| 103 | * @return static |
||||
| 104 | */ |
||||
| 105 | public function currencyByCountryName($country_name = null) |
||||
| 106 | { |
||||
| 107 | if (!$country_name) { |
||||
| 108 | return []; |
||||
|
0 ignored issues
–
show
|
|||||
| 109 | } |
||||
| 110 | |||||
| 111 | return collect($this->getOptimizedCurrenciesData())->filter(function ($item) use ($country_name) { |
||||
|
0 ignored issues
–
show
The function
collect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 112 | return strtolower($item['country_name']) == strtolower($country_name); |
||||
| 113 | })->values(); |
||||
| 114 | } |
||||
| 115 | |||||
| 116 | /** |
||||
| 117 | * Get currency b y country code. |
||||
| 118 | * |
||||
| 119 | * @param $country_code |
||||
| 120 | * |
||||
| 121 | * @return static |
||||
| 122 | */ |
||||
| 123 | public function currencyByCountryCode($country_code = null) |
||||
| 124 | { |
||||
| 125 | if (!$country_code) { |
||||
| 126 | return []; |
||||
|
0 ignored issues
–
show
|
|||||
| 127 | } |
||||
| 128 | |||||
| 129 | return collect($this->getOptimizedCurrenciesData())->filter(function ($item) use ($country_code) { |
||||
|
0 ignored issues
–
show
The function
collect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 130 | return strtolower($item['country_code']) == strtolower($country_code); |
||||
| 131 | })->values(); |
||||
| 132 | } |
||||
| 133 | |||||
| 134 | /** |
||||
| 135 | * Get currency by currency name. |
||||
| 136 | * |
||||
| 137 | * @param $currency_name |
||||
| 138 | * |
||||
| 139 | * @return static |
||||
| 140 | */ |
||||
| 141 | public function currencyByCurrencyName($currency_name = null) |
||||
| 142 | { |
||||
| 143 | if (!$currency_name) { |
||||
| 144 | return []; |
||||
|
0 ignored issues
–
show
|
|||||
| 145 | } |
||||
| 146 | |||||
| 147 | return collect($this->getOptimizedCurrenciesData())->filter(function ($item) use ($currency_name) { |
||||
|
0 ignored issues
–
show
The function
collect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 148 | return strpos(strtolower($item['currency_name']), strtolower($currency_name)) !== false; |
||||
| 149 | })->values(); |
||||
| 150 | } |
||||
| 151 | |||||
| 152 | /** |
||||
| 153 | * Get currency by currency code. |
||||
| 154 | * |
||||
| 155 | * @param $currency_code |
||||
| 156 | * |
||||
| 157 | * @return static |
||||
| 158 | */ |
||||
| 159 | public function currencyByCurrencyCode($currency_code = null) |
||||
| 160 | { |
||||
| 161 | if (!$currency_code) { |
||||
| 162 | return []; |
||||
|
0 ignored issues
–
show
|
|||||
| 163 | } |
||||
| 164 | |||||
| 165 | return collect($this->getOptimizedCurrenciesData())->filter(function ($item) use ($currency_code) { |
||||
|
0 ignored issues
–
show
The function
collect was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 166 | return strtolower($item['currency_code']) == strtolower($currency_code); |
||||
| 167 | })->values(); |
||||
| 168 | } |
||||
| 169 | } |
||||
| 170 |
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