Skip to content

Commit c147b60

Browse files
committed
ServiceGenerator updated
1 parent 4d24f2c commit c147b60

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/ServiceGenerator.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
use Illuminate\Console\GeneratorCommand;
66
use Illuminate\Support\Facades\Artisan;
77
use Illuminate\Support\Str;
8-
use Symfony\Component\Console\Command\Command as CommandAlias;
98

109
class ServiceGenerator extends GeneratorCommand
1110
{
1211

12+
const SUCCESS = 0;
13+
const FAILURE = 1;
14+
1315
private bool $isConstructFound = false;
1416

1517
private string $controllerNamespace = "App/Http/Controllers";
@@ -61,19 +63,18 @@ public function generateService(): int
6163
if (!$controllerIsNotCreated) {
6264
$controller = $this->getControllerFile();
6365
$controller = $this->ifConstructExist($controller);
64-
if (is_int($controller))
65-
{
66+
if (is_int($controller)) {
6667
return $controller;
6768
}
6869
$controller = $this->ifConstructEmpty($controller);
6970
file_put_contents($this->getControllerPath(), $controller);
7071
$this->components->info("Service linked in " . $this->getControllerName());
7172
} else {
72-
return CommandAlias::FAILURE;
73+
return self::FAILURE;
7374
}
7475

7576

76-
return CommandAlias::SUCCESS;
77+
return self::SUCCESS;
7778
}
7879

7980
public function ifConstructEmpty(array $file): array
@@ -120,7 +121,7 @@ private function ifConstructExist(array $file): int|array
120121
} else {
121122
if (str_contains(implode("", $file), $this->getServiceNamespace())) {
122123
$this->components->warn("Service already linked in " . $this->getControllerName());
123-
return CommandAlias::SUCCESS;
124+
return self::SUCCESS;
124125
}
125126
$code = preg_replace(
126127
"/\)/",
@@ -147,12 +148,10 @@ private function generateController(): bool
147148
if ($isResponseStatusTrue) {
148149
Artisan::call("make:controller " . $this->getControllerName());
149150
$this->components->info("Created " . $this->getControllerName());
150-
} else {
151-
return CommandAlias::SUCCESS;
152151
}
153152
}
154153

155-
return CommandAlias::SUCCESS;
154+
return self::SUCCESS;
156155
}
157156

158157

0 commit comments

Comments
 (0)