Passed
Push — master ( ee094a...0581a6 )
by IRFA
02:19 queued 11s
created
src/RajaOngkirServiceProvider.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -6,38 +6,38 @@
 block discarded – undo
6 6
 
7 7
 class RajaOngkirServiceProvider extends ServiceProvider
8 8
 {
9
-    /**
10
-     * Register services.
11
-     *
12
-     * @return void
13
-     */
9
+	/**
10
+	 * Register services.
11
+	 *
12
+	 * @return void
13
+	 */
14 14
    
15
-    protected $commands = [
16
-       'Irfa\RajaOngkir\Console\Commands\ROCache',
17
-       'Irfa\RajaOngkir\Console\Commands\ROInfoPackage',
18
-    ];
19
-
20
-    public function register()
21
-    {
22
-        $this->commands($this->commands);
23
-
24
-    }
25
-
26
-    /**
27
-     * Bootstrap services.
28
-     *
29
-     * @return void
30
-     */
31
-    public function boot()
32
-    {
33
-        $this->publishes([
34
-            __DIR__.'/../resources/config/irfa/rajaongkir.php' => config_path('irfa/rajaongkir.php'), ], 'raja-ongkir');
35
-
36
-        $this->publishes([
37
-            __DIR__.'/../database/migrations/' => database_path('migrations'),
38
-        ], 'raja-ongkir');
39
-
40
-        $this->publishes([__DIR__.'/../database/migrations/' => database_path('migrations'),
41
-        ], 'raja-ongkir');
42
-    }
15
+	protected $commands = [
16
+	   'Irfa\RajaOngkir\Console\Commands\ROCache',
17
+	   'Irfa\RajaOngkir\Console\Commands\ROInfoPackage',
18
+	];
19
+
20
+	public function register()
21
+	{
22
+		$this->commands($this->commands);
23
+
24
+	}
25
+
26
+	/**
27
+	 * Bootstrap services.
28
+	 *
29
+	 * @return void
30
+	 */
31
+	public function boot()
32
+	{
33
+		$this->publishes([
34
+			__DIR__.'/../resources/config/irfa/rajaongkir.php' => config_path('irfa/rajaongkir.php'), ], 'raja-ongkir');
35
+
36
+		$this->publishes([
37
+			__DIR__.'/../database/migrations/' => database_path('migrations'),
38
+		], 'raja-ongkir');
39
+
40
+		$this->publishes([__DIR__.'/../database/migrations/' => database_path('migrations'),
41
+		], 'raja-ongkir');
42
+	}
43 43
 }
Please login to merge, or discard this patch.
src/Console/Commands/ROCache.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -7,89 +7,89 @@
 block discarded – undo
7 7
 
8 8
 class ROCache extends Command
9 9
 {
10
-    /**
11
-     * The name and signature of the console command.
12
-     *
13
-     * @var string
14
-     */
15
-    protected $signature = 'raja-ongkir:cache {name}';
10
+	/**
11
+	 * The name and signature of the console command.
12
+	 *
13
+	 * @var string
14
+	 */
15
+	protected $signature = 'raja-ongkir:cache {name}';
16 16
 
17
-    /**
18
-     * The console command description.
19
-     *
20
-     * @var string
21
-     */
22
-    protected $description = 'Create cache RajaOngkir';
17
+	/**
18
+	 * The console command description.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	protected $description = 'Create cache RajaOngkir';
23 23
 
24
-    /**
25
-     * Create a new command instance.
26
-     *
27
-     * @return void
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct();
32
-    }
24
+	/**
25
+	 * Create a new command instance.
26
+	 *
27
+	 * @return void
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct();
32
+	}
33 33
 
34
-    /**
35
-     * Execute the console command.
36
-     *
37
-     * @return mixed
38
-     */
39
-    public function handle()
40
-    {
41
-        if($this->argument('name') == "all"){
42
-            $this->all();
43
-        } elseif($this->argument('name') == "city"){
44
-            RajaOngkir::cachingCity();
45
-        } elseif($this->argument('name') == "province"){
46
-             RajaOngkir::cachingProvince();
47
-        } elseif($this->argument('name') == "subdistrict"){
48
-             RajaOngkir::cachingSubDistrict();
49
-        } elseif($this->argument('name') == "clear"){
50
-             ROCache::clearCache();
51
-        } elseif($this->argument('name') == "refresh"){
52
-             ROCache::refresh();
53
-        } else{
54
-             $this->line('<fg=yellow>Valid input is  all, clear, refresh, city, province and subdistrict.');
55
-        }
56
-    }
57
-    private function all(){
58
-        echo "---------------------".PHP_EOL;
59
-        echo"Province Caching".PHP_EOL;
60
-        echo"---------------------".PHP_EOL;
61
-        RajaOngkir::cachingProvince();
62
-        echo PHP_EOL."---------------------".PHP_EOL;
63
-        sleep(1);//Cooling Down
64
-        echo"City Caching".PHP_EOL;
65
-        echo "---------------------".PHP_EOL;
66
-        RajaOngkir::cachingCity();
67
-        echo PHP_EOL."---------------------".PHP_EOL;
68
-        sleep(1);//Cooling Down
69
-        echo"Subdistrict Caching".PHP_EOL;
70
-        echo "---------------------".PHP_EOL;
71
-        RajaOngkir::cachingSubDistrict();
72
-        echo PHP_EOL."---------------------".PHP_EOL;
73
-    }
74
-    private function refresh(){
75
-        echo "---------------------".PHP_EOL;
76
-        echo"Refresh Cache".PHP_EOL;
77
-        echo"---------------------".PHP_EOL;
78
-        ROCache::clearCache();
79
-        echo "---------------------".PHP_EOL;
80
-        echo"Province Caching".PHP_EOL;
81
-        echo"---------------------".PHP_EOL;
82
-        RajaOngkir::cachingProvince();
83
-        echo PHP_EOL."---------------------".PHP_EOL;
84
-        sleep(1);//Cooling Down
85
-        echo"City Caching".PHP_EOL;
86
-        echo "---------------------".PHP_EOL;
87
-        RajaOngkir::cachingCity();
88
-        echo PHP_EOL."---------------------".PHP_EOL;
89
-        sleep(1);//Cooling Down
90
-        echo"Subdistrict Caching".PHP_EOL;
91
-        echo "---------------------".PHP_EOL;
92
-        RajaOngkir::cachingSubDistrict();
93
-        echo PHP_EOL."---------------------".PHP_EOL;
94
-    }
34
+	/**
35
+	 * Execute the console command.
36
+	 *
37
+	 * @return mixed
38
+	 */
39
+	public function handle()
40
+	{
41
+		if($this->argument('name') == "all"){
42
+			$this->all();
43
+		} elseif($this->argument('name') == "city"){
44
+			RajaOngkir::cachingCity();
45
+		} elseif($this->argument('name') == "province"){
46
+			 RajaOngkir::cachingProvince();
47
+		} elseif($this->argument('name') == "subdistrict"){
48
+			 RajaOngkir::cachingSubDistrict();
49
+		} elseif($this->argument('name') == "clear"){
50
+			 ROCache::clearCache();
51
+		} elseif($this->argument('name') == "refresh"){
52
+			 ROCache::refresh();
53
+		} else{
54
+			 $this->line('<fg=yellow>Valid input is  all, clear, refresh, city, province and subdistrict.');
55
+		}
56
+	}
57
+	private function all(){
58
+		echo "---------------------".PHP_EOL;
59
+		echo"Province Caching".PHP_EOL;
60
+		echo"---------------------".PHP_EOL;
61
+		RajaOngkir::cachingProvince();
62
+		echo PHP_EOL."---------------------".PHP_EOL;
63
+		sleep(1);//Cooling Down
64
+		echo"City Caching".PHP_EOL;
65
+		echo "---------------------".PHP_EOL;
66
+		RajaOngkir::cachingCity();
67
+		echo PHP_EOL."---------------------".PHP_EOL;
68
+		sleep(1);//Cooling Down
69
+		echo"Subdistrict Caching".PHP_EOL;
70
+		echo "---------------------".PHP_EOL;
71
+		RajaOngkir::cachingSubDistrict();
72
+		echo PHP_EOL."---------------------".PHP_EOL;
73
+	}
74
+	private function refresh(){
75
+		echo "---------------------".PHP_EOL;
76
+		echo"Refresh Cache".PHP_EOL;
77
+		echo"---------------------".PHP_EOL;
78
+		ROCache::clearCache();
79
+		echo "---------------------".PHP_EOL;
80
+		echo"Province Caching".PHP_EOL;
81
+		echo"---------------------".PHP_EOL;
82
+		RajaOngkir::cachingProvince();
83
+		echo PHP_EOL."---------------------".PHP_EOL;
84
+		sleep(1);//Cooling Down
85
+		echo"City Caching".PHP_EOL;
86
+		echo "---------------------".PHP_EOL;
87
+		RajaOngkir::cachingCity();
88
+		echo PHP_EOL."---------------------".PHP_EOL;
89
+		sleep(1);//Cooling Down
90
+		echo"Subdistrict Caching".PHP_EOL;
91
+		echo "---------------------".PHP_EOL;
92
+		RajaOngkir::cachingSubDistrict();
93
+		echo PHP_EOL."---------------------".PHP_EOL;
94
+	}
95 95
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -38,40 +38,40 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function handle()
40 40
     {
41
-        if($this->argument('name') == "all"){
41
+        if ($this->argument('name') == "all") {
42 42
             $this->all();
43
-        } elseif($this->argument('name') == "city"){
43
+        } elseif ($this->argument('name') == "city") {
44 44
             RajaOngkir::cachingCity();
45
-        } elseif($this->argument('name') == "province"){
45
+        } elseif ($this->argument('name') == "province") {
46 46
              RajaOngkir::cachingProvince();
47
-        } elseif($this->argument('name') == "subdistrict"){
47
+        } elseif ($this->argument('name') == "subdistrict") {
48 48
              RajaOngkir::cachingSubDistrict();
49
-        } elseif($this->argument('name') == "clear"){
49
+        } elseif ($this->argument('name') == "clear") {
50 50
              ROCache::clearCache();
51
-        } elseif($this->argument('name') == "refresh"){
51
+        } elseif ($this->argument('name') == "refresh") {
52 52
              ROCache::refresh();
53
-        } else{
53
+        } else {
54 54
              $this->line('<fg=yellow>Valid input is  all, clear, refresh, city, province and subdistrict.');
55 55
         }
56 56
     }
57
-    private function all(){
57
+    private function all() {
58 58
         echo "---------------------".PHP_EOL;
59 59
         echo"Province Caching".PHP_EOL;
60 60
         echo"---------------------".PHP_EOL;
61 61
         RajaOngkir::cachingProvince();
62 62
         echo PHP_EOL."---------------------".PHP_EOL;
63
-        sleep(1);//Cooling Down
63
+        sleep(1); //Cooling Down
64 64
         echo"City Caching".PHP_EOL;
65 65
         echo "---------------------".PHP_EOL;
66 66
         RajaOngkir::cachingCity();
67 67
         echo PHP_EOL."---------------------".PHP_EOL;
68
-        sleep(1);//Cooling Down
68
+        sleep(1); //Cooling Down
69 69
         echo"Subdistrict Caching".PHP_EOL;
70 70
         echo "---------------------".PHP_EOL;
71 71
         RajaOngkir::cachingSubDistrict();
72 72
         echo PHP_EOL."---------------------".PHP_EOL;
73 73
     }
74
-    private function refresh(){
74
+    private function refresh() {
75 75
         echo "---------------------".PHP_EOL;
76 76
         echo"Refresh Cache".PHP_EOL;
77 77
         echo"---------------------".PHP_EOL;
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
         echo"---------------------".PHP_EOL;
82 82
         RajaOngkir::cachingProvince();
83 83
         echo PHP_EOL."---------------------".PHP_EOL;
84
-        sleep(1);//Cooling Down
84
+        sleep(1); //Cooling Down
85 85
         echo"City Caching".PHP_EOL;
86 86
         echo "---------------------".PHP_EOL;
87 87
         RajaOngkir::cachingCity();
88 88
         echo PHP_EOL."---------------------".PHP_EOL;
89
-        sleep(1);//Cooling Down
89
+        sleep(1); //Cooling Down
90 90
         echo"Subdistrict Caching".PHP_EOL;
91 91
         echo "---------------------".PHP_EOL;
92 92
         RajaOngkir::cachingSubDistrict();
Please login to merge, or discard this patch.
src/Console/Commands/ROInfoPackage.php 3 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -7,60 +7,60 @@  discard block
 block discarded – undo
7 7
 
8 8
 class ROInfoPackage extends Command
9 9
 {
10
-    /**
11
-     * The name and signature of the console command.
12
-     *
13
-     * @var string
14
-     */
15
-    protected $signature = 'raja-ongkir {cmd}';
10
+	/**
11
+	 * The name and signature of the console command.
12
+	 *
13
+	 * @var string
14
+	 */
15
+	protected $signature = 'raja-ongkir {cmd}';
16 16
 
17
-    /**
18
-     * The console command description.
19
-     *
20
-     * @var string
21
-     */
22
-    protected $description = 'Option';
17
+	/**
18
+	 * The console command description.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	protected $description = 'Option';
23 23
 
24
-    /**
25
-     * Create a new command instance.
26
-     *
27
-     * @return void
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct();
32
-    }
24
+	/**
25
+	 * Create a new command instance.
26
+	 *
27
+	 * @return void
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct();
32
+	}
33 33
 
34
-    /**
35
-     * Execute the console command.
36
-     *
37
-     * @return mixed
38
-     */
39
-    public function handle()
40
-    {
41
-        if($this->argument('cmd') == "version" || $this->argument('cmd') == "v" ){
42
-            $this->informasi();
43
-        } elseif($this->argument('cmd') == "key"){
44
-            $this->line('Api Key: '.config('irfa.rajaongkir.api_key'));
45
-        } elseif($this->argument('cmd') == "type"){
46
-            $this->line('Account Type: '.config('irfa.rajaongkir.account_type'));
47
-        }  elseif($this->argument('cmd') == "info"){
48
-             $this->informasi();
49
-            $this->line('-------------------------------------------------------------------------------');
50
-            $this->line('Account Type: '.config('irfa.rajaongkir.account_type'));
51
-            $this->line('Api Key: '.config('irfa.rajaongkir.api_key'));
52
-            $this->line('Api Version: '.config('irfa.rajaongkir.api_version'));
53
-            $this->line('Province Table: '.config('irfa.rajaongkir.province_table'));
54
-            $this->line('City Table: '.config('irfa.rajaongkir.city_table'));
55
-            $this->line('Subdistrict Table: '.config('irfa.rajaongkir.subdistrict_table'));
56
-            $this->line('Cache Type: '.config('irfa.rajaongkir.cache_type'));
57
-        } else{
58
-             $this->line('<fg=yellow>valid input is  version, key, type, info,and v.');
59
-        }
60
-    }
34
+	/**
35
+	 * Execute the console command.
36
+	 *
37
+	 * @return mixed
38
+	 */
39
+	public function handle()
40
+	{
41
+		if($this->argument('cmd') == "version" || $this->argument('cmd') == "v" ){
42
+			$this->informasi();
43
+		} elseif($this->argument('cmd') == "key"){
44
+			$this->line('Api Key: '.config('irfa.rajaongkir.api_key'));
45
+		} elseif($this->argument('cmd') == "type"){
46
+			$this->line('Account Type: '.config('irfa.rajaongkir.account_type'));
47
+		}  elseif($this->argument('cmd') == "info"){
48
+			 $this->informasi();
49
+			$this->line('-------------------------------------------------------------------------------');
50
+			$this->line('Account Type: '.config('irfa.rajaongkir.account_type'));
51
+			$this->line('Api Key: '.config('irfa.rajaongkir.api_key'));
52
+			$this->line('Api Version: '.config('irfa.rajaongkir.api_version'));
53
+			$this->line('Province Table: '.config('irfa.rajaongkir.province_table'));
54
+			$this->line('City Table: '.config('irfa.rajaongkir.city_table'));
55
+			$this->line('Subdistrict Table: '.config('irfa.rajaongkir.subdistrict_table'));
56
+			$this->line('Cache Type: '.config('irfa.rajaongkir.cache_type'));
57
+		} else{
58
+			 $this->line('<fg=yellow>valid input is  version, key, type, info,and v.');
59
+		}
60
+	}
61 61
 
62
-    private function informasi(){
63
-         $this->line(" |_   _|     / _|               |  __ \     (_)        / __ \            | |  (_)     
62
+	private function informasi(){
63
+		 $this->line(" |_   _|     / _|               |  __ \     (_)        / __ \            | |  (_)     
64 64
    | |  _ __| |_ __ _   ______  | |__) |__ _ _  __ _  | |  | |_ __   __ _| | ___ _ __ 
65 65
    | | | '__|  _/ _` | |______| |  _  // _` | |/ _` | | |  | | '_ \ / _` | |/ / | '__|
66 66
   _| |_| |  | || (_| |          | | \ \ (_| | | (_| | | |__| | | | | (_| |   <| | |   
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
                                            _/ |                      __/ |            
69 69
                                           |__/                      |___/             ".PHP_EOL);
70 70
 
71
-    $this->line('-------------------------------------------------------------------------------');
72
-    $this->line('Raja Ongkir');
73
-    $this->line('Version 1.6.0 (2020)');
74
-    $this->line('https://github.com/irfaardy/raja-ongkir');
75
-    }
71
+	$this->line('-------------------------------------------------------------------------------');
72
+	$this->line('Raja Ongkir');
73
+	$this->line('Version 1.6.0 (2020)');
74
+	$this->line('https://github.com/irfaardy/raja-ongkir');
75
+	}
76 76
    
77 77
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function handle()
40 40
     {
41
-        if($this->argument('cmd') == "version" || $this->argument('cmd') == "v" ){
41
+        if ($this->argument('cmd') == "version" || $this->argument('cmd') == "v") {
42 42
             $this->informasi();
43
-        } elseif($this->argument('cmd') == "key"){
43
+        } elseif ($this->argument('cmd') == "key") {
44 44
             $this->line('Api Key: '.config('irfa.rajaongkir.api_key'));
45
-        } elseif($this->argument('cmd') == "type"){
45
+        } elseif ($this->argument('cmd') == "type") {
46 46
             $this->line('Account Type: '.config('irfa.rajaongkir.account_type'));
47
-        }  elseif($this->argument('cmd') == "info"){
47
+        }  elseif ($this->argument('cmd') == "info") {
48 48
              $this->informasi();
49 49
             $this->line('-------------------------------------------------------------------------------');
50 50
             $this->line('Account Type: '.config('irfa.rajaongkir.account_type'));
@@ -54,12 +54,12 @@  discard block
 block discarded – undo
54 54
             $this->line('City Table: '.config('irfa.rajaongkir.city_table'));
55 55
             $this->line('Subdistrict Table: '.config('irfa.rajaongkir.subdistrict_table'));
56 56
             $this->line('Cache Type: '.config('irfa.rajaongkir.cache_type'));
57
-        } else{
57
+        } else {
58 58
              $this->line('<fg=yellow>valid input is  version, key, type, info,and v.');
59 59
         }
60 60
     }
61 61
 
62
-    private function informasi(){
62
+    private function informasi() {
63 63
          $this->line(" |_   _|     / _|               |  __ \     (_)        / __ \            | |  (_)     
64 64
    | |  _ __| |_ __ _   ______  | |__) |__ _ _  __ _  | |  | |_ __   __ _| | ___ _ __ 
65 65
    | | | '__|  _/ _` | |______| |  _  // _` | |/ _` | | |  | | '_ \ / _` | |/ / | '__|
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
             $this->line('Api Key: '.config('irfa.rajaongkir.api_key'));
45 45
         } elseif($this->argument('cmd') == "type"){
46 46
             $this->line('Account Type: '.config('irfa.rajaongkir.account_type'));
47
-        }  elseif($this->argument('cmd') == "info"){
47
+        } elseif($this->argument('cmd') == "info"){
48 48
              $this->informasi();
49 49
             $this->line('-------------------------------------------------------------------------------');
50 50
             $this->line('Account Type: '.config('irfa.rajaongkir.account_type'));
Please login to merge, or discard this patch.
src/Ongkir/Func/Api.php 2 patches
Indentation   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -12,292 +12,292 @@
 block discarded – undo
12 12
 
13 13
 class Api extends CacheCurl
14 14
 {
15
-    private static $account_type;
16
-    private static $api_key;
17
-    private static $api_version;
18
-    private static $url;
19
-    private static $count = 0;
20
-
21
-    private static function setup_option()
22
-    {
23
-        if (function_exists('config') and function_exists('app')) {//Load Config For Laravel
24
-            self::$account_type = strtolower(config('irfa.rajaongkir.account_type'));
25
-            self::$api_key = config('irfa.rajaongkir.api_key');
26
-            self::$api_version = config('irfa.rajaongkir.api_version');
27
-        } else {//Load config For PHP Native
28
-            require __DIR__.'../../../../config/config.php';
29
-            self::$account_type = strtolower($config['account_type']);
30
-            self::$api_key = $config['api_key'];
31
-            self::$api_version = $config['api_version'];
32
-        }
33
-        if (self::$account_type == 'pro') {
34
-            self::$url = 'https://pro.rajaongkir.com/api';
35
-        } else {
36
-            self::$url = 'https://api.rajaongkir.com/'.self::$account_type;
37
-        }
38
-    }
39
-
40
-    protected static function cacheProvince()
41
-    {
42
-        self::setup_option();
43
-        echo "Retrieving data from \033[96m".self::$url."...\033[0m".PHP_EOL;
44
-        CacheCurl::caching(self::get_province())->province();
45
-    }
46
-
47
-    protected static function cacheCity()
48
-    {
49
-        self::setup_option();
50
-        echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL;
51
-        CacheCurl::caching(self::get_city())->city();
52
-    }
53
-    protected static function cacheSubDistrict($arr)
54
-    {
55
-        self::setup_option();
56
-        echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL;
57
-        CacheCurl::caching(self::getSubdistrict($arr))->subdistrict();
58
-    }
59
-    protected static function get_province($arr = null)
60
-    {
61
-        if ($arr != null) {
62
-            $province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null;
63
-        } else {
64
-            $province_id = null;
65
-        }
66
-        self::setup_option();
67
-        $curl = curl_init();
68
-        curl_setopt_array($curl, [
69
-            CURLOPT_URL            => self::$url.'/province'.$province_id,
70
-            CURLOPT_RETURNTRANSFER => true,
71
-            CURLOPT_ENCODING       => '',
72
-            CURLOPT_MAXREDIRS      => 10,
73
-            CURLOPT_TIMEOUT        => 30,
74
-            CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
75
-            CURLOPT_CUSTOMREQUEST  => 'GET',
76
-            CURLOPT_HTTPHEADER     => [
77
-                'key: '.self::$api_key,
78
-            ],
79
-        ]);
80
-        $response = curl_exec($curl);
81
-        $err = curl_error($curl);
82
-
83
-        curl_close($curl);
84
-
85
-        if ($err) {
86
-            self::exceptCurl($err);
87
-        } else {
88
-            $json = json_decode($response, false)->rajaongkir;
89
-            if ($json->status->code == '400') {
90
-                throw new Exception($json->status->description);
91
-            } else {
92
-                $res = $json->results;
93
-
94
-                return $res;
95
-            }
96
-        }
97
-    }
98
-
99
-    protected static function get_city($arr = null)
100
-    {
101
-        if ($arr != null) {
102
-            $province_id = array_key_exists('province_id', $arr) ? '?province='.$arr['province_id'] : null;
103
-        } else {
104
-            $province_id = null;
105
-        }
106
-        self::setup_option();
107
-        $curl = curl_init();
108
-        curl_setopt_array($curl, [
109
-            CURLOPT_URL            => self::$url.'/city'.$province_id,
110
-            CURLOPT_RETURNTRANSFER => true,
111
-            CURLOPT_ENCODING       => '',
112
-            CURLOPT_MAXREDIRS      => 10,
113
-            CURLOPT_TIMEOUT        => 30,
114
-            CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
115
-            CURLOPT_CUSTOMREQUEST  => 'GET',
116
-            CURLOPT_HTTPHEADER     => [
117
-                'key: '.self::$api_key,
118
-            ],
119
-        ]);
120
-        $response = curl_exec($curl);
121
-        $err = curl_error($curl);
122
-
123
-        curl_close($curl);
124
-
125
-        if ($err) {
126
-           self::exceptCurl($err);
127
-        } else {
128
-            $json = json_decode($response, false)->rajaongkir;
129
-            if ($json->status->code == '400') {
130
-                throw new Exception($json->status->description);
131
-            } else {
132
-                $res = $json->results;
133
-
134
-                return $res;
135
-            }
136
-        }
137
-    }
138
-
139
-    protected static function get_courier($arr)
140
-    {
141
-        $origin = $arr['origin'];
142
-        $destination = $arr['destination'];
143
-        $weight = $arr['weight'];
144
-        $courier = $arr['courier'];
145
-        $res = self::curl_cost_get($origin, $destination, $weight, $courier);
146
-
147
-        return $res;
148
-    }
149
-
150
-    protected static function get_cost_details($arr)
151
-    {
152
-        $origin = $arr['origin'];
153
-        $destination = $arr['destination'];
154
-        $weight = $arr['weight'];
155
-        $courier = $arr['courier'];
156
-        $res = self::curl_cost_get($origin, $destination, $weight, $courier);
157
-
158
-        return $res[0]->costs;
159
-    }
160
-
161
-    private static function curl_cost_get($origin, $destination, $weight, $courier)
162
-    {
163
-        $curl = curl_init();
164
-
165
-        curl_setopt_array($curl, self::curl_cost_option($origin, $destination, $weight, $courier));
166
-
167
-        $response = curl_exec($curl);
168
-        $err = curl_error($curl);
169
-
170
-        curl_close($curl);
171
-
172
-        if ($err) {
173
-            echo "Can't connect to server, please check your internet connection.";
174
-            exit();
175
-        } else {
176
-            $json = json_decode($response, false)->rajaongkir;
177
-            if ($json->status->code == '400') {
178
-                throw new Exception($json->status->description);
179
-            } else {
180
-                $res = $json->results;
181
-
182
-                return $res;
183
-            }
184
-        }
185
-    }
186
-
187
-    private static function curl_cost_option($origin, $destination, $weight, $courier)
188
-    {
189
-        self::setup_option();
190
-
191
-        return [
192
-            CURLOPT_URL            => self::$url.'/cost',
193
-            CURLOPT_RETURNTRANSFER => true,
194
-            CURLOPT_ENCODING       => '',
195
-            CURLOPT_MAXREDIRS      => 10,
196
-            CURLOPT_TIMEOUT        => 30,
197
-            CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
198
-            CURLOPT_CUSTOMREQUEST  => 'POST',
199
-            CURLOPT_POSTFIELDS     => 'origin='.$origin.'&destination='.$destination.'&weight='.$weight.'&courier='.strtolower($courier),
200
-            CURLOPT_HTTPHEADER     => [
201
-                'content-type: application/x-www-form-urlencoded',
202
-                'key: '.self::$api_key,
203
-            ],
204
-        ];
205
-    }
15
+	private static $account_type;
16
+	private static $api_key;
17
+	private static $api_version;
18
+	private static $url;
19
+	private static $count = 0;
20
+
21
+	private static function setup_option()
22
+	{
23
+		if (function_exists('config') and function_exists('app')) {//Load Config For Laravel
24
+			self::$account_type = strtolower(config('irfa.rajaongkir.account_type'));
25
+			self::$api_key = config('irfa.rajaongkir.api_key');
26
+			self::$api_version = config('irfa.rajaongkir.api_version');
27
+		} else {//Load config For PHP Native
28
+			require __DIR__.'../../../../config/config.php';
29
+			self::$account_type = strtolower($config['account_type']);
30
+			self::$api_key = $config['api_key'];
31
+			self::$api_version = $config['api_version'];
32
+		}
33
+		if (self::$account_type == 'pro') {
34
+			self::$url = 'https://pro.rajaongkir.com/api';
35
+		} else {
36
+			self::$url = 'https://api.rajaongkir.com/'.self::$account_type;
37
+		}
38
+	}
39
+
40
+	protected static function cacheProvince()
41
+	{
42
+		self::setup_option();
43
+		echo "Retrieving data from \033[96m".self::$url."...\033[0m".PHP_EOL;
44
+		CacheCurl::caching(self::get_province())->province();
45
+	}
46
+
47
+	protected static function cacheCity()
48
+	{
49
+		self::setup_option();
50
+		echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL;
51
+		CacheCurl::caching(self::get_city())->city();
52
+	}
53
+	protected static function cacheSubDistrict($arr)
54
+	{
55
+		self::setup_option();
56
+		echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL;
57
+		CacheCurl::caching(self::getSubdistrict($arr))->subdistrict();
58
+	}
59
+	protected static function get_province($arr = null)
60
+	{
61
+		if ($arr != null) {
62
+			$province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null;
63
+		} else {
64
+			$province_id = null;
65
+		}
66
+		self::setup_option();
67
+		$curl = curl_init();
68
+		curl_setopt_array($curl, [
69
+			CURLOPT_URL            => self::$url.'/province'.$province_id,
70
+			CURLOPT_RETURNTRANSFER => true,
71
+			CURLOPT_ENCODING       => '',
72
+			CURLOPT_MAXREDIRS      => 10,
73
+			CURLOPT_TIMEOUT        => 30,
74
+			CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
75
+			CURLOPT_CUSTOMREQUEST  => 'GET',
76
+			CURLOPT_HTTPHEADER     => [
77
+				'key: '.self::$api_key,
78
+			],
79
+		]);
80
+		$response = curl_exec($curl);
81
+		$err = curl_error($curl);
82
+
83
+		curl_close($curl);
84
+
85
+		if ($err) {
86
+			self::exceptCurl($err);
87
+		} else {
88
+			$json = json_decode($response, false)->rajaongkir;
89
+			if ($json->status->code == '400') {
90
+				throw new Exception($json->status->description);
91
+			} else {
92
+				$res = $json->results;
93
+
94
+				return $res;
95
+			}
96
+		}
97
+	}
98
+
99
+	protected static function get_city($arr = null)
100
+	{
101
+		if ($arr != null) {
102
+			$province_id = array_key_exists('province_id', $arr) ? '?province='.$arr['province_id'] : null;
103
+		} else {
104
+			$province_id = null;
105
+		}
106
+		self::setup_option();
107
+		$curl = curl_init();
108
+		curl_setopt_array($curl, [
109
+			CURLOPT_URL            => self::$url.'/city'.$province_id,
110
+			CURLOPT_RETURNTRANSFER => true,
111
+			CURLOPT_ENCODING       => '',
112
+			CURLOPT_MAXREDIRS      => 10,
113
+			CURLOPT_TIMEOUT        => 30,
114
+			CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
115
+			CURLOPT_CUSTOMREQUEST  => 'GET',
116
+			CURLOPT_HTTPHEADER     => [
117
+				'key: '.self::$api_key,
118
+			],
119
+		]);
120
+		$response = curl_exec($curl);
121
+		$err = curl_error($curl);
122
+
123
+		curl_close($curl);
124
+
125
+		if ($err) {
126
+		   self::exceptCurl($err);
127
+		} else {
128
+			$json = json_decode($response, false)->rajaongkir;
129
+			if ($json->status->code == '400') {
130
+				throw new Exception($json->status->description);
131
+			} else {
132
+				$res = $json->results;
133
+
134
+				return $res;
135
+			}
136
+		}
137
+	}
138
+
139
+	protected static function get_courier($arr)
140
+	{
141
+		$origin = $arr['origin'];
142
+		$destination = $arr['destination'];
143
+		$weight = $arr['weight'];
144
+		$courier = $arr['courier'];
145
+		$res = self::curl_cost_get($origin, $destination, $weight, $courier);
146
+
147
+		return $res;
148
+	}
149
+
150
+	protected static function get_cost_details($arr)
151
+	{
152
+		$origin = $arr['origin'];
153
+		$destination = $arr['destination'];
154
+		$weight = $arr['weight'];
155
+		$courier = $arr['courier'];
156
+		$res = self::curl_cost_get($origin, $destination, $weight, $courier);
157
+
158
+		return $res[0]->costs;
159
+	}
160
+
161
+	private static function curl_cost_get($origin, $destination, $weight, $courier)
162
+	{
163
+		$curl = curl_init();
164
+
165
+		curl_setopt_array($curl, self::curl_cost_option($origin, $destination, $weight, $courier));
166
+
167
+		$response = curl_exec($curl);
168
+		$err = curl_error($curl);
169
+
170
+		curl_close($curl);
171
+
172
+		if ($err) {
173
+			echo "Can't connect to server, please check your internet connection.";
174
+			exit();
175
+		} else {
176
+			$json = json_decode($response, false)->rajaongkir;
177
+			if ($json->status->code == '400') {
178
+				throw new Exception($json->status->description);
179
+			} else {
180
+				$res = $json->results;
181
+
182
+				return $res;
183
+			}
184
+		}
185
+	}
186
+
187
+	private static function curl_cost_option($origin, $destination, $weight, $courier)
188
+	{
189
+		self::setup_option();
190
+
191
+		return [
192
+			CURLOPT_URL            => self::$url.'/cost',
193
+			CURLOPT_RETURNTRANSFER => true,
194
+			CURLOPT_ENCODING       => '',
195
+			CURLOPT_MAXREDIRS      => 10,
196
+			CURLOPT_TIMEOUT        => 30,
197
+			CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
198
+			CURLOPT_CUSTOMREQUEST  => 'POST',
199
+			CURLOPT_POSTFIELDS     => 'origin='.$origin.'&destination='.$destination.'&weight='.$weight.'&courier='.strtolower($courier),
200
+			CURLOPT_HTTPHEADER     => [
201
+				'content-type: application/x-www-form-urlencoded',
202
+				'key: '.self::$api_key,
203
+			],
204
+		];
205
+	}
206 206
 ///PRO
207
-     protected static function getSubdistrict($arr = null)
208
-    {
209
-        if ($arr != null) {
210
-            $city = array_key_exists('city', $arr) ? '?city='.$arr['city'] : null;
211
-        } else {
212
-            $city = null;
213
-        }
214
-        self::setup_option();
215
-        $curl = curl_init();
216
-        curl_setopt_array($curl, [
217
-            CURLOPT_URL            => self::$url.'/subdistrict'.$city,
218
-            CURLOPT_RETURNTRANSFER => true,
219
-            CURLOPT_ENCODING       => '',
220
-            CURLOPT_MAXREDIRS      => 10,
221
-            CURLOPT_TIMEOUT        => 30,
222
-            CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
223
-            CURLOPT_CUSTOMREQUEST  => 'GET',
224
-            CURLOPT_HTTPHEADER     => [
225
-                'key: '.self::$api_key,
226
-            ],
227
-        ]);
228
-        $response = curl_exec($curl);
229
-        $err = curl_error($curl);
230
-
231
-        curl_close($curl);
232
-
233
-        if ($err) {
234
-            self::exceptCurl($err);
235
-        } else {
236
-            $json = json_decode($response, false)->rajaongkir;
237
-            if ($json->status->code == '400') {
238
-                throw new Exception($json->status->description);
239
-            } else {
240
-                $res = $json->results;
241
-
242
-                return $res;
243
-            }
244
-        }
245
-    }
207
+	 protected static function getSubdistrict($arr = null)
208
+	{
209
+		if ($arr != null) {
210
+			$city = array_key_exists('city', $arr) ? '?city='.$arr['city'] : null;
211
+		} else {
212
+			$city = null;
213
+		}
214
+		self::setup_option();
215
+		$curl = curl_init();
216
+		curl_setopt_array($curl, [
217
+			CURLOPT_URL            => self::$url.'/subdistrict'.$city,
218
+			CURLOPT_RETURNTRANSFER => true,
219
+			CURLOPT_ENCODING       => '',
220
+			CURLOPT_MAXREDIRS      => 10,
221
+			CURLOPT_TIMEOUT        => 30,
222
+			CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
223
+			CURLOPT_CUSTOMREQUEST  => 'GET',
224
+			CURLOPT_HTTPHEADER     => [
225
+				'key: '.self::$api_key,
226
+			],
227
+		]);
228
+		$response = curl_exec($curl);
229
+		$err = curl_error($curl);
230
+
231
+		curl_close($curl);
232
+
233
+		if ($err) {
234
+			self::exceptCurl($err);
235
+		} else {
236
+			$json = json_decode($response, false)->rajaongkir;
237
+			if ($json->status->code == '400') {
238
+				throw new Exception($json->status->description);
239
+			} else {
240
+				$res = $json->results;
241
+
242
+				return $res;
243
+			}
244
+		}
245
+	}
246 246
 
247 247
 private static function exceptCurl($err){
248
-      if(php_sapi_name() == "cli"){
249
-                echo "Can't connect to server, please check your internet connection.\n";
250
-                echo "Exception: \033[31m".$err;
251
-                exit();
252
-            } else{
253
-                throw new Exception($err);
254
-            }
248
+	  if(php_sapi_name() == "cli"){
249
+				echo "Can't connect to server, please check your internet connection.\n";
250
+				echo "Exception: \033[31m".$err;
251
+				exit();
252
+			} else{
253
+				throw new Exception($err);
254
+			}
255 255
 }
256 256
 
257 257
 protected static function test_connection($arr = null)
258 258
 {
259
-        if ($arr != null) {
260
-            $province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null;
261
-        } else {
262
-            $province_id = null;
263
-        }
264
-        self::setup_option();
265
-        $curl = curl_init();
266
-        curl_setopt_array($curl, [
267
-            CURLOPT_URL            => self::$url.'/province'.$province_id,
268
-            CURLOPT_RETURNTRANSFER => true,
269
-            CURLOPT_ENCODING       => '',
270
-            CURLOPT_MAXREDIRS      => 10,
271
-            CURLOPT_TIMEOUT        => 30,
272
-            CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
273
-            CURLOPT_CUSTOMREQUEST  => 'GET',
274
-            CURLOPT_HTTPHEADER     => [
275
-                'key: '.self::$api_key,
276
-            ],
277
-        ]);
278
-        $response = curl_exec($curl);
279
-        $err = curl_error($curl);
280
-
281
-        curl_close($curl);
282
-
283
-        if ($err) {
284
-            $result = false;
285
-            return $result;
286
-        } else {
287
-            $data = json_decode($response, false);
288
-            if(!empty($data)){
289
-                $json = $data->rajaongkir;
290
-                if ($json->status->code == '400') {
291
-                    $result = ['res' => $json->status->code,'success'=> false];
292
-                    return $result;
293
-                } else {
294
-                    $result = ['res' => "Connected to server.",'success'=> true];
295
-                    return $result;
296
-                }
297
-             } else{
298
-                 $result = ['res' => "Data is Empty.",'success'=> false];
299
-                return $result;
300
-             }
301
-        }
302
-    }
259
+		if ($arr != null) {
260
+			$province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null;
261
+		} else {
262
+			$province_id = null;
263
+		}
264
+		self::setup_option();
265
+		$curl = curl_init();
266
+		curl_setopt_array($curl, [
267
+			CURLOPT_URL            => self::$url.'/province'.$province_id,
268
+			CURLOPT_RETURNTRANSFER => true,
269
+			CURLOPT_ENCODING       => '',
270
+			CURLOPT_MAXREDIRS      => 10,
271
+			CURLOPT_TIMEOUT        => 30,
272
+			CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
273
+			CURLOPT_CUSTOMREQUEST  => 'GET',
274
+			CURLOPT_HTTPHEADER     => [
275
+				'key: '.self::$api_key,
276
+			],
277
+		]);
278
+		$response = curl_exec($curl);
279
+		$err = curl_error($curl);
280
+
281
+		curl_close($curl);
282
+
283
+		if ($err) {
284
+			$result = false;
285
+			return $result;
286
+		} else {
287
+			$data = json_decode($response, false);
288
+			if(!empty($data)){
289
+				$json = $data->rajaongkir;
290
+				if ($json->status->code == '400') {
291
+					$result = ['res' => $json->status->code,'success'=> false];
292
+					return $result;
293
+				} else {
294
+					$result = ['res' => "Connected to server.",'success'=> true];
295
+					return $result;
296
+				}
297
+			 } else{
298
+				 $result = ['res' => "Data is Empty.",'success'=> false];
299
+				return $result;
300
+			 }
301
+		}
302
+	}
303 303
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
         }
245 245
     }
246 246
 
247
-private static function exceptCurl($err){
248
-      if(php_sapi_name() == "cli"){
247
+private static function exceptCurl($err) {
248
+      if (php_sapi_name() == "cli") {
249 249
                 echo "Can't connect to server, please check your internet connection.\n";
250 250
                 echo "Exception: \033[31m".$err;
251 251
                 exit();
252
-            } else{
252
+            } else {
253 253
                 throw new Exception($err);
254 254
             }
255 255
 }
@@ -285,17 +285,17 @@  discard block
 block discarded – undo
285 285
             return $result;
286 286
         } else {
287 287
             $data = json_decode($response, false);
288
-            if(!empty($data)){
288
+            if (!empty($data)) {
289 289
                 $json = $data->rajaongkir;
290 290
                 if ($json->status->code == '400') {
291
-                    $result = ['res' => $json->status->code,'success'=> false];
291
+                    $result = ['res' => $json->status->code, 'success'=> false];
292 292
                     return $result;
293 293
                 } else {
294
-                    $result = ['res' => "Connected to server.",'success'=> true];
294
+                    $result = ['res' => "Connected to server.", 'success'=> true];
295 295
                     return $result;
296 296
                 }
297
-             } else{
298
-                 $result = ['res' => "Data is Empty.",'success'=> false];
297
+             } else {
298
+                 $result = ['res' => "Data is Empty.", 'success'=> false];
299 299
                 return $result;
300 300
              }
301 301
         }
Please login to merge, or discard this patch.
src/Ongkir/Ongkir.php 2 patches
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -12,216 +12,216 @@
 block discarded – undo
12 12
 
13 13
 class Ongkir extends Api
14 14
 {
15
-    private static $arr;
16
-    private static $return;
17
-    private static $province;
18
-    private static $city;
19
-    private static $cacheType;
20
-
21
-    public static function find($arr)
22
-    {
23
-        if (is_array($arr)) {
24
-            self::$arr = $arr;
25
-
26
-            return new static();
27
-        } else {
28
-            throw new Exception('Parameter must be an array.');
29
-
30
-            return false;
31
-        }
32
-    }
33
-
34
-    public static function get()
35
-    {
36
-        self::$arr = null; //Clear parameter
37
-        if (empty(self::$return)) {
38
-            throw new Exception('Data is not defined.');
39
-
40
-            return false;
41
-        }
42
-        $ret = self::$return;
43
-        self::$return = null;
44
-
45
-        return $ret;
46
-    }
47
-
48
-    public static function cachingProvince()
49
-    {
50
-        self::cacheProvince();
51
-    }
52
-
53
-     public static function cachingSubDistrict()
54
-    {
55
-        $get = self::cityData();
56
-        $count = count($get);
57
-        $i=0;
58
-        echo PHP_EOL."\033[42mThis may take longer, please wait.\033[0m";
59
-        foreach($get as $city){
60
-            $i++;
61
-             echo PHP_EOL."Remaining City\033[96m ".$i."/".$count."\033[0m";
62
-             echo PHP_EOL."Get Subdistrict\033[96m ".$city->city_name."...\033[0m".PHP_EOL;
63
-             self::cacheSubDistrict(['city' =>  $city->city_id]);
64
-             echo PHP_EOL;
65
-        }
66
-    }
67
-
68
-    public static function cachingCity()
69
-    {
70
-        self::cacheCity();
71
-    }
72
-
73
-    public static function costDetails()
74
-    {
75
-        self::$return = self::get_cost_details(self::$arr);
76
-
77
-        return new static();
78
-    } 
79
-    public static function testConnection()
80
-    {
81
-        self::$return = self::test_connection(self::$arr);
82
-
83
-        return new static();
84
-    }
85
-
86
-    public static function courier()
87
-    {
88
-        self::$return = self::get_courier(self::$arr);
89
-
90
-        return new static();
91
-    }
15
+	private static $arr;
16
+	private static $return;
17
+	private static $province;
18
+	private static $city;
19
+	private static $cacheType;
20
+
21
+	public static function find($arr)
22
+	{
23
+		if (is_array($arr)) {
24
+			self::$arr = $arr;
25
+
26
+			return new static();
27
+		} else {
28
+			throw new Exception('Parameter must be an array.');
29
+
30
+			return false;
31
+		}
32
+	}
33
+
34
+	public static function get()
35
+	{
36
+		self::$arr = null; //Clear parameter
37
+		if (empty(self::$return)) {
38
+			throw new Exception('Data is not defined.');
39
+
40
+			return false;
41
+		}
42
+		$ret = self::$return;
43
+		self::$return = null;
44
+
45
+		return $ret;
46
+	}
47
+
48
+	public static function cachingProvince()
49
+	{
50
+		self::cacheProvince();
51
+	}
52
+
53
+	 public static function cachingSubDistrict()
54
+	{
55
+		$get = self::cityData();
56
+		$count = count($get);
57
+		$i=0;
58
+		echo PHP_EOL."\033[42mThis may take longer, please wait.\033[0m";
59
+		foreach($get as $city){
60
+			$i++;
61
+			 echo PHP_EOL."Remaining City\033[96m ".$i."/".$count."\033[0m";
62
+			 echo PHP_EOL."Get Subdistrict\033[96m ".$city->city_name."...\033[0m".PHP_EOL;
63
+			 self::cacheSubDistrict(['city' =>  $city->city_id]);
64
+			 echo PHP_EOL;
65
+		}
66
+	}
67
+
68
+	public static function cachingCity()
69
+	{
70
+		self::cacheCity();
71
+	}
72
+
73
+	public static function costDetails()
74
+	{
75
+		self::$return = self::get_cost_details(self::$arr);
76
+
77
+		return new static();
78
+	} 
79
+	public static function testConnection()
80
+	{
81
+		self::$return = self::test_connection(self::$arr);
82
+
83
+		return new static();
84
+	}
85
+
86
+	public static function courier()
87
+	{
88
+		self::$return = self::get_courier(self::$arr);
89
+
90
+		return new static();
91
+	}
92 92
    
93
-    public static function province()
94
-    {
95
-        $ret = self::provinceData();
96
-        self::$return = $ret;
97
-
98
-        return new static();
99
-    } 
100
-
101
-    public static function subDistrict()
102
-    {
103
-        $ret = self::subDistrictData();
104
-        self::$return = $ret;
105
-
106
-        return new static();
107
-    }
108
-    public static function internationalOrigin()
109
-    {
110
-        $ret = self::internationalOriginData();
111
-        self::$return = $ret;
112
-
113
-        return new static();
114
-    }
115
-
116
-    public static function city()
117
-    {
118
-        $ret = self::cityData();
119
-        self::$return = $ret;
120
-
121
-        return new static();
122
-    }
123
-
124
-    private static function setupConfig()
125
-    {
126
-        self::$cacheType = strtolower(config('irfa.rajaongkir.cache_type'));
127
-        self::$province = config('irfa.rajaongkir.province_table');
128
-        self::$city = config('irfa.rajaongkir.city_table');
129
-    }
130
-
131
-    private static function provinceData()
132
-    {
133
-        if (function_exists('config') && function_exists('app')) {
134
-            self::setupConfig();
135
-            $cache_type = self::$cacheType;
136
-            if ($cache_type == 'database') {
137
-                if (ROCache::checkProv()) {
138
-                    if (count(ROCache::getProv(self::$arr)) > 0) {
139
-                        $ret = ROCache::getProv(self::$arr);
140
-                    } else {
141
-                        $ret = self::get_province(self::$arr);
142
-                    }
143
-                }
144
-            } elseif ($cache_type == 'file') {
145
-                $ret = ROCache::cacheFile(self::$province, self::$arr);
146
-                if ($ret == null) {
147
-                    self::exceptionCache();
148
-                }
149
-            } else {
150
-                $ret = self::get_province(self::$arr);
151
-            }
152
-        } else {
153
-            $ret = self::get_province(self::$arr);
154
-        }
155
-
156
-        return $ret;
157
-    }
158
-    private static function subDistrictData()
159
-    {
160
-        if (function_exists('config') && function_exists('app')) {
161
-            self::setupConfig();
162
-            $cache_type = self::$cacheType;
163
-            if ($cache_type == 'database') {
164
-                if (ROCache::checkProv()) {
165
-                    if (count(ROCache::getSubdistrict(self::$arr)) > 0) {
166
-                        $ret = ROCache::getSubdistrict(self::$arr);
167
-                    } else {
168
-                        $ret = self::getSubdistrict(self::$arr);
169
-                    }
170
-                }
171
-            } elseif ($cache_type == 'file') {
172
-                $ret = ROCache::cacheFile(self::$province, self::$arr);
173
-                if ($ret == null) {
174
-                    self::exceptionCache();
175
-                }
176
-            } else {
177
-                $ret = self::getSubdistrict(self::$arr);
178
-            }
179
-        } else {
180
-            $ret = self::getSubdistrict(self::$arr);
181
-        }
182
-
183
-        return $ret;
184
-    }
185
-    private static function internationalOriginData()
186
-    {
93
+	public static function province()
94
+	{
95
+		$ret = self::provinceData();
96
+		self::$return = $ret;
97
+
98
+		return new static();
99
+	} 
100
+
101
+	public static function subDistrict()
102
+	{
103
+		$ret = self::subDistrictData();
104
+		self::$return = $ret;
105
+
106
+		return new static();
107
+	}
108
+	public static function internationalOrigin()
109
+	{
110
+		$ret = self::internationalOriginData();
111
+		self::$return = $ret;
112
+
113
+		return new static();
114
+	}
115
+
116
+	public static function city()
117
+	{
118
+		$ret = self::cityData();
119
+		self::$return = $ret;
120
+
121
+		return new static();
122
+	}
123
+
124
+	private static function setupConfig()
125
+	{
126
+		self::$cacheType = strtolower(config('irfa.rajaongkir.cache_type'));
127
+		self::$province = config('irfa.rajaongkir.province_table');
128
+		self::$city = config('irfa.rajaongkir.city_table');
129
+	}
130
+
131
+	private static function provinceData()
132
+	{
133
+		if (function_exists('config') && function_exists('app')) {
134
+			self::setupConfig();
135
+			$cache_type = self::$cacheType;
136
+			if ($cache_type == 'database') {
137
+				if (ROCache::checkProv()) {
138
+					if (count(ROCache::getProv(self::$arr)) > 0) {
139
+						$ret = ROCache::getProv(self::$arr);
140
+					} else {
141
+						$ret = self::get_province(self::$arr);
142
+					}
143
+				}
144
+			} elseif ($cache_type == 'file') {
145
+				$ret = ROCache::cacheFile(self::$province, self::$arr);
146
+				if ($ret == null) {
147
+					self::exceptionCache();
148
+				}
149
+			} else {
150
+				$ret = self::get_province(self::$arr);
151
+			}
152
+		} else {
153
+			$ret = self::get_province(self::$arr);
154
+		}
155
+
156
+		return $ret;
157
+	}
158
+	private static function subDistrictData()
159
+	{
160
+		if (function_exists('config') && function_exists('app')) {
161
+			self::setupConfig();
162
+			$cache_type = self::$cacheType;
163
+			if ($cache_type == 'database') {
164
+				if (ROCache::checkProv()) {
165
+					if (count(ROCache::getSubdistrict(self::$arr)) > 0) {
166
+						$ret = ROCache::getSubdistrict(self::$arr);
167
+					} else {
168
+						$ret = self::getSubdistrict(self::$arr);
169
+					}
170
+				}
171
+			} elseif ($cache_type == 'file') {
172
+				$ret = ROCache::cacheFile(self::$province, self::$arr);
173
+				if ($ret == null) {
174
+					self::exceptionCache();
175
+				}
176
+			} else {
177
+				$ret = self::getSubdistrict(self::$arr);
178
+			}
179
+		} else {
180
+			$ret = self::getSubdistrict(self::$arr);
181
+		}
182
+
183
+		return $ret;
184
+	}
185
+	private static function internationalOriginData()
186
+	{
187 187
         
188
-            $ret = self::get_international_origin(self::$arr);
188
+			$ret = self::get_international_origin(self::$arr);
189 189
      
190 190
 
191
-        return $ret;
192
-    }
193
-    private static function cityData()
194
-    {
195
-        if (function_exists('config') && function_exists('app')) {
196
-            self::setupConfig();
197
-            $cache_type = self::$cacheType;
198
-            if ($cache_type == 'database') {
199
-                if (ROCache::checkCity()) {
200
-                    if (count(ROCache::getCity(self::$arr)) > 0) {
201
-                        $ret = ROCache::getCity(self::$arr);
202
-                    } else {
203
-                        $ret = self::get_city(self::$arr);
204
-                    }
205
-                }
206
-            } elseif ($cache_type == 'file') {
207
-                $ret = ROCache::cacheFile(self::$city, self::$arr);
208
-                if ($ret == null) {
209
-                    self::exceptionCache();
210
-                }
211
-            } else {
212
-                $ret = self::get_city(self::$arr);
213
-            }
214
-        } else {
215
-            $ret = self::get_city(self::$arr);
216
-        }
217
-
218
-        return $ret;
219
-    }
220
-
221
-    private static function exceptionCache()
222
-    {
223
-        throw new Exception('Cache file is empty. Try php artisan raja-ongkir:cache');
224
-
225
-        return false;
226
-    }
191
+		return $ret;
192
+	}
193
+	private static function cityData()
194
+	{
195
+		if (function_exists('config') && function_exists('app')) {
196
+			self::setupConfig();
197
+			$cache_type = self::$cacheType;
198
+			if ($cache_type == 'database') {
199
+				if (ROCache::checkCity()) {
200
+					if (count(ROCache::getCity(self::$arr)) > 0) {
201
+						$ret = ROCache::getCity(self::$arr);
202
+					} else {
203
+						$ret = self::get_city(self::$arr);
204
+					}
205
+				}
206
+			} elseif ($cache_type == 'file') {
207
+				$ret = ROCache::cacheFile(self::$city, self::$arr);
208
+				if ($ret == null) {
209
+					self::exceptionCache();
210
+				}
211
+			} else {
212
+				$ret = self::get_city(self::$arr);
213
+			}
214
+		} else {
215
+			$ret = self::get_city(self::$arr);
216
+		}
217
+
218
+		return $ret;
219
+	}
220
+
221
+	private static function exceptionCache()
222
+	{
223
+		throw new Exception('Cache file is empty. Try php artisan raja-ongkir:cache');
224
+
225
+		return false;
226
+	}
227 227
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,9 +54,9 @@
 block discarded – undo
54 54
     {
55 55
         $get = self::cityData();
56 56
         $count = count($get);
57
-        $i=0;
57
+        $i = 0;
58 58
         echo PHP_EOL."\033[42mThis may take longer, please wait.\033[0m";
59
-        foreach($get as $city){
59
+        foreach ($get as $city) {
60 60
             $i++;
61 61
              echo PHP_EOL."Remaining City\033[96m ".$i."/".$count."\033[0m";
62 62
              echo PHP_EOL."Get Subdistrict\033[96m ".$city->city_name."...\033[0m".PHP_EOL;
Please login to merge, or discard this patch.
resources/config/irfa/rajaongkir.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 return [
4
-    /*
4
+	/*
5 5
     |--------------------------------------------------------------------------
6 6
     | End Point Api ( Server Configuration )
7 7
     |--------------------------------------------------------------------------
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
     | Pro       : http://pro.rajaongkir.com/api
12 12
     |
13 13
     */
14
-    'account_type' => env('RAJAONGKIR_ACCOUNT_TYPE', 'starter'),
15
-    /*
14
+	'account_type' => env('RAJAONGKIR_ACCOUNT_TYPE', 'starter'),
15
+	/*
16 16
     |--------------------------------------------------------------------------
17 17
     | API key
18 18
     |--------------------------------------------------------------------------
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
     |
21 21
     */
22 22
 
23
-    'api_key' => env('RAJAONGKIR_API_KEY', 'your-api-key'),
24
-    /*
23
+	'api_key' => env('RAJAONGKIR_API_KEY', 'your-api-key'),
24
+	/*
25 25
     |--------------------------------------------------------------------------
26 26
     | API Version (for account type basic and pro)
27 27
     |--------------------------------------------------------------------------
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
     |
30 30
     */
31 31
 
32
-    'api_version' => env('RAJAONGKIR_API_VERSION', 'v2'),
33
-    /*
32
+	'api_version' => env('RAJAONGKIR_API_VERSION', 'v2'),
33
+	/*
34 34
     |--------------------------------------------------------------------------
35 35
     | For Caching
36 36
     |--------------------------------------------------------------------------
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
     | Cache supported database,and file. If you can't use cache, set value to null
43 43
     */
44 44
     
45
-    'province_table' => env('RAJAONGKIR_PROV_TABLE', 'ro_province'),
45
+	'province_table' => env('RAJAONGKIR_PROV_TABLE', 'ro_province'),
46 46
 
47
-    'city_table' => env('RAJAONGKIR_CITY_TABLE', 'ro_city'),
47
+	'city_table' => env('RAJAONGKIR_CITY_TABLE', 'ro_city'),
48 48
 
49
-    'subdistrict_table' => env('RAJAONGKIR_SUBDISTRICT_TABLE', 'ro_subdistrict'),
49
+	'subdistrict_table' => env('RAJAONGKIR_SUBDISTRICT_TABLE', 'ro_subdistrict'),
50 50
 
51
-    'cache_type' => env('RAJAONGKIR_CACHE', 'database'),
51
+	'cache_type' => env('RAJAONGKIR_CACHE', 'database'),
52 52
 
53 53
 ];
Please login to merge, or discard this patch.