Skip to content

Commit

Permalink
Mess with Config object
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed May 10, 2024
1 parent 64632cd commit 59781c7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 60 deletions.
31 changes: 10 additions & 21 deletions src/Config.php
Expand Up @@ -5,9 +5,8 @@
namespace Intervention\Image;

use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Interfaces\ConfigInterface;

class Config implements ConfigInterface
class Config
{
/**
* Create config object instance
Expand All @@ -25,30 +24,20 @@ public function __construct(
}

/**
* {@inheritdoc}
* Set values of given config options
*
* @see ConfigInterface::setOption()
*/
public function setOption(string $name, mixed $value): self
{
if (!property_exists($this, $name)) {
throw new InputException('Property ' . $name . ' does not exists for ' . $this::class . '.');
}

$this->{$name} = $value;

return $this;
}

/**
* {@inheritdoc}
*
* @see COnfigInterface::setOptions()
* @param mixed $options
* @throws InputException
* @return Config
*/
public function setOptions(mixed ...$options): self
{
foreach ($options as $name => $value) {
$this->setOption($name, $value);
if (!property_exists($this, $name)) {
throw new InputException('Property ' . $name . ' does not exists for ' . $this::class . '.');
}

$this->{$name} = $value;
}

return $this;
Expand Down
5 changes: 2 additions & 3 deletions src/Drivers/AbstractDriver.php
Expand Up @@ -10,7 +10,6 @@
use Intervention\Image\InputHandler;
use Intervention\Image\Interfaces\AnalyzerInterface;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ConfigInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\EncoderInterface;
Expand All @@ -25,7 +24,7 @@ abstract class AbstractDriver implements DriverInterface
/**
* Driver options
*/
protected ConfigInterface $config;
protected Config $config;

/**
* @throws DriverException
Expand All @@ -42,7 +41,7 @@ public function __construct()
*
* @see DriverInterface::config()
*/
public function config(): ConfigInterface
public function config(): Config
{
return $this->config;
}
Expand Down
29 changes: 0 additions & 29 deletions src/Interfaces/ConfigInterface.php

This file was deleted.

5 changes: 3 additions & 2 deletions src/Interfaces/DriverInterface.php
Expand Up @@ -4,6 +4,7 @@

namespace Intervention\Image\Interfaces;

use Intervention\Image\Config;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Exceptions\RuntimeException;
Expand All @@ -23,9 +24,9 @@ public function id(): string;
/**
* Get driver configuration
*
* @return ConfigInterface
* @return Config
*/
public function config(): ConfigInterface;
public function config(): Config;

/**
* Resolve given object into a specialized version for the current driver
Expand Down
6 changes: 1 addition & 5 deletions tests/Unit/ConfigTest.php
Expand Up @@ -53,14 +53,10 @@ public function testGetSetOptions(): void
$this->assertFalse($result->decodeAnimation);
$this->assertEquals('f00', $result->blendingColor);

$result = $config->setOption('blendingColor', '000');
$result = $config->setOptions(blendingColor: '000');

$this->assertFalse($config->autoOrientation);
$this->assertFalse($config->decodeAnimation);
$this->assertEquals('000', $config->blendingColor);

$this->assertFalse($result->autoOrientation);
$this->assertFalse($result->decodeAnimation);
$this->assertEquals('000', $result->blendingColor);
}
}

0 comments on commit 59781c7

Please sign in to comment.