/** * @covers Symfony\CS\Fixer::addConfig * @covers Symfony\CS\Fixer::getConfigs */ public function testThatCanAddAndGetConfigs() { $fixer = new Fixer(); $configs = $fixer->getConfigs(); $c1 = $this->getMock('Symfony\\CS\\ConfigInterface'); $c2 = $this->getMock('Symfony\\CS\\ConfigInterface'); $fixer->addConfig($c1); $fixer->addConfig($c2); $configs[] = $c1; $configs[] = $c2; $this->assertSame($configs, $fixer->getConfigs()); }
protected function getConfigsHelp() { $help = ''; $maxName = 0; $configs = $this->fixer->getConfigs(); usort($configs, function (ConfigInterface $a, ConfigInterface $b) { return strcmp($a->getName(), $b->getName()); }); foreach ($configs as $config) { if (strlen($config->getName()) > $maxName) { $maxName = strlen($config->getName()); } } $count = count($this->fixer->getConfigs()) - 1; foreach ($configs as $i => $config) { $chunks = explode("\n", wordwrap($config->getDescription(), 72 - $maxName, "\n")); $help .= sprintf(" * <comment>%s</comment>%s %s\n", $config->getName(), str_repeat(' ', $maxName - strlen($config->getName())), array_shift($chunks)); while ($c = array_shift($chunks)) { $help .= str_repeat(' ', $maxName + 4) . $c . "\n"; } if ($count !== $i) { $help .= "\n"; } } return $help; }
/** * Resolve config based on options: config, config-file. */ private function resolveConfig() { $configOption = $this->options['config']; if ($configOption) { foreach ($this->fixer->getConfigs() as $c) { if ($c->getName() === $configOption) { $this->config = $c; return; } } if (null === $this->config) { throw new \InvalidArgumentException(sprintf('The configuration "%s" is not defined.', $configOption)); } } foreach ($this->computeConfigFiles() as $configFile) { if (!file_exists($configFile)) { continue; } $config = (include $configFile); // verify that the config has an instance of Config if (!$config instanceof Config) { throw new \UnexpectedValueException(sprintf('The config file: "%s" does not return a "Symfony\\CS\\Config\\Config" instance. Got: "%s".', $configFile, is_object($config) ? get_class($config) : gettype($config))); } $this->config = $config; $this->configFile = $configFile; return; } $this->config = $this->defaultConfig; }