Use ::class syntax to fetch class name instead of get_class() function (#3910)

This commit is contained in:
Ngô Quốc Đạt 2023-10-29 20:43:58 +07:00 committed by GitHub
parent 2950290ad1
commit 015529ff1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 37 additions and 37 deletions

View File

@ -24,7 +24,7 @@ class FlagSerializer extends AbstractSerializer
{
if (! ($model instanceof Flag)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.Flag::class
$this::class.' can only serialize instances of '.Flag::class
);
}

View File

@ -24,7 +24,7 @@ class TaskSerializer extends AbstractSerializer
{
if (! ($model instanceof Task)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.Task::class
$this::class.' can only serialize instances of '.Task::class
);
}

View File

@ -29,7 +29,7 @@ class TagSerializer extends AbstractSerializer
{
if (! ($model instanceof Tag)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.Tag::class
$this::class.' can only serialize instances of '.Tag::class
);
}

View File

@ -27,7 +27,7 @@ class AccessTokenSerializer extends AbstractSerializer
{
if (! ($model instanceof AccessToken)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.AccessToken::class
$this::class.' can only serialize instances of '.AccessToken::class
);
}

View File

@ -30,7 +30,7 @@ class BasicDiscussionSerializer extends AbstractSerializer
{
if (! ($model instanceof Discussion)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.Discussion::class
$this::class.' can only serialize instances of '.Discussion::class
);
}

View File

@ -34,7 +34,7 @@ class BasicPostSerializer extends AbstractSerializer
{
if (! ($model instanceof Post)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.Post::class
$this::class.' can only serialize instances of '.Post::class
);
}

View File

@ -30,7 +30,7 @@ class BasicUserSerializer extends AbstractSerializer
{
if (! ($model instanceof User)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.User::class
$this::class.' can only serialize instances of '.User::class
);
}

View File

@ -18,7 +18,7 @@ class CurrentUserSerializer extends UserSerializer
{
if (! ($model instanceof User)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.User::class
$this::class.' can only serialize instances of '.User::class
);
}

View File

@ -29,7 +29,7 @@ class GroupSerializer extends AbstractSerializer
{
if (! ($model instanceof Group)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.Group::class
$this::class.' can only serialize instances of '.Group::class
);
}

View File

@ -30,7 +30,7 @@ class NotificationSerializer extends AbstractSerializer
{
if (! ($model instanceof Notification)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.Notification::class
$this::class.' can only serialize instances of '.Notification::class
);
}

View File

@ -15,7 +15,7 @@ class Dispatcher extends BaseDispatcher
{
public function getCommandHandler($command)
{
$handler = get_class($command).'Handler';
$handler = $command::class.'Handler';
if (class_exists($handler)) {
return $this->container->make($handler);

View File

@ -20,7 +20,7 @@ class ExtensionBootError extends Exception
public object $extender,
Throwable $previous = null
) {
$extenderClass = get_class($extender);
$extenderClass = $extender::class;
parent::__construct("Experienced an error while booting extension: {$extension->getTitle()}.\n\nError occurred while applying an extender of type: $extenderClass.", 0, $previous);
}

View File

@ -115,7 +115,7 @@ class Application extends IlluminateContainer implements LaravelApplication
public function getProvider(string|ServiceProvider $provider): ?ServiceProvider
{
$name = is_string($provider) ? $provider : get_class($provider);
$name = is_string($provider) ? $provider : $provider::class;
return Arr::first($this->serviceProviders, function ($key, $value) use ($name) {
return $value instanceof $name;
@ -134,7 +134,7 @@ class Application extends IlluminateContainer implements LaravelApplication
protected function markAsRegistered(ServiceProvider $provider): void
{
$this['events']->dispatch($class = get_class($provider), [$provider]);
$this['events']->dispatch($class = $provider::class, [$provider]);
$this->serviceProviders[] = $provider;

View File

@ -57,7 +57,7 @@ class ApplicationInfoProvider
public function identifyQueueDriver(): string
{
// Get class name
$queue = get_class($this->queue);
$queue = $this->queue::class;
// Drop the namespace
$queue = Str::afterLast($queue, '\\');
// Lowercase the class name
@ -103,7 +103,7 @@ class ApplicationInfoProvider
* And compare that to the current configured driver.
*/
// Get class name
$handlerName = get_class($this->sessionHandler);
$handlerName = $this->sessionHandler::class;
// Drop the namespace
$handlerName = Str::afterLast($handlerName, '\\');
// Lowercase the class name

View File

@ -184,7 +184,7 @@ trait InteractsWithLaravel
public function getProviders($provider): array
{
$name = is_string($provider) ? $provider : get_class($provider);
$name = is_string($provider) ? $provider : $provider::class;
return Arr::where($this->serviceProviders, fn ($value) => $value instanceof $name);
}

View File

@ -54,7 +54,7 @@ class Registry
if ($error instanceof KnownError) {
$errorType = $error->getType();
} else {
$errorClass = get_class($error);
$errorClass = $error::class;
if (isset($this->classMap[$errorClass])) {
$errorType = $this->classMap[$errorClass];
}
@ -73,7 +73,7 @@ class Registry
private function handleCustomTypes(Throwable $error): ?HandledError
{
$errorClass = get_class($error);
$errorClass = $error::class;
if (isset($this->handlerMap[$errorClass])) {
$handler = new $this->handlerMap[$errorClass];

View File

@ -77,7 +77,7 @@ class SourceCollector
if (! empty($this->allowedSourceTypes) && ! $isInstanceOfOneOfTheAllowedSourceTypes) {
throw new \InvalidArgumentException(sprintf(
'Source type %s is not allowed for this collector. Allowed types are: %s',
get_class($source),
$source::class,
implode(', ', $this->allowedSourceTypes)
));
}

View File

@ -89,7 +89,7 @@ class Server
$message = $error->getMessage();
$file = $error->getFile();
$line = $error->getLine();
$type = get_class($error);
$type = $error::class;
echo <<<ERROR
Flarum encountered a boot error ($type)<br />

View File

@ -137,7 +137,7 @@ class Notification extends AbstractModel
*/
public function scopeWhereSubject(Builder $query, AbstractModel $model): Builder
{
return $query->whereSubjectModel(get_class($model))
return $query->whereSubjectModel($model::class)
->where('subject_id', $model->getAttribute('id'));
}

View File

@ -60,7 +60,7 @@ class GambitManager
foreach ($this->gambits as $gambit) {
if (! $gambit instanceof GambitInterface) {
throw new LogicException(
'Gambit '.get_class($gambit).' does not implement '.GambitInterface::class
'Gambit '.$gambit::class.' does not implement '.GambitInterface::class
);
}

View File

@ -50,7 +50,7 @@ class Gate
$appliedPolicies = [];
if ($model) {
$modelClasses = is_string($model) ? [$model] : array_merge(class_parents($model), [get_class($model)]);
$modelClasses = is_string($model) ? [$model] : array_merge(class_parents($model), [$model::class]);
foreach ($modelClasses as $class) {
$appliedPolicies = array_merge($appliedPolicies, $this->getPolicies($class));

View File

@ -51,7 +51,7 @@ class FilesystemTest extends TestCase
/** @var FilesystemAdapter $uploadsDisk */
$uploadsDisk = $this->app()->getContainer()->make('filesystem')->disk('flarum-uploads');
$this->assertEquals(get_class($uploadsDisk->getAdapter()), LocalFilesystemAdapter::class);
$this->assertEquals($uploadsDisk->getAdapter()::class, LocalFilesystemAdapter::class);
}
/**
@ -64,7 +64,7 @@ class FilesystemTest extends TestCase
/** @var FilesystemAdapter $uploadsDisk */
$uploadsDisk = $this->app()->getContainer()->make('filesystem')->disk('flarum-uploads');
$this->assertEquals(get_class($uploadsDisk->getAdapter()), LocalFilesystemAdapter::class);
$this->assertEquals($uploadsDisk->getAdapter()::class, LocalFilesystemAdapter::class);
}
/**
@ -77,7 +77,7 @@ class FilesystemTest extends TestCase
/** @var FilesystemAdapter $assetsDisk */
$assetsDisk = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets');
$this->assertEquals(get_class($assetsDisk->getAdapter()), LocalFilesystemAdapter::class);
$this->assertEquals($assetsDisk->getAdapter()::class, LocalFilesystemAdapter::class);
}
/**
@ -90,7 +90,7 @@ class FilesystemTest extends TestCase
/** @var FilesystemAdapter $assetsDisk */
$assetsDisk = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets');
$this->assertEquals(get_class($assetsDisk->getAdapter()), LocalFilesystemAdapter::class);
$this->assertEquals($assetsDisk->getAdapter()::class, LocalFilesystemAdapter::class);
}
/**
@ -107,7 +107,7 @@ class FilesystemTest extends TestCase
/** @var FilesystemAdapter $assetsDisk */
$assetsDisk = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets');
$this->assertEquals(get_class($assetsDisk->getAdapter()), InMemoryFilesystemAdapter::class);
$this->assertEquals($assetsDisk->getAdapter()::class, InMemoryFilesystemAdapter::class);
}
/**
@ -124,7 +124,7 @@ class FilesystemTest extends TestCase
/** @var FilesystemAdapter $assetsDisk */
$assetsDisk = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets');
$this->assertEquals(get_class($assetsDisk->getAdapter()), InMemoryFilesystemAdapter::class);
$this->assertEquals($assetsDisk->getAdapter()::class, InMemoryFilesystemAdapter::class);
}
}

View File

@ -51,7 +51,7 @@ class SessionTest extends TestCase
$driver = $this->app()->getContainer()->make('session')->driver('flarum-acme');
$this->assertEquals(NullSessionHandler::class, get_class($driver->getHandler()));
$this->assertEquals(NullSessionHandler::class, $driver->getHandler()::class);
}
/**
@ -63,7 +63,7 @@ class SessionTest extends TestCase
$driver = $this->app()->getContainer()->make('session')->driver('redis');
$this->assertEquals(NullSessionHandler::class, get_class($driver->getHandler()));
$this->assertEquals(NullSessionHandler::class, $driver->getHandler()::class);
}
/**
@ -75,7 +75,7 @@ class SessionTest extends TestCase
$handler = $this->app()->getContainer()->make('session.handler');
$this->assertEquals(FileSessionHandler::class, get_class($handler));
$this->assertEquals(FileSessionHandler::class, $handler::class);
}
/**
@ -87,7 +87,7 @@ class SessionTest extends TestCase
$handler = $this->app()->getContainer()->make('session.handler');
$this->assertEquals(FileSessionHandler::class, get_class($handler));
$this->assertEquals(FileSessionHandler::class, $handler::class);
}
/**
@ -103,7 +103,7 @@ class SessionTest extends TestCase
$handler = $this->app()->getContainer()->make('session.handler');
$this->assertEquals(NullSessionHandler::class, get_class($handler));
$this->assertEquals(NullSessionHandler::class, $handler::class);
}
}

View File

@ -38,7 +38,7 @@ class Extender
foreach ($this->constructorArguments as $index => $constructorArgument) {
$string = null;
switch (get_class($constructorArgument)) {
switch ($constructorArgument::class) {
case Expr\ClassConstFetch::class:
$string = $constructorArgument->class->toString();
break;

View File

@ -147,7 +147,7 @@ class Resolver
$methodStack = array_reverse($methodStack);
if (! $value->var instanceof New_) {
throw new \Exception('Unable to resolve extender for '.get_class($value->var));
throw new \Exception('Unable to resolve extender for '.$value->var::class);
}
return $this->resolveExtenderNew($value->var, $methodStack);