Skip to content

Commit

Permalink
Update Make.php
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar authored Sep 8, 2024
1 parent 08b47fe commit 4bc837e
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/Processors/Make.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DragonCode\Support\Facades\Filesystem\File;
use DragonCode\Support\Facades\Filesystem\Path;
use DragonCode\Support\Facades\Helpers\Str;
use DragonCode\Support\Helpers\Ables\Stringable;

use function base_path;
use function date;
Expand All @@ -21,14 +22,26 @@ class Make extends Processor

public function handle(): void
{
$pathWithName = $this->getPath().$this->getName();
$this->notification->task($this->message(), fn () => $this->create());
}

$this->notification->task('Creating an operation ['.$pathWithName.']', fn () => $this->create($pathWithName));
protected function message(): string
{
return 'Operation [' . $this->displayName($this->getFullPath()) . '] created successfully';
}

protected function create(string $path): void
protected function create(): void
{
File::copy($this->stubPath(), $path);
File::copy($this->stubPath(), $this->getFullPath());
}

protected function displayName(string $path): string
{
return Str::of($path)
->when(! $this->showFullPath(), fn (Stringable $str) => $str->after(base_path()))
->replace('\\', '/')
->ltrim('./')
->toString();
}

protected function getName(): string
Expand All @@ -43,6 +56,11 @@ protected function getPath(): string
return $this->options->path;
}

protected function getFullPath(): string
{
return $this->getPath() . $this->getName();
}

protected function getFilename(string $branch): string
{
$directory = Path::dirname($branch);
Expand All @@ -53,6 +71,7 @@ protected function getFilename(string $branch): string
->prepend($this->getTime())
->finish('.php')
->prepend($directory . '/')
->replace('\\', '/')
->ltrim('./')
->toString();
}
Expand Down Expand Up @@ -95,4 +114,9 @@ protected function stubPath(): string

return $this->defaultStub;
}

protected function showFullPath(): bool
{
return $this->config->showFullPath();
}
}

0 comments on commit 4bc837e

Please sign in to comment.