Skip to content

Commit f87003b

Browse files
refactor(Command): modify and refactor BaseCommand
- convert BaseCommand class to abstract - remove unused namespace - improvement code style
1 parent cc9d8b6 commit f87003b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/Commands/BaseCommand.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
namespace Eghamat24\DatabaseRepository\Commands;
44

5-
use Illuminate\Container\Container;
65
use Illuminate\Support\Collection;
76
use Illuminate\Console\Command;
8-
use Eghamat24\DatabaseRepository\CustomMySqlQueries;
97
use Illuminate\Support\Str;
108

11-
class BaseCommand extends Command
9+
abstract class BaseCommand extends Command
1210
{
13-
// use CustomMySqlQueries;
1411
public string $selectedDb;
1512
public string $tableName;
1613
public string $detectForeignKeys;
@@ -74,7 +71,7 @@ public function setArguments()
7471
public function checkDelete(string $filenameWithPath, string $entityName, string $objectName): void
7572
{
7673
if (file_exists($filenameWithPath) && $this->option('delete')) {
77-
unlink($filenameWithPath);
74+
\unlink($filenameWithPath);
7875
$this->info("$objectName '$entityName' has been deleted.");
7976
}
8077
}
@@ -125,19 +122,25 @@ public function getChoice(): null|string
125122

126123
public function checkStrategyName()
127124
{
128-
$strategyNames = array("ClearableTemporaryCacheStrategy", "QueryCacheStrategy", "SingleKeyCacheStrategy", "TemporaryCacheStrategy");
125+
$strategyNames = [
126+
'ClearableTemporaryCacheStrategy',
127+
'QueryCacheStrategy',
128+
'SingleKeyCacheStrategy',
129+
'TemporaryCacheStrategy'
130+
];
131+
129132
if (!in_array($this->argument('strategy'), $strategyNames)) {
130-
$this->alert("This pattern strategy does not exist !!! ");
133+
$this->alert('This pattern strategy does not exist !!! ');
131134
exit;
132135
}
133136
}
134137

135138
public function checkDatabasesExist()
136139
{
137-
138140
$entityName = Str::singular(ucfirst(Str::camel($this->argument('table_name'))));
139-
$mysql = config('repository.path.relative.repositories') . DIRECTORY_SEPARATOR . $entityName . DIRECTORY_SEPARATOR . "MySql" . $entityName . "Repository.php";
140-
$redis = config('repository.path.relative.repositories') . DIRECTORY_SEPARATOR . $entityName . DIRECTORY_SEPARATOR . "Redis" . $entityName . "Repository.php";
141+
$mysql = config('repository.path.relative.repositories') . DIRECTORY_SEPARATOR . $entityName . DIRECTORY_SEPARATOR . 'MySql' . $entityName . 'Repository.php';
142+
$redis = config('repository.path.relative.repositories') . DIRECTORY_SEPARATOR . $entityName . DIRECTORY_SEPARATOR . 'Redis' . $entityName . 'Repository.php';
143+
141144
if (!(file_exists($mysql) && file_exists($redis))) {
142145
$this->alert("First create the class databases!!!");
143146
exit;

0 commit comments

Comments
 (0)