From ca73572e441f5cc7bab46df30cc734541623ba81 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Wed, 31 Jan 2024 16:56:12 +0100 Subject: [PATCH] Refactor get_class() to class constant --- src/Colors/AbstractColor.php | 2 +- src/Colors/Cmyk/Colorspace.php | 2 +- src/Colors/Hsl/Colorspace.php | 2 +- src/Colors/Hsv/Colorspace.php | 2 +- src/Colors/Rgb/Colorspace.php | 2 +- src/Drivers/AbstractDriver.php | 2 +- src/Drivers/AbstractInputHandler.php | 2 +- src/Drivers/Imagick/ColorProcessor.php | 2 +- src/Drivers/Imagick/Modifiers/ColorspaceModifier.php | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Colors/AbstractColor.php b/src/Colors/AbstractColor.php index 5faf773d..51e5f40f 100644 --- a/src/Colors/AbstractColor.php +++ b/src/Colors/AbstractColor.php @@ -24,7 +24,7 @@ abstract class AbstractColor implements ColorInterface public function channel(string $classname): ColorChannelInterface { $channels = array_filter($this->channels(), function (ColorChannelInterface $channel) use ($classname) { - return get_class($channel) == $classname; + return $channel::class == $classname; }); if (count($channels) == 0) { diff --git a/src/Colors/Cmyk/Colorspace.php b/src/Colors/Cmyk/Colorspace.php index fe47d7f0..2b64030f 100644 --- a/src/Colors/Cmyk/Colorspace.php +++ b/src/Colors/Cmyk/Colorspace.php @@ -42,7 +42,7 @@ class Colorspace implements ColorspaceInterface */ public function importColor(ColorInterface $color): ColorInterface { - return match (get_class($color)) { + return match ($color::class) { RgbColor::class => $this->importRgbColor($color), HsvColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)), HslColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)), diff --git a/src/Colors/Hsl/Colorspace.php b/src/Colors/Hsl/Colorspace.php index e3c7e421..c8baf320 100644 --- a/src/Colors/Hsl/Colorspace.php +++ b/src/Colors/Hsl/Colorspace.php @@ -35,7 +35,7 @@ class Colorspace implements ColorspaceInterface public function importColor(ColorInterface $color): ColorInterface { - return match (get_class($color)) { + return match ($color::class) { CmykColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)), RgbColor::class => $this->importRgbColor($color), HsvColor::class => $this->importHsvColor($color), diff --git a/src/Colors/Hsv/Colorspace.php b/src/Colors/Hsv/Colorspace.php index 01d97013..c6f2f545 100644 --- a/src/Colors/Hsv/Colorspace.php +++ b/src/Colors/Hsv/Colorspace.php @@ -40,7 +40,7 @@ class Colorspace implements ColorspaceInterface */ public function importColor(ColorInterface $color): ColorInterface { - return match (get_class($color)) { + return match ($color::class) { CmykColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)), RgbColor::class => $this->importRgbColor($color), HslColor::class => $this->importHslColor($color), diff --git a/src/Colors/Rgb/Colorspace.php b/src/Colors/Rgb/Colorspace.php index 60bbc455..0335eabd 100644 --- a/src/Colors/Rgb/Colorspace.php +++ b/src/Colors/Rgb/Colorspace.php @@ -40,7 +40,7 @@ class Colorspace implements ColorspaceInterface */ public function importColor(ColorInterface $color): ColorInterface { - return match (get_class($color)) { + return match ($color::class) { CmykColor::class => $this->importCmykColor($color), HsvColor::class => $this->importHsvColor($color), HslColor::class => $this->importHslColor($color), diff --git a/src/Drivers/AbstractDriver.php b/src/Drivers/AbstractDriver.php index 17a1a2d2..9428c63f 100644 --- a/src/Drivers/AbstractDriver.php +++ b/src/Drivers/AbstractDriver.php @@ -33,7 +33,7 @@ abstract class AbstractDriver implements DriverInterface } $driver_namespace = (new ReflectionClass($this))->getNamespaceName(); - $class_path = substr(get_class($object), strlen("Intervention\\Image\\")); + $class_path = substr($object::class, strlen("Intervention\\Image\\")); $classname = $driver_namespace . "\\" . $class_path; if (!class_exists($classname)) { diff --git a/src/Drivers/AbstractInputHandler.php b/src/Drivers/AbstractInputHandler.php index 4f1c5d0c..88d77c4b 100644 --- a/src/Drivers/AbstractInputHandler.php +++ b/src/Drivers/AbstractInputHandler.php @@ -36,7 +36,7 @@ abstract class AbstractInputHandler implements InputHandlerInterface protected function chain(): AbstractDecoder { if (count($this->decoders) == 0) { - throw new DecoderException('No decoders found in ' . get_class($this)); + throw new DecoderException('No decoders found in ' . $this::class); } // get instance of last decoder in stack diff --git a/src/Drivers/Imagick/ColorProcessor.php b/src/Drivers/Imagick/ColorProcessor.php index 75a6be83..3cbb04dd 100644 --- a/src/Drivers/Imagick/ColorProcessor.php +++ b/src/Drivers/Imagick/ColorProcessor.php @@ -26,7 +26,7 @@ class ColorProcessor implements ColorProcessorInterface public function nativeToColor(mixed $native): ColorInterface { - return match (get_class($this->colorspace)) { + return match ($this->colorspace::class) { CmykColorspace::class => $this->colorspace->colorFromNormalized([ $native->getColorValue(Imagick::COLOR_CYAN), $native->getColorValue(Imagick::COLOR_MAGENTA), diff --git a/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php b/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php index fb2d0279..77f34138 100644 --- a/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php +++ b/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php @@ -37,10 +37,10 @@ class ColorspaceModifier extends DriverSpecialized implements ModifierInterface private function getImagickColorspace(ColorspaceInterface $colorspace): int { - if (!array_key_exists(get_class($colorspace), self::$mapping)) { + if (!array_key_exists($colorspace::class, self::$mapping)) { throw new NotSupportedException('Given colorspace is not supported.'); } - return self::$mapping[get_class($colorspace)]; + return self::$mapping[$colorspace::class]; } }