Skip to content

Commit 4c16656

Browse files
committed
fix overwrite file service and repository
1 parent f00826d commit 4c16656

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/Commands/MakeRepository.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public function createRepositoryInterface(string $className)
8282
];
8383

8484
$repositoryInterfacePath = $this->getRepositoryInterfacePath($className);
85+
if (file_exists($repositoryInterfacePath)) {
86+
$this->line("<warning>file $className repository interface already exist:</warning> {$repositoryInterfaceName}");
87+
return ;
88+
}
8589

8690
new CreateFile(
8791
$stubProperties,
@@ -114,6 +118,10 @@ public function createRepository(string $className, $isDefault = true)
114118

115119
$stubName = $isDefault ? "eloquent-repository.stub" : "custom-repository.stub";
116120
$repositoryPath = $this->getRepositoryPath($className, $isDefault);
121+
if (file_exists($repositoryPath)) {
122+
$this->line("<warning>file $className repository already exist:</warning> {$repositoryName}");
123+
return ;
124+
}
117125
new CreateFile(
118126
$stubProperties,
119127
$repositoryPath,
@@ -170,6 +178,5 @@ private function checkIfRequiredDirectoriesExist(string $className)
170178
{
171179
$this->ensureDirectoryExists(config("easy-repository.repository_directory"));
172180
$this->ensureDirectoryExists(config("easy-repository.repository_directory") . "/". $className);
173-
$this->ensureDirectoryExists(config("easy-repository.repository_directory") . "/" . $className);
174181
}
175182
}

src/Commands/MakeService.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function handle()
2424
$name = str_replace(config("easy-repository.service_interface_suffix"), "", $this->argument("name"));
2525
$className = Str::studly($name);
2626

27-
$this->checkIfRequiredDirectoriesExist();
27+
$this->checkIfRequiredDirectoriesExist($className);
2828

2929
$this->createServiceInterface($className);
3030

@@ -56,8 +56,9 @@ public function createService(string $className)
5656
];
5757
// check file exist
5858
$filePath = $this->getServicePath($className, $nameOfService);
59-
if (!file_exists($filePath)) {
60-
File::makeDirectory($filePath, 0775, true, true);
59+
if (file_exists($filePath)) {
60+
$this->line("<warning>file $className service already exist:</warning> {$serviceName}");
61+
return ;
6162
}
6263

6364
// check command blank
@@ -94,8 +95,9 @@ public function createServiceInterface(string $className)
9495
];
9596
// check folder exist
9697
$interfacePath = $this->getServiceInterfacePath($className,$serviceName);
97-
if (!file_exists($interfacePath)) {
98-
File::makeDirectory($interfacePath, 0775, true, true);
98+
if (file_exists($interfacePath)) {
99+
$this->line("<warning>file $className service interface already exist:</warning> {$serviceName}");
100+
return ;
99101
}
100102
// create file
101103
new CreateFile(
@@ -174,9 +176,10 @@ private function getRepositoryName(string $className) {
174176
*
175177
* @return void
176178
*/
177-
private function checkIfRequiredDirectoriesExist()
179+
private function checkIfRequiredDirectoriesExist(string $className)
178180
{
179181
$this->ensureDirectoryExists(config("easy-repository.service_directory"));
182+
$this->ensureDirectoryExists(config("easy-repository.service_directory"). "/". $className);
180183
}
181184

182185
/**

0 commit comments

Comments
 (0)