|
21 | 21 | use Dot\Maker\VisibilityEnum; |
22 | 22 | use Throwable; |
23 | 23 |
|
24 | | -use function array_shift; |
25 | | -use function count; |
26 | | -use function implode; |
27 | | -use function preg_replace; |
28 | | -use function preg_split; |
29 | 24 | use function sprintf; |
30 | | -use function strtolower; |
| 25 | +use function str_replace; |
31 | 26 | use function ucfirst; |
32 | 27 |
|
33 | 28 | class Command extends AbstractType implements FileInterface |
@@ -73,19 +68,16 @@ public function create(string $name): File |
73 | 68 | $this->fileSystem->serviceInterface($this->fileSystem->getModuleName())->getComponent(), |
74 | 69 | ); |
75 | 70 |
|
76 | | - try { |
77 | | - $command->create($content); |
78 | | - Output::info(sprintf('Created Command "%s"', $command->getPath())); |
79 | | - } catch (RuntimeException $exception) { |
80 | | - Output::error($exception->getMessage()); |
81 | | - } |
| 71 | + $command->create($content); |
| 72 | + |
| 73 | + Output::success(sprintf('Created Command "%s"', $command->getPath())); |
82 | 74 |
|
83 | 75 | return $command; |
84 | 76 | } |
85 | 77 |
|
86 | 78 | public function render(Component $command, Component $serviceInterface): string |
87 | 79 | { |
88 | | - $defaultName = $this->getDefaultName($command->getClassName()); |
| 80 | + $defaultName = $this->getDefaultName($command); |
89 | 81 |
|
90 | 82 | $class = (new ClassFile($command->getNamespace(), $command->getClassName())) |
91 | 83 | ->setExtends('Command') |
@@ -145,17 +137,10 @@ public function render(Component $command, Component $serviceInterface): string |
145 | 137 | return $class->render(); |
146 | 138 | } |
147 | 139 |
|
148 | | - public function getDefaultName(string $className): string |
| 140 | + public function getDefaultName(Component $command): string |
149 | 141 | { |
150 | | - $className = preg_replace('/Command$/', '', $className); |
151 | | - |
152 | | - $parts = preg_split('/(?<!^)(?=[A-Z])/', $className); |
153 | | - $module = array_shift($parts); |
154 | | - |
155 | | - if (count($parts) === 0) { |
156 | | - $parts[] = 'action'; |
157 | | - } |
| 142 | + $defaultName = sprintf('%s:command', $command->toKebabCase()); |
158 | 143 |
|
159 | | - return strtolower(sprintf('%s:%s', $module, implode('-', $parts))); |
| 144 | + return str_replace('-command', '', $defaultName); |
160 | 145 | } |
161 | 146 | } |
0 commit comments