Ejemplo n.º 1
0
 /**
  * Factory config according Input
  *
  * @param InputInterface $input
  * @return Configuration
  */
 public function factory(InputInterface $input)
 {
     $config = new Configuration();
     $treeBuilder = new TreeBuilder();
     $hydrator = new Hydrator(new Validator($treeBuilder->getTree()));
     // first, load config file
     $locator = new ConfigLocator();
     $filename = $locator->locate($input->getOption('config'));
     if (null !== $filename) {
         $loader = new Loader($hydrator);
         $config = $loader->load($filename);
     } else {
         $config = $hydrator->hydrates($config, array());
     }
     // then, overwrite configuration by arguments provided in run
     strlen($input->getArgument('path')) > 0 && $config->getPath()->setBasePath($input->getArgument('path'));
     strlen($input->getOption('extensions')) > 0 && $config->getPath()->setExtensions($input->getOption('extensions'));
     strlen($input->getOption('excluded-dirs')) > 0 && $config->getPath()->setExcludedDirs($input->getOption('excluded-dirs'));
     strlen($input->getOption('symlinks')) > 0 && $config->getPath()->setFollowSymlinks(true);
     strlen($input->getOption('report-xml')) > 0 && $config->getLogging()->setReport('xml', $input->getOption('report-xml'));
     strlen($input->getOption('report-cli')) > 0 && $config->getLogging()->setReport('cli', $input->getOption('report-cli'));
     strlen($input->getOption('report-json')) > 0 && $config->getLogging()->setReport('json', $input->getOption('report-json'));
     strlen($input->getOption('report-html')) > 0 && $config->getLogging()->setReport('html', $input->getOption('report-html'));
     strlen($input->getOption('report-csv')) > 0 && $config->getLogging()->setReport('csv', $input->getOption('report-csv'));
     strlen($input->getOption('violations-xml')) > 0 && $config->getLogging()->setViolation('xml', $input->getOption('violations-xml'));
     strlen($input->getOption('chart-bubbles')) > 0 && $config->getLogging()->setChart('bubbles', $input->getOption('chart-bubbles'));
     strlen($input->getOption('failure-condition')) > 0 && $config->setFailureCondition($input->getOption('failure-condition'));
     strlen($input->getOption('template-title')) > 0 && $config->getTemplate()->setTitle($input->getOption('template-title'));
     strlen($input->getOption('ignore-errors')) > 0 && $config->setIgnoreErrors(true);
     return $config;
 }
Ejemplo n.º 2
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage configuration file is not accessible
  */
 public function testExplicitExceptionIsThrownWhenConfigFileIsNotFound()
 {
     $treeBuilder = new TreeBuilder();
     $hydrator = new Hydrator(new Validator($treeBuilder->getTree()));
     $loader = new Loader($hydrator);
     $config = $loader->load('/pat/to/anything');
 }
Ejemplo n.º 3
0
 /**
  * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  */
 public function testInvalideConfigurationAreDetected()
 {
     $config = array('phpmetrics' => array('rules' => array('rule1' => array(1, 2, 3, 4))));
     $treeBuilder = new TreeBuilder();
     $validator = new Validator($treeBuilder->getTree());
     $validator->validates($config);
 }
Ejemplo n.º 4
0
 /**
  * Factory config according Input
  *
  * @param InputInterface $input
  * @return Configuration
  */
 public function factory(InputInterface $input)
 {
     $config = new Configuration();
     $treeBuilder = new TreeBuilder();
     $hydrator = new Hydrator(new Validator($treeBuilder->getTree()));
     // first, load config file
     if (strlen($input->getOption('config')) > 0) {
         $loader = new Loader($hydrator);
         $config = $loader->load($input->getOption('config'));
     } else {
         $config = $hydrator->hydrates($config, array());
     }
     // then, overwrite configuration by arguments provided in run
     strlen($input->getArgument('path')) > 0 && $config->getPath()->setBasePath($input->getArgument('path'));
     strlen($input->getOption('extensions')) > 0 && $config->getPath()->setExtensions($input->getOption('extensions'));
     strlen($input->getOption('excluded-dirs')) > 0 && $config->getPath()->setExcludedDirs($input->getOption('excluded-dirs'));
     strlen($input->getOption('report-xml')) > 0 && $config->getLogging()->setReport('xml', $input->getOption('report-xml'));
     strlen($input->getOption('report-json')) > 0 && $config->getLogging()->setReport('json', $input->getOption('report-json'));
     strlen($input->getOption('report-html')) > 0 && $config->getLogging()->setReport('html', $input->getOption('report-html'));
     strlen($input->getOption('report-csv')) > 0 && $config->getLogging()->setReport('csv', $input->getOption('report-csv'));
     strlen($input->getOption('violations-xml')) > 0 && $config->getLogging()->setViolation('xml', $input->getOption('violations-xml'));
     strlen($input->getOption('chart-bubbles')) > 0 && $config->getLogging()->setChart('bubbles', $input->getOption('chart-bubbles'));
     return $config;
 }