Skip to content

Commit ad17640

Browse files
committed
refactor(serviceprovider): Refactor alias method
- Remove unused parameter - Update method signature - Update alias generation logic
1 parent 1c687cf commit ad17640

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/ExceptionNotifyServiceProvider.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Guanguans\LaravelExceptionNotify;
1414

1515
use Guanguans\LaravelExceptionNotify\Commands\TestCommand;
16+
use Guanguans\LaravelExceptionNotify\Facades\ExceptionNotify;
1617
use Guanguans\LaravelExceptionNotify\Macros\CollectionMacro;
1718
use Guanguans\LaravelExceptionNotify\Macros\RequestMacro;
1819
use Guanguans\LaravelExceptionNotify\Macros\StringableMacro;
@@ -135,9 +136,7 @@ protected function registerCollectorManager(): self
135136
protected function registerTestCommand(): self
136137
{
137138
$this->app->singleton(TestCommand::class);
138-
139139
$this->alias(TestCommand::class);
140-
$this->app->alias(TestCommand::class, 'command.exception-notify.test');
141140

142141
return $this;
143142
}
@@ -171,23 +170,24 @@ protected function registerCommands(): self
171170
/**
172171
* @param class-string $class
173172
*/
174-
protected function alias(string $class, ?string $prefix = null): void
173+
protected function alias(string $class): self
175174
{
176-
$this->app->alias($class, $this->toAlias($class, $prefix));
175+
$this->app->alias($class, $this->toAlias($class));
176+
177+
return $this;
177178
}
178179

179180
/**
180181
* @param class-string $class
181182
*/
182-
protected function toAlias(string $class, ?string $prefix = null): string
183+
protected function toAlias(string $class): string
183184
{
184-
$prefix ??= 'exception.notify.';
185-
186-
$alias = Str::snake(class_basename($class), '.');
187-
if (Str::startsWith($alias, Str::replaceLast('.', '', $prefix))) {
188-
return $alias;
189-
}
190-
191-
return $prefix.$alias;
185+
return str($class)
186+
->replaceFirst(__NAMESPACE__, '')
187+
->start('\\'.class_basename(ExceptionNotify::class))
188+
->ltrim('\\')
189+
->explode('\\')
190+
->map(static fn (string $name): string => Str::snake($name, '-'))
191+
->implode('.');
192192
}
193193
}

0 commit comments

Comments
 (0)