|
@@ -23,13 +23,10 @@ final class FixerConfigurationResolver implements FixerConfigurationResolverInte
|
|
|
{
|
|
|
/**
|
|
|
* @var list<FixerOptionInterface>
|
|
|
+ *
|
|
|
+ * @readonly
|
|
|
*/
|
|
|
- private array $options = [];
|
|
|
-
|
|
|
- /**
|
|
|
- * @var list<string>
|
|
|
- */
|
|
|
- private array $registeredNames = [];
|
|
|
+ private array $options;
|
|
|
|
|
|
/**
|
|
|
* @param iterable<FixerOptionInterface> $options
|
|
@@ -37,12 +34,11 @@ final class FixerConfigurationResolver implements FixerConfigurationResolverInte
|
|
|
public function __construct(iterable $options)
|
|
|
{
|
|
|
$fixerOptionSorter = new FixerOptionSorter();
|
|
|
+ $this->validateOptions($options);
|
|
|
|
|
|
- foreach ($fixerOptionSorter->sort($options) as $option) {
|
|
|
- $this->addOption($option);
|
|
|
- }
|
|
|
+ $this->options = $fixerOptionSorter->sort($options);
|
|
|
|
|
|
- if (0 === \count($this->registeredNames)) {
|
|
|
+ if (0 === \count($this->options)) {
|
|
|
throw new \LogicException('Options cannot be empty.');
|
|
|
}
|
|
|
}
|
|
@@ -131,17 +127,22 @@ final class FixerConfigurationResolver implements FixerConfigurationResolverInte
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @param iterable<FixerOptionInterface> $options
|
|
|
+ *
|
|
|
* @throws \LogicException when the option is already defined
|
|
|
*/
|
|
|
- private function addOption(FixerOptionInterface $option): void
|
|
|
+ private function validateOptions(iterable $options): void
|
|
|
{
|
|
|
- $name = $option->getName();
|
|
|
+ $names = [];
|
|
|
|
|
|
- if (\in_array($name, $this->registeredNames, true)) {
|
|
|
- throw new \LogicException(\sprintf('The "%s" option is defined multiple times.', $name));
|
|
|
- }
|
|
|
+ foreach ($options as $option) {
|
|
|
+ $name = $option->getName();
|
|
|
|
|
|
- $this->options[] = $option;
|
|
|
- $this->registeredNames[] = $name;
|
|
|
+ if (\in_array($name, $names, true)) {
|
|
|
+ throw new \LogicException(\sprintf('The "%s" option is defined multiple times.', $name));
|
|
|
+ }
|
|
|
+
|
|
|
+ $names[] = $name;
|
|
|
+ }
|
|
|
}
|
|
|
}
|