Countries   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 86
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A countries() 0 10 1
A optimizeCountryData() 0 9 1
A searchCountry() 0 16 2
1
<?php
2
3
namespace Someshwer\WorldCountries\Lib;
4
5
use Illuminate\Encryption\Encrypter;
0 ignored issues
show
Bug introduced by
The type Illuminate\Encryption\Encrypter was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Someshwer\WorldCountries\Data\DataRepository;
7
8
/**
9
 * Author: Someshwer Bandapally
10
 * Date: 14-07-2018.
11
 *
12
 * This class gives all country names
13
 *
14
 * Class Countries
15
 */
16
class Countries extends ISOCodes
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
     * Countries 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
     * Optimizing the country data.
46
     *
47
     * @param $all_countries_data
48
     *
49
     * @return string
50
     */
51
    private function optimizeCountryData($all_countries_data)
52
    {
53
        $str_length = strlen($all_countries_data) - 4;
54
        $all_countries_trimmed_data = substr($all_countries_data, 0, 2).substr($all_countries_data, 3, $str_length);
55
        // $hash = new Encrypter($this->en_key, Config::get('app.cipher'));
56
        $hash = new Encrypter($this->en_key, $this->cipher);
57
        $all_countries = $hash->decrypt($all_countries_trimmed_data);
58
59
        return $all_countries;
60
    }
61
62
    /**
63
     * Get all countries.
64
     *
65
     * @return array
66
     */
67
    public function countries()
68
    {
69
        $all_countries_data = $this->data->countries();
70
        $all_countries = $this->optimizeCountryData($all_countries_data);
71
        $countries = collect($all_countries)->map(function ($item) {
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

71
        $countries = /** @scrutinizer ignore-call */ collect($all_countries)->map(function ($item) {
Loading history...
72
            // return title_case(str_replace('-',' ', $item));
73
            return studly_case($item);
0 ignored issues
show
Bug introduced by
The function studly_case 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 ignore-call  annotation

73
            return /** @scrutinizer ignore-call */ studly_case($item);
Loading history...
74
        });
75
76
        return ['countries' => $countries];
77
    }
78
79
    /**
80
     * Search country by search string.
81
     *
82
     * @param $search_string
83
     *
84
     * @return array
85
     */
86
    public function searchCountry($search_string = null)
87
    {
88
        $all_countries_data = $this->data->countries();
89
        $all_countries = $this->optimizeCountryData($all_countries_data);
90
        if ($search_string == null) {
91
            return array_map(function ($it) {
92
                return studly_case($it);
0 ignored issues
show
Bug introduced by
The function studly_case 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 ignore-call  annotation

92
                return /** @scrutinizer ignore-call */ studly_case($it);
Loading history...
93
            }, $all_countries);
0 ignored issues
show
Bug introduced by
$all_countries of type string is incompatible with the type array expected by parameter $arr1 of array_map(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
            }, /** @scrutinizer ignore-type */ $all_countries);
Loading history...
94
        }
95
        $countries = array_map(function ($it) {
96
            return studly_case($it);
0 ignored issues
show
Bug introduced by
The function studly_case 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 ignore-call  annotation

96
            return /** @scrutinizer ignore-call */ studly_case($it);
Loading history...
97
        }, array_filter($all_countries, function ($item) use ($search_string) {
0 ignored issues
show
Bug introduced by
$all_countries of type string is incompatible with the type array expected by parameter $input of array_filter(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

97
        }, array_filter(/** @scrutinizer ignore-type */ $all_countries, function ($item) use ($search_string) {
Loading history...
98
            return strpos($item, strtolower($search_string)) === 0;
99
        }));
100
101
        return ['countries' => array_values($countries)];
102
    }
103
}
104