1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-23 05:52:47 +02:00

Remove redundant code

This commit is contained in:
Oliver Vogel
2023-11-25 14:40:47 +01:00
parent 3d9272f353
commit f4c22cffe8
6 changed files with 0 additions and 144 deletions

View File

@@ -1,8 +0,0 @@
<?php
namespace Intervention\Image\Exceptions;
class TypeException extends \RuntimeException
{
//
}

View File

@@ -1,15 +0,0 @@
<?php
namespace Intervention\Image\Traits;
use Intervention\Image\Interfaces\FactoryInterface;
trait CanBuildNewImage
{
use CanResolveDriverClass;
public function imageFactory(): FactoryInterface
{
return $this->resolveDriverClass('Factory');
}
}

View File

@@ -1,26 +0,0 @@
<?php
namespace Intervention\Image\Traits;
use Intervention\Image\Exceptions\TypeException;
trait CanCheckType
{
public function failIfNotClass(mixed $input, string $classname)
{
if (!is_object($input) || get_class($input) != $classname) {
throw new TypeException('Given input is not instance of ' . $classname);
}
return $input;
}
public function failIfNotInstance(mixed $input, string $classname)
{
if (!is_object($input) || !is_a($input, $classname)) {
throw new TypeException('Given input is not instance of ' . $classname);
}
return $input;
}
}

View File

@@ -1,16 +0,0 @@
<?php
namespace Intervention\Image\Traits;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
trait CanHandleInput
{
use CanResolveDriverClass;
public function handleInput($input): ImageInterface|ColorInterface
{
return $this->resolveDriverClass('InputHandler')->handle($input);
}
}

View File

@@ -1,50 +0,0 @@
<?php
namespace Intervention\Image\Traits;
use Intervention\Image\Exceptions\MissingDriverComponentException;
use Intervention\Image\Exceptions\RuntimeException;
use ReflectionClass;
use ReflectionException;
trait CanResolveDriverClass
{
/**
* Resolve given classname according to current driver
*
* @param string $classname
* @param array $arguments
* @return mixed
*/
protected function resolveDriverClass(string $classname, ...$arguments)
{
$driver_id = $this->getCurrentDriver();
$classname = sprintf(
"Intervention\\Image\\Drivers\\%s\\%s",
ucfirst($driver_id),
$classname
);
try {
$reflection = new ReflectionClass($classname);
} catch (ReflectionException $e) {
throw new MissingDriverComponentException(
'Class (' . $classname . ') could not be resolved with driver ' . ucfirst($driver_id) . '.'
);
}
return $reflection->newInstanceArgs($arguments);
}
protected function getCurrentDriver(): string
{
$pattern = '/Intervention\\\Image\\\Drivers\\\(?P<driver>[A-Za-z]+)/';
preg_match($pattern, get_class($this), $matches);
if (! array_key_exists('driver', $matches)) {
throw new RuntimeException('Current driver could not be resolved.');
}
return strtolower($matches['driver']);
}
}

View File

@@ -1,29 +0,0 @@
<?php
namespace Intervention\Image\Traits;
trait CanRunCallback
{
protected function runCallback(callable $callback, object $object): object
{
$callback($object);
return $object;
}
/**
* Runs given callback against given object and returns object
*
* @param null|callable $callback
* @param object $object
* @return object
*/
protected function maybeRunCallback(?callable $callback, object $object): object
{
if (is_callable($callback)) {
return $this->runCallback($callback, $object);
}
return $object;
}
}