22
33namespace Codenom \Midtrans \Commands ;
44
5- use Config \Autoload ;
6- use CodeIgniter \CLI \CLI ;
75use CodeIgniter \CLI \BaseCommand ;
6+ use CodeIgniter \CLI \CLI ;
7+ use Config \Autoload ;
88
99class MidtransCommand extends BaseCommand
1010{
@@ -14,12 +14,13 @@ class MidtransCommand extends BaseCommand
1414
1515 /**
1616 * Private or protected function
17- *
17+ *
1818 * @var string
1919 */
2020 protected $ sourcePath ;
2121
2222 //--------------------------------------------------------------------
23+
2324 /**
2425 * Copy config file
2526 *
@@ -37,26 +38,30 @@ public function run(array $params)
3738 */
3839 protected function determineSourcePath ()
3940 {
40- $ this ->sourcePath = realpath (__DIR__ . '/../ ' );
41+ $ this ->sourcePath = \ realpath (__DIR__ . '/../ ' );
4142 if ($ this ->sourcePath == '/ ' || empty ($ this ->sourcePath )) {
4243 CLI ::error ('Unable to determine the correct source directory. Bailing. ' );
4344 exit ();
4445 }
4546 }
47+
4648 //--------------------------------------------------------------------
49+
4750 /**
4851 * Publish config file.
4952 */
5053 protected function publishConfig ()
5154 {
5255 $ path = "{$ this ->sourcePath }/Config/Midtrans.php " ;
53- $ content = file_get_contents ($ path );
54- $ content = str_replace ('use CodeIgniter\Config\BaseConfig ' , "use Codenom\Midtrans\Config\Midtrans as MidtransConfig " , $ content );
55- $ content = str_replace ('namespace Codenom\Midtrans\Config ' , " namespace Config " , $ content );
56- $ content = str_replace ('extends BaseConfig ' , " extends MidtransConfig " , $ content );
56+ $ content = \ file_get_contents ($ path );
57+ $ content = \ str_replace ('use CodeIgniter\Config\BaseConfig ' , "use Codenom\Midtrans\Config\Midtrans as MidtransConfig " , $ content );
58+ $ content = \ str_replace ('namespace Codenom\Midtrans\Config ' , ' namespace Config ' , $ content );
59+ $ content = \ str_replace ('extends BaseConfig ' , ' extends MidtransConfig ' , $ content );
5760 $ this ->writeFile ('Config/Midtrans.php ' , $ content );
5861 }
62+
5963 //--------------------------------------------------------------------
64+
6065 /**
6166 * Write a file, catching any exceptions and showing a nicely formatted error.
6267 *
@@ -67,11 +72,11 @@ protected function writeFile(string $path, string $content)
6772 {
6873 $ config = new Autoload ();
6974 $ appPath = $ config ->psr4 [APP_NAMESPACE ];
70- $ directory = dirname ($ appPath . $ path );
71- if (!is_dir ($ directory )) {
72- mkdir ($ directory , 0777 , true );
75+ $ directory = \ dirname ($ appPath . $ path );
76+ if (!\ is_dir ($ directory )) {
77+ \ mkdir ($ directory , 0777 , true );
7378 }
74- if (file_exists ($ appPath . $ path ) && CLI ::prompt ('Config file already exists, do you want to replace it? ' , ['y ' , 'n ' ]) == 'n ' ) {
79+ if (\ file_exists ($ appPath . $ path ) && CLI ::prompt ('Config file already exists, do you want to replace it? ' , ['y ' , 'n ' ]) == 'n ' ) {
7580 CLI ::error ('Cancelled ' );
7681 exit ();
7782 }
@@ -81,8 +86,9 @@ protected function writeFile(string $path, string $content)
8186 $ this ->showError ($ e );
8287 exit ();
8388 }
84- $ path = str_replace ($ appPath , '' , $ path );
89+ $ path = \ str_replace ($ appPath , '' , $ path );
8590 CLI ::write (CLI ::color ('Created: ' , 'yellow ' ) . $ path );
8691 }
92+
8793 //--------------------------------------------------------------------
8894}
0 commit comments