From 107800dfcd0139bf38f556af6f839872dab5cda8 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Thu, 2 May 2024 10:21:42 +0200 Subject: [PATCH] Replace `get_class()` with `::class` --- src/Api/Api.php | 4 ++-- src/Api/Model.php | 2 +- src/Cms/App.php | 2 +- src/Cms/AppErrors.php | 2 +- src/Option/OptionsQuery.php | 2 +- src/Parsley/Parsley.php | 2 +- src/Sane/Sane.php | 6 +++--- src/Uuid/Uuid.php | 2 +- tests/Database/QueryTest.php | 7 ++++--- tests/Image/Darkroom/GdLibTest.php | 4 ++-- tests/Image/Darkroom/ImageMagickTest.php | 4 ++-- 11 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Api/Api.php b/src/Api/Api.php index 13e2c7562b..3a67adce42 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -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)); } /** @@ -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(), diff --git a/src/Api/Model.php b/src/Api/Model.php index 24af00bbca..7e4071f287 100644 --- a/src/Api/Model.php +++ b/src/Api/Model.php @@ -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'])); } diff --git a/src/Cms/App.php b/src/Cms/App.php index 11a09367b8..5607bba389 100644 --- a/src/Cms/App.php +++ b/src/Cms/App.php @@ -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 ])); } diff --git a/src/Cms/AppErrors.php b/src/Cms/AppErrors.php index 7b2abc7ecb..e03e151412 100644 --- a/src/Cms/AppErrors.php +++ b/src/Cms/AppErrors.php @@ -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, diff --git a/src/Option/OptionsQuery.php b/src/Option/OptionsQuery.php index 77312c4ce5..e1d8e4d4bc 100644 --- a/src/Option/OptionsQuery.php +++ b/src/Option/OptionsQuery.php @@ -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); } diff --git a/src/Parsley/Parsley.php b/src/Parsley/Parsley.php index 3f2242e204..e06e70890f 100644 --- a/src/Parsley/Parsley.php +++ b/src/Parsley/Parsley.php @@ -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; } diff --git a/src/Sane/Sane.php b/src/Sane/Sane.php index c079e2af26..a793fd116b 100644 --- a/src/Sane/Sane.php +++ b/src/Sane/Sane.php @@ -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 @@ -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)) ); } } @@ -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 ( diff --git a/src/Uuid/Uuid.php b/src/Uuid/Uuid.php index 28ad6c433b..1157f3d331 100644 --- a/src/Uuid/Uuid.php +++ b/src/Uuid/Uuid.php @@ -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) }; } diff --git a/tests/Database/QueryTest.php b/tests/Database/QueryTest.php index 28e36f8e9a..209acdf7c5 100644 --- a/tests/Database/QueryTest.php +++ b/tests/Database/QueryTest.php @@ -5,6 +5,7 @@ use InvalidArgumentException; use Kirby\TestCase; use Kirby\Toolkit\Collection; +use Kirby\Toolkit\Pagination; use PDOException; /** @@ -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()); @@ -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()); @@ -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()); diff --git a/tests/Image/Darkroom/GdLibTest.php b/tests/Image/Darkroom/GdLibTest.php index 7e319b31d8..379fc13237 100644 --- a/tests/Image/Darkroom/GdLibTest.php +++ b/tests/Image/Darkroom/GdLibTest.php @@ -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(); @@ -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(); diff --git a/tests/Image/Darkroom/ImageMagickTest.php b/tests/Image/Darkroom/ImageMagickTest.php index 2b2718ad44..96b7768222 100644 --- a/tests/Image/Darkroom/ImageMagickTest.php +++ b/tests/Image/Darkroom/ImageMagickTest.php @@ -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, '', [ @@ -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, '', [