Skip to content

Commit

Permalink
Use ::class syntax to fetch class name instead of get_class() fun…
Browse files Browse the repository at this point in the history
…ction (#3910)
  • Loading branch information
datlechin authored Oct 29, 2023
1 parent 2950290 commit 015529f
Show file tree
Hide file tree
Showing 25 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion extensions/flags/src/Api/Serializer/FlagSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/tags/src/Api/Serializer/TagSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Api/Serializer/BasicPostSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Api/Serializer/BasicUserSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Api/Serializer/GroupSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function getDefaultAttributes(object|array $model): array
{
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
);
}

Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Bus/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
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);
}
Expand Down
4 changes: 2 additions & 2 deletions framework/core/src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function register($provider, $force = false): ServiceProvider

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;
Expand All @@ -134,7 +134,7 @@ public function resolveProvider($provider): ServiceProvider

protected function markAsRegistered(ServiceProvider $provider): void
{
$this['events']->dispatch($class = get_class($provider), [$provider]);
$this['events']->dispatch($class = $provider::class, [$provider]);

$this->serviceProviders[] = $provider;

Expand Down
4 changes: 2 additions & 2 deletions framework/core/src/Foundation/ApplicationInfoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getSchedulerStatus(): string
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
Expand Down Expand Up @@ -103,7 +103,7 @@ public function identifySessionDriver(bool $forWeb = false): string
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function getNamespace(): string

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);
}
Expand Down
4 changes: 2 additions & 2 deletions framework/core/src/Foundation/ErrorHandling/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function handleKnownTypes(Throwable $error): ?HandledError
if ($error instanceof KnownError) {
$errorType = $error->getType();
} else {
$errorClass = get_class($error);
$errorClass = $error::class;
if (isset($this->classMap[$errorClass])) {
$errorType = $this->classMap[$errorClass];
}
Expand All @@ -73,7 +73,7 @@ private function handleKnownTypes(Throwable $error): ?HandledError

private function handleCustomTypes(Throwable $error): ?HandledError
{
$errorClass = get_class($error);
$errorClass = $error::class;

if (isset($this->handlerMap[$errorClass])) {
$handler = new $this->handlerMap[$errorClass];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function validateSourceType(SourceInterface $source): SourceInterface
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)
));
}
Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Http/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function cleanBootExceptionLog(Throwable $error): void
$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 />
Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Notification/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function scopeWhereSubjectVisibleTo(Builder $query, User $actor): Builder
*/
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'));
}

Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Search/GambitManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function applyGambits(SearchState $search, string $query): string
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
);
}

Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/User/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function allows(User $actor, string $ability, string|AbstractModel|null $
$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));
Expand Down
12 changes: 6 additions & 6 deletions framework/core/tests/integration/extenders/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function custom_disk_exists_if_added_and_uses_local_adapter_by_default()
/** @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);
}

/**
Expand All @@ -64,7 +64,7 @@ public function custom_disk_exists_if_added_via_invokable_class_and_uses_local_a
/** @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);
}

/**
Expand All @@ -77,7 +77,7 @@ public function disk_uses_local_adapter_if_configured_adapter_unavailable()
/** @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);
}

/**
Expand All @@ -90,7 +90,7 @@ public function disk_uses_local_adapter_if_configured_adapter_from_config_file_u
/** @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);
}

/**
Expand All @@ -107,7 +107,7 @@ public function disk_uses_custom_adapter_if_configured_and_available()
/** @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);
}

/**
Expand All @@ -124,7 +124,7 @@ public function disk_uses_custom_adapter_from_config_file_if_configured_and_avai
/** @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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions framework/core/tests/integration/extenders/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function custom_driver_exists_if_added()

$driver = $this->app()->getContainer()->make('session')->driver('flarum-acme');

$this->assertEquals(NullSessionHandler::class, get_class($driver->getHandler()));
$this->assertEquals(NullSessionHandler::class, $driver->getHandler()::class);
}

/**
Expand All @@ -63,7 +63,7 @@ public function custom_driver_overrides_laravel_defined_drivers_if_added()

$driver = $this->app()->getContainer()->make('session')->driver('redis');

$this->assertEquals(NullSessionHandler::class, get_class($driver->getHandler()));
$this->assertEquals(NullSessionHandler::class, $driver->getHandler()::class);
}

/**
Expand All @@ -75,7 +75,7 @@ public function uses_default_driver_if_driver_from_config_file_not_configured()

$handler = $this->app()->getContainer()->make('session.handler');

$this->assertEquals(FileSessionHandler::class, get_class($handler));
$this->assertEquals(FileSessionHandler::class, $handler::class);
}

/**
Expand All @@ -87,7 +87,7 @@ public function uses_default_driver_if_configured_driver_from_config_file_unavai

$handler = $this->app()->getContainer()->make('session.handler');

$this->assertEquals(FileSessionHandler::class, get_class($handler));
$this->assertEquals(FileSessionHandler::class, $handler::class);
}

/**
Expand All @@ -103,7 +103,7 @@ public function uses_custom_driver_from_config_file_if_configured_and_available(

$handler = $this->app()->getContainer()->make('session.handler');

$this->assertEquals(NullSessionHandler::class, get_class($handler));
$this->assertEquals(NullSessionHandler::class, $handler::class);
}
}

Expand Down
2 changes: 1 addition & 1 deletion php-packages/phpstan/src/Extender/Extender.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function extends(...$args): bool
foreach ($this->constructorArguments as $index => $constructorArgument) {
$string = null;

switch (get_class($constructorArgument)) {
switch ($constructorArgument::class) {
case Expr\ClassConstFetch::class:
$string = $constructorArgument->class->toString();
break;
Expand Down
2 changes: 1 addition & 1 deletion php-packages/phpstan/src/Extender/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function resolveExtender(MethodCall $value): Extender
$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);
Expand Down

0 comments on commit 015529f

Please sign in to comment.