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; |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
} |
26
|
|
|
public static function get(){ |
27
|
|
|
if(empty(self::$return)){ |
28
|
|
|
throw new Exception("Data is not defined."); |
29
|
|
|
return false; |
|
|
|
|
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; |
|
|
|
|
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; |
|
|
|
|
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; |
|
|
|
|
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; |
|
|
|
|
103
|
|
|
return new static(); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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
orexit
statements that have been added for debug purposes.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.