Completed
Push — master ( 7fcc49...0a3113 )
by
unknown
10s
created

WilayahIndonesiaController::desaindex()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 27
Code Lines 19

Duplication

Lines 18
Ratio 66.67 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 19
nc 6
nop 0
dl 18
loc 27
rs 8.439
c 1
b 0
f 0
1
<?php namespace Bantenprov\WilayahIndonesia\Http\Controllers;
2
3
use App\Http\Controllers\Controller;
4
use Illuminate\Http\Request;
5
use Bantenprov\WilayahIndonesia\Facades\WilayahIndonesia;
6
use Bantenprov\WilayahIndonesia\Models\Provinsi;
7
use Laravolt\Indonesia\Indonesia;
8
use Response;
9
/**
10
 * The WilayahIndonesiaController class.
11
 *
12
 * @package Bantenprov\WilayahIndonesia
13
 * @author  bantenprov <[email protected]>
14
 */
15
class WilayahIndonesiaController extends Controller
16
{
17
	protected $indonesia;
18
	protected $provinsi;
19
	protected $kabupaten;
20
	protected $kecamatan;
21
	protected $desa;
22
	
23
	public function __construct()
24
	{
25
		$this->indonesia 	= new Indonesia;
26
		$this->provinsi 	= new Provinsi;
27
	}
28
	public function provinsiindex()
29
	{
30
		$page 					= 10;
31
		$data 					= $this->indonesia->paginateProvinces($page);
32
		return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json");
33
	}
34
	public function provinsicreate()
35
	{
36
		
37
	}
38
	public function provinsishow()
39
	{
40
		
41
	}
42
	public function provinsiedit()
43
	{
44
		
45
	}
46
	public function provinsidelete()
47
	{
48
		
49
	}
50
	public function provinsipage()
51
	{
52
		
53
	}
54
	//END DATA PROVINSI
55
56
	//DATA KABUPATEN
57
	public function kabupatenindex()
58
	{
59
		$page 							= 10;
60
		$cities 						= $this->indonesia->paginateCities($page);		
61
		foreach($cities as $key => $city){
62
			$provinces 					= $this->indonesia->paginateProvinces($city['province_id']);
63
			foreach($provinces as $province){
64
				if($city['province_id'] == $province['id']){
65
					$data 				= 	[
66
												"id"=>$city['id'],
67
												"province_name"=>$province['name'],
68
												"city_name"=>$city['name']
69
											];
70
					$cities[$key] 		= $data;
71
				}
72
			}
73
		}
74
		return Response::make(json_encode($cities, JSON_PRETTY_PRINT))->header('Content-Type', "application/json");
75
	}
76
	public function kabupatencreate()
77
	{
78
		
79
	}
80
	public function kabupatenshow()
81
	{
82
		
83
	}
84
	public function kabupatenedit()
85
	{
86
		
87
	}
88
	public function kabupatendelete()
89
	{
90
		
91
	}
92
	//END DATA KABUPATEN
93
94
	//DATA KECAMATAN
95
	public function kecamatanindex()
96
	{
97
		$page 								= 10;
98
		$districts 							= $this->indonesia->paginateDistricts($page);
99 View Code Duplication
		foreach($districts as $key => $district){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
			$cities 						= $this->indonesia->paginateCities($district['city_id']);
101
			foreach($cities as $key1 => $city){
102
				$provinces 					= $this->indonesia->paginateProvinces($city['province_id']);
103
				foreach($provinces as $province){
104
					if($city['province_id'] == $province['id']){
105
						$data 			= 	[
106
													"id"=>$district['id'],
107
													"province_name"=>$province['name'],
108
													"city_name"=>$city['name'],
109
													"district_name"=>$district['name']
110
												];
111
						$districts[$key] 		= $data;
112
					}
113
				}
114
			}			
115
		}
116
		return Response::make(json_encode($districts, JSON_PRETTY_PRINT))->header('Content-Type', "application/json");
117
	}
118
	public function kecamatancreate()
119
	{
120
		
121
	}
122
	public function kecamatanshow()
123
	{
124
		
125
	}
126
	public function kecamatanedit()
127
	{
128
		
129
	}
130
	public function kecamatandelete()
131
	{
132
		
133
	}
134
	//END DATA KECAMATAN
135
136
	//DATA DESA
137
	public function desaindex()
138
	{
139
		$page 								= 10;
140
		$villages 							= $this->indonesia->paginateVillages($page);
141
		foreach($villages as $key => $village){
142
			$districts 							= $this->indonesia->paginateDistricts($village['district_id']);
143 View Code Duplication
			foreach($districts as $key => $district){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
144
				$cities 						= $this->indonesia->paginateCities($district['city_id']);
145
				foreach($cities as $key1 => $city){
146
					$provinces 					= $this->indonesia->paginateProvinces($city['province_id']);
147
					foreach($provinces as $province){
148
						if($city['province_id'] == $province['id']){
149
							$data 			= 	[
150
														"id"=>$village['id'],
151
														"province_name"=>$province['name'],
152
														"city_name"=>$city['name'],
153
														"district_name"=>$district['name'],
154
														"village_name"=>$village['name']
155
													];
156
							$districts[$key] 		= $data;
157
						}
158
					}
159
				}			
160
			}
161
		}
162
		return Response::make(json_encode($districts, JSON_PRETTY_PRINT))->header('Content-Type', "application/json");
0 ignored issues
show
Bug introduced by
The variable $districts does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
163
	}
164
	public function desacreate()
165
	{
166
		
167
	}
168
	public function desashow()
169
	{
170
		
171
	}
172
	public function desaedit()
173
	{
174
		
175
	}
176
	public function desadelete()
177
	{
178
		
179
	}
180
	//END DATA DESA
181
	
182
}
183