Skip to content

Commit

Permalink
ServiceGenerator updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorsone committed Oct 31, 2022
1 parent 4d24f2c commit c147b60
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/ServiceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
use Symfony\Component\Console\Command\Command as CommandAlias;

class ServiceGenerator extends GeneratorCommand
{

const SUCCESS = 0;
const FAILURE = 1;

private bool $isConstructFound = false;

private string $controllerNamespace = "App/Http/Controllers";
Expand Down Expand Up @@ -61,19 +63,18 @@ public function generateService(): int
if (!$controllerIsNotCreated) {
$controller = $this->getControllerFile();
$controller = $this->ifConstructExist($controller);
if (is_int($controller))
{
if (is_int($controller)) {
return $controller;
}
$controller = $this->ifConstructEmpty($controller);
file_put_contents($this->getControllerPath(), $controller);
$this->components->info("Service linked in " . $this->getControllerName());
} else {
return CommandAlias::FAILURE;
return self::FAILURE;
}


return CommandAlias::SUCCESS;
return self::SUCCESS;
}

public function ifConstructEmpty(array $file): array
Expand Down Expand Up @@ -120,7 +121,7 @@ private function ifConstructExist(array $file): int|array
} else {
if (str_contains(implode("", $file), $this->getServiceNamespace())) {
$this->components->warn("Service already linked in " . $this->getControllerName());
return CommandAlias::SUCCESS;
return self::SUCCESS;
}
$code = preg_replace(
"/\)/",
Expand All @@ -147,12 +148,10 @@ private function generateController(): bool
if ($isResponseStatusTrue) {
Artisan::call("make:controller " . $this->getControllerName());
$this->components->info("Created " . $this->getControllerName());
} else {
return CommandAlias::SUCCESS;
}
}

return CommandAlias::SUCCESS;
return self::SUCCESS;
}


Expand Down

0 comments on commit c147b60

Please sign in to comment.