1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Someshwer\WorldCountries\Utils; |
4
|
|
|
|
5
|
|
|
use Illuminate\Encryption\Encrypter; |
|
|
|
|
6
|
|
|
use Someshwer\WorldCountries\Data\DataRepository; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Author: Someshwer Bandapally |
10
|
|
|
* Date: 14-07-2018. |
11
|
|
|
* |
12
|
|
|
* Gives union territories names |
13
|
|
|
* |
14
|
|
|
* Class UnionTerritories |
15
|
|
|
*/ |
16
|
|
|
trait UnionTerritories |
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
|
|
|
* UnionTerritories constructor. |
35
|
|
|
* |
36
|
|
|
* @param DataRepository $dataRepository |
37
|
|
|
*/ |
38
|
|
|
public function __construct(DataRepository $dataRepository) |
39
|
|
|
{ |
40
|
|
|
$this->data = $dataRepository; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Optimizes union territories data. |
45
|
|
|
* |
46
|
|
|
* @param $all_territories_data |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
private function optimizeTerritoriesData($all_territories_data) |
51
|
|
|
{ |
52
|
|
|
$str_length = strlen($all_territories_data) - 4; |
53
|
|
|
$all_territories_trimmed_data = substr($all_territories_data, 0, 2).substr($all_territories_data, 3, $str_length); |
54
|
|
|
$hash = new Encrypter($this->en_key, $this->cipher); |
55
|
|
|
|
56
|
|
|
return $hash->decrypt($all_territories_trimmed_data); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Fetches union territories names from a file. |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
private function getOptimizedTerritoriesData() |
65
|
|
|
{ |
66
|
|
|
$all_territories_data = $this->data->unionTerritories(); |
67
|
|
|
$territories_data = $this->optimizeTerritoriesData($all_territories_data); |
68
|
|
|
|
69
|
|
|
return $territories_data; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Formats union territories. |
74
|
|
|
* |
75
|
|
|
* @param $territories |
76
|
|
|
* |
77
|
|
|
* @return static |
78
|
|
|
*/ |
79
|
|
|
private function formatTerritories($territories) |
80
|
|
|
{ |
81
|
|
|
return collect($territories)->transform(function ($item, $key) { |
|
|
|
|
82
|
|
|
$data['name'] = $key; |
|
|
|
|
83
|
|
|
$data['display_name'] = str_replace('_', ' ', title_case($key)); |
|
|
|
|
84
|
|
|
$data['capital'] = str_replace('_', ' ', title_case($item)); |
85
|
|
|
$data['country'] = 'India'; |
86
|
|
|
|
87
|
|
|
return $data; |
88
|
|
|
})->values(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns all union territories names. |
93
|
|
|
* |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
|
|
public function unionTerritories() |
97
|
|
|
{ |
98
|
|
|
$territories = $this->getOptimizedTerritoriesData(); |
99
|
|
|
$formatted_territories = $this->formatTerritories($territories); |
100
|
|
|
|
101
|
|
|
return ['union_territories' => ['india' => $formatted_territories]]; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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