Skip to content

Commit 4bc837e

Browse files
Update Make.php
1 parent 08b47fe commit 4bc837e

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/Processors/Make.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DragonCode\Support\Facades\Filesystem\File;
88
use DragonCode\Support\Facades\Filesystem\Path;
99
use DragonCode\Support\Facades\Helpers\Str;
10+
use DragonCode\Support\Helpers\Ables\Stringable;
1011

1112
use function base_path;
1213
use function date;
@@ -21,14 +22,26 @@ class Make extends Processor
2122

2223
public function handle(): void
2324
{
24-
$pathWithName = $this->getPath().$this->getName();
25+
$this->notification->task($this->message(), fn () => $this->create());
26+
}
2527

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

29-
protected function create(string $path): void
33+
protected function create(): void
3034
{
31-
File::copy($this->stubPath(), $path);
35+
File::copy($this->stubPath(), $this->getFullPath());
36+
}
37+
38+
protected function displayName(string $path): string
39+
{
40+
return Str::of($path)
41+
->when(! $this->showFullPath(), fn (Stringable $str) => $str->after(base_path()))
42+
->replace('\\', '/')
43+
->ltrim('./')
44+
->toString();
3245
}
3346

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

59+
protected function getFullPath(): string
60+
{
61+
return $this->getPath() . $this->getName();
62+
}
63+
4664
protected function getFilename(string $branch): string
4765
{
4866
$directory = Path::dirname($branch);
@@ -53,6 +71,7 @@ protected function getFilename(string $branch): string
5371
->prepend($this->getTime())
5472
->finish('.php')
5573
->prepend($directory . '/')
74+
->replace('\\', '/')
5675
->ltrim('./')
5776
->toString();
5877
}
@@ -95,4 +114,9 @@ protected function stubPath(): string
95114

96115
return $this->defaultStub;
97116
}
117+
118+
protected function showFullPath(): bool
119+
{
120+
return $this->config->showFullPath();
121+
}
98122
}

0 commit comments

Comments
 (0)