Skip to content

Commit

Permalink
remove deprecated RectorServiceConfigurator::configure() method
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 6, 2023
1 parent ccf37c6 commit 2b39454
Showing 1 changed file with 1 addition and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,12 @@

namespace Rector\Core\DependencyInjection\Loader\Configurator;

use Rector\Core\Configuration\ValueObjectInliner;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServiceConfigurator;

/**
* @api
* Same as Symfony service configurator, with extra "configure()" method for easier DX
* Same as Symfony service configurator
*/
final class RectorServiceConfigurator extends ServiceConfigurator
{
/**
* @deprecated Use @see \Rector\Config\RectorConfig instead
* @param mixed[] $configuration
*/
public function configure(array $configuration): self
{
$this->ensureClassIsConfigurable($this->id);

// decorate with value object inliner so Symfony understands, see https://getrector.org/blog/2020/09/07/how-to-inline-value-object-in-symfony-php-config
array_walk_recursive($configuration, static function (&$value) {
if (is_object($value)) {
$value = ValueObjectInliner::inline($value);
}

return $value;
});

$this->call('configure', [$configuration]);

return $this;
}

private function ensureClassIsConfigurable(?string $class): void
{
if ($class === null) {
throw new InvalidConfigurationException('The class is missing');
}

if (! is_a($class, ConfigurableRectorInterface::class, true)) {
$errorMessage = sprintf(
'The service "%s" is not configurable. Make it implement "%s" or remove "configure()" call.',
$class,
ConfigurableRectorInterface::class,
);
throw new InvalidConfigurationException($errorMessage);
}
}
}

0 comments on commit 2b39454

Please sign in to comment.