mirror of
https://github.com/Intervention/image.git
synced 2025-08-13 17:34:04 +02:00
Refactor get_class() to class constant
This commit is contained in:
@@ -24,7 +24,7 @@ abstract class AbstractColor implements ColorInterface
|
|||||||
public function channel(string $classname): ColorChannelInterface
|
public function channel(string $classname): ColorChannelInterface
|
||||||
{
|
{
|
||||||
$channels = array_filter($this->channels(), function (ColorChannelInterface $channel) use ($classname) {
|
$channels = array_filter($this->channels(), function (ColorChannelInterface $channel) use ($classname) {
|
||||||
return get_class($channel) == $classname;
|
return $channel::class == $classname;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (count($channels) == 0) {
|
if (count($channels) == 0) {
|
||||||
|
@@ -42,7 +42,7 @@ class Colorspace implements ColorspaceInterface
|
|||||||
*/
|
*/
|
||||||
public function importColor(ColorInterface $color): ColorInterface
|
public function importColor(ColorInterface $color): ColorInterface
|
||||||
{
|
{
|
||||||
return match (get_class($color)) {
|
return match ($color::class) {
|
||||||
RgbColor::class => $this->importRgbColor($color),
|
RgbColor::class => $this->importRgbColor($color),
|
||||||
HsvColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
|
HsvColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
|
||||||
HslColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
|
HslColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
|
||||||
|
@@ -35,7 +35,7 @@ class Colorspace implements ColorspaceInterface
|
|||||||
|
|
||||||
public function importColor(ColorInterface $color): ColorInterface
|
public function importColor(ColorInterface $color): ColorInterface
|
||||||
{
|
{
|
||||||
return match (get_class($color)) {
|
return match ($color::class) {
|
||||||
CmykColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
|
CmykColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
|
||||||
RgbColor::class => $this->importRgbColor($color),
|
RgbColor::class => $this->importRgbColor($color),
|
||||||
HsvColor::class => $this->importHsvColor($color),
|
HsvColor::class => $this->importHsvColor($color),
|
||||||
|
@@ -40,7 +40,7 @@ class Colorspace implements ColorspaceInterface
|
|||||||
*/
|
*/
|
||||||
public function importColor(ColorInterface $color): ColorInterface
|
public function importColor(ColorInterface $color): ColorInterface
|
||||||
{
|
{
|
||||||
return match (get_class($color)) {
|
return match ($color::class) {
|
||||||
CmykColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
|
CmykColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
|
||||||
RgbColor::class => $this->importRgbColor($color),
|
RgbColor::class => $this->importRgbColor($color),
|
||||||
HslColor::class => $this->importHslColor($color),
|
HslColor::class => $this->importHslColor($color),
|
||||||
|
@@ -40,7 +40,7 @@ class Colorspace implements ColorspaceInterface
|
|||||||
*/
|
*/
|
||||||
public function importColor(ColorInterface $color): ColorInterface
|
public function importColor(ColorInterface $color): ColorInterface
|
||||||
{
|
{
|
||||||
return match (get_class($color)) {
|
return match ($color::class) {
|
||||||
CmykColor::class => $this->importCmykColor($color),
|
CmykColor::class => $this->importCmykColor($color),
|
||||||
HsvColor::class => $this->importHsvColor($color),
|
HsvColor::class => $this->importHsvColor($color),
|
||||||
HslColor::class => $this->importHslColor($color),
|
HslColor::class => $this->importHslColor($color),
|
||||||
|
@@ -33,7 +33,7 @@ abstract class AbstractDriver implements DriverInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$driver_namespace = (new ReflectionClass($this))->getNamespaceName();
|
$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;
|
$classname = $driver_namespace . "\\" . $class_path;
|
||||||
|
|
||||||
if (!class_exists($classname)) {
|
if (!class_exists($classname)) {
|
||||||
|
@@ -36,7 +36,7 @@ abstract class AbstractInputHandler implements InputHandlerInterface
|
|||||||
protected function chain(): AbstractDecoder
|
protected function chain(): AbstractDecoder
|
||||||
{
|
{
|
||||||
if (count($this->decoders) == 0) {
|
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
|
// get instance of last decoder in stack
|
||||||
|
@@ -26,7 +26,7 @@ class ColorProcessor implements ColorProcessorInterface
|
|||||||
|
|
||||||
public function nativeToColor(mixed $native): ColorInterface
|
public function nativeToColor(mixed $native): ColorInterface
|
||||||
{
|
{
|
||||||
return match (get_class($this->colorspace)) {
|
return match ($this->colorspace::class) {
|
||||||
CmykColorspace::class => $this->colorspace->colorFromNormalized([
|
CmykColorspace::class => $this->colorspace->colorFromNormalized([
|
||||||
$native->getColorValue(Imagick::COLOR_CYAN),
|
$native->getColorValue(Imagick::COLOR_CYAN),
|
||||||
$native->getColorValue(Imagick::COLOR_MAGENTA),
|
$native->getColorValue(Imagick::COLOR_MAGENTA),
|
||||||
|
@@ -37,10 +37,10 @@ class ColorspaceModifier extends DriverSpecialized implements ModifierInterface
|
|||||||
|
|
||||||
private function getImagickColorspace(ColorspaceInterface $colorspace): int
|
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.');
|
throw new NotSupportedException('Given colorspace is not supported.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$mapping[get_class($colorspace)];
|
return self::$mapping[$colorspace::class];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user