Passed
Push — master ( c04375...1cad22 )
by IRFA
01:49
created

Ongkir::city()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 19
c 1
b 0
f 0
nc 7
nop 0
dl 0
loc 25
rs 8.4444
1
<?php 
2
/* 
3
	Author: Irfa Ardiansyah <[email protected]>
4
*/
5
namespace Irfa\RajaOngkir\Ongkir;
6
7
use Irfa\RajaOngkir\Ongkir\Func\Api;
8
use Irfa\RajaOngkir\Caching\ROCache;
9
use Exception;
10
11
class Ongkir extends Api{
12
13
	 private static $arr;
14
	 private static $return;
15
16
	 public static function find($arr){
17
	 	if(is_array($arr)){
18
	 		self::$arr = $arr;
19
	 	 	return new static();
20
	 	 } else{
21
	 	 	 throw new Exception("Parameter must be an array.");
22
	 	 	 return false;
0 ignored issues
show
Unused Code introduced by
return false is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
23
	 	 }
24
	       	
25
		}
26
	 public static function get(){
27
	 	if(empty(self::$return)){
28
	 	  throw new Exception("Data is not defined.");
29
	 	 	return false;
0 ignored issues
show
Unused Code introduced by
return false is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
30
	 	};
31
	 	return self::$return;
32
	 }
33
	 public static function cachingProvince(){
34
	 	self::cacheProvince();
35
	 } 
36
	 public static function cachingCity(){
37
	 	self::cacheCity();
38
	 }
39
40
	 public static function costDetails(){
41
	 	self::$return = self::get_cost_details(self::$arr);
42
	 	return new static();
43
	 } 
44
45
	 public static function courier(){
46
	 	self::$return = self::get_courier(self::$arr);
47
	 	return new static();
48
	 }
49
50
	 public static function province(){
51
	 	if(function_exists('config') AND function_exists('app')){
52
	 		$cache_type = strtolower(config('irfa.rajaongkir.cache_type'));
53
	 		if($cache_type == 'database'){
54
	 			if(ROCache::checkProv()){
55
	 				if(count(ROCache::getProv(self::$arr)) > 0){
56
	 					$ret = ROCache::getProv(self::$arr);
57
	 				} else{
58
	 					$ret = self::get_province(self::$arr);
59
	 				}
60
	 			}
61
	 		} elseif($cache_type == 'file'){
62
	 			$ret = ROCache::cacheFile(config('irfa.rajaongkir.province_table'),self::$arr);
63
	 			if($ret == null){
64
	 				throw new Exception("Cache is empty.");
65
	 	 	 		return false;
0 ignored issues
show
Unused Code introduced by
return false is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
66
	 			}
67
68
	 		} else{
69
	 			$ret = self::get_province(self::$arr);
70
	 		}
71
	 	} else{
72
	 			$ret = self::get_province(self::$arr);
73
	 		}
74
	 		self::$return = $ret;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.
Loading history...
75
	 		return new static();
76
	 	 	
77
	 }
78
79
	 public static function city(){
80
		if(function_exists('config') AND function_exists('app')){
81
	 		$cache_type = strtolower(config('irfa.rajaongkir.cache_type'));
82
	 		if($cache_type == 'database'){
83
	 			if(ROCache::checkCity()){
84
	 				if(count(ROCache::getCity(self::$arr)) > 0){
85
	 					$ret = ROCache::getCity(self::$arr);
86
	 				} else{
87
	 					$ret = self::get_city(self::$arr);
88
	 				}
89
	 			}
90
	 		} elseif($cache_type == 'file'){
91
	 			$ret = ROCache::cacheFile(config('irfa.rajaongkir.city_table'),self::$arr);
92
	 			if($ret == null){
93
	 				throw new Exception("Cache is empty. Try php artisan raja-ongkir:cache");
94
	 	 	 		return false;
0 ignored issues
show
Unused Code introduced by
return false is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
95
	 			}
96
	 		} else{
97
	 			$ret = self::get_city(self::$arr);
98
	 		}
99
	 	} else{
100
	 			$ret = self::get_city(self::$arr);
101
	 		}
102
	 	 	self::$return = $ret;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.
Loading history...
103
	 	 	return new static();
104
	 }
105
}
106