Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace get_class() with ::class #6475

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public function resolve($object): Model|Collection
return $this->collection($collection, $object);
}

throw new NotFoundException(sprintf('The object "%s" cannot be resolved', get_class($object)));
throw new NotFoundException(sprintf('The object "%s" cannot be resolved', $object::class));
}

/**
Expand Down Expand Up @@ -542,7 +542,7 @@ public function responseForException(Throwable $e): array
'status' => 'error',
'message' => $e->getMessage(),
'code' => empty($e->getCode()) === true ? 500 : $e->getCode(),
'exception' => get_class($e),
'exception' => $e::class,
'key' => null,
'file' => F::relativepath($e->getFile(), $docRoot),
'line' => $e->getLine(),
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(
) {
$class = match ($this->data) {
null => 'null',
default => get_class($this->data),
default => $this->data::class,
};
throw new Exception(sprintf('Invalid model type "%s" expected: "%s"', $class, $schema['type']));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cms/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ public function io(mixed $input): Response
return $response->code($code)->send($errorPage->render([
'errorCode' => $code,
'errorMessage' => $message,
'errorType' => get_class($input)
'errorType' => $input::class
]));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cms/AppErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected function handleJsonErrors(): void
if ($this->option('debug') === true) {
echo Response::json([
'status' => 'error',
'exception' => get_class($exception),
'exception' => $exception::class,
'code' => $code,
'message' => $exception->getMessage(),
'details' => $details,
Expand Down
2 changes: 1 addition & 1 deletion src/Option/OptionsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function resolve(ModelWithContent $model, bool $safeMode = true): Options
}

if ($result instanceof Collection === false) {
$type = is_object($result) === true ? get_class($result) : gettype($result);
$type = is_object($result) === true ? $result::class : gettype($result);

throw new InvalidArgumentException('Invalid query result data: ' . $type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parsley/Parsley.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function parseNode(DOMNode $element): bool
$skip = ['DOMComment', 'DOMDocumentType'];

// unwanted element types
if (in_array(get_class($element), $skip) === true) {
if (in_array($element::class, $skip) === true) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Sane/Sane.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Kirby\Exception\LogicException;
use Kirby\Exception\NotFoundException;
use Kirby\Filesystem\F;
use Kirby\Toolkit\A;

/**
* The `Sane` class validates that files
Expand Down Expand Up @@ -123,10 +124,9 @@ public static function sanitizeFile(
default:
// more than one matching handler;
// sanitizing with all handlers will not leave much in the output
$handlerNames = array_map('get_class', $handlers);
throw new LogicException(
'Cannot sanitize file as more than one handler applies: ' .
implode(', ', $handlerNames)
implode(', ', A::map($handlers, fn ($handler) => $handler::class))
);
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ protected static function handlersForFile(

foreach ($options as $option) {
$handler = static::handler($option, $lazy);
$handlerClass = $handler ? get_class($handler) : null;
$handlerClass = $handler ? $handler::class : null;

// ensure that each handler class is only returned once
if (
Expand Down
2 changes: 1 addition & 1 deletion src/Uuid/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ final public static function for(
// $seed instanceof StructureObject
// => new StructureUuid(model: $seed, context: $context),
default
=> throw new InvalidArgumentException('UUID not supported for: ' . get_class($seed))
=> throw new InvalidArgumentException('UUID not supported for: ' . $seed::class)
};
}

Expand Down
7 changes: 4 additions & 3 deletions tests/Database/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use InvalidArgumentException;
use Kirby\TestCase;
use Kirby\Toolkit\Collection;
use Kirby\Toolkit\Pagination;
use PDOException;

/**
Expand Down Expand Up @@ -669,7 +670,7 @@ public function testPage()

$this->assertCount(5, $results);
$this->assertSame('John', $results->first()->fname());
$this->assertTrue(get_class($pagination) === 'Kirby\Toolkit\Pagination');
$this->assertTrue($pagination instanceof Pagination);
$this->assertSame(1, $pagination->pages());
$this->assertSame(5, $pagination->total());
$this->assertSame(1, $pagination->page());
Expand All @@ -683,7 +684,7 @@ public function testPage()

$this->assertCount(1, $results);
$this->assertSame('George', $results->first()->fname());
$this->assertTrue(get_class($pagination) === 'Kirby\Toolkit\Pagination');
$this->assertTrue($pagination instanceof Pagination);
$this->assertSame(5, $pagination->pages());
$this->assertSame(5, $pagination->total());
$this->assertSame(3, $pagination->page());
Expand All @@ -697,7 +698,7 @@ public function testPage()

$this->assertCount(2, $results);
$this->assertSame('Mark', $results->first()->fname());
$this->assertTrue(get_class($pagination) === 'Kirby\Toolkit\Pagination');
$this->assertTrue($pagination instanceof Pagination);
$this->assertSame(2, $pagination->pages());
$this->assertSame(5, $pagination->total());
$this->assertSame(2, $pagination->page());
Expand Down
4 changes: 2 additions & 2 deletions tests/Image/Darkroom/GdLibTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testSharpen()
{
$gd = new GdLib();

$method = new ReflectionMethod(get_class($gd), 'sharpen');
$method = new ReflectionMethod($gd::class, 'sharpen');
$method->setAccessible(true);

$simpleImage = new SimpleImageMock();
Expand All @@ -96,7 +96,7 @@ public function testSharpenWithoutValue()
{
$gd = new GdLib();

$method = new ReflectionMethod(get_class($gd), 'sharpen');
$method = new ReflectionMethod($gd::class, 'sharpen');
$method->setAccessible(true);

$simpleImage = new SimpleImageMock();
Expand Down
4 changes: 2 additions & 2 deletions tests/Image/Darkroom/ImageMagickTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testSharpen()
{
$im = new ImageMagick();

$method = new ReflectionMethod(get_class($im), 'sharpen');
$method = new ReflectionMethod($im::class, 'sharpen');
$method->setAccessible(true);

$result = $method->invoke($im, '', [
Expand All @@ -75,7 +75,7 @@ public function testSharpenWithoutValue()
{
$im = new ImageMagick();

$method = new ReflectionMethod(get_class($im), 'sharpen');
$method = new ReflectionMethod($im::class, 'sharpen');
$method->setAccessible(true);

$result = $method->invoke($im, '', [
Expand Down
Loading