public function configure(array $configuration = null)
{
if (null === $configuration) {
$this->configuration = self::$defaultConfiguration;
return;
}
$this->configuration = array();
foreach ($configuration as $from => $to) {
if (!is_string($from)) {
throw new InvalidFixerConfigurationException($this->getName(), 'Tag to replace must be a string.');
}
if (!is_string($to)) {
throw new InvalidFixerConfigurationException($this->getName(), sprintf('Tag to replace to from "%s" must be a string.', $from));
}
if (1 !== preg_match('#^[^\\s]+$#', $to) || false !== strpos($to, '*/')) {
throw new InvalidFixerConfigurationException($this->getName(), sprintf('Tag "%s" cannot be replaced by invalid tag "%s".', $from, $to));
}
$this->configuration[trim($from)] = trim($to);
if (isset($this->configuration[$to])) {
throw new InvalidFixerConfigurationException($this->getName(), sprintf('Cannot change tag "%s" to tag "%s", as the tag is set configured to be replaced to "%s".', $from, $to, $this->configuration[$to]));
}
}
}