PHPSA\Configuration::getConfigTreeBuilder PHP Method

getConfigTreeBuilder() public method

Generates the configuration tree.
public getConfigTreeBuilder ( array $analyzersConfiguration = [] ) : Symfony\Component\Config\Definition\Builder\TreeBuilder
$analyzersConfiguration array
return Symfony\Component\Config\Definition\Builder\TreeBuilder
    public function getConfigTreeBuilder(array $analyzersConfiguration = [])
    {
        $treeBuilder = new TreeBuilder();
        $root = $treeBuilder->root('phpsa');
        $root->children()->booleanNode('blame')->defaultFalse()->end()->scalarNode('language_level')->defaultValue(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION)->attribute('example', '5.3')->attribute('info', 'Will be used to automatically disable the analyzers that require a greater version of PHP.')->end()->enumNode('parser')->defaultValue('prefer-7')->attribute('label', 'Check types of Arguments.')->values([ParserFactory::PREFER_PHP7 => 'prefer-7', ParserFactory::PREFER_PHP5 => 'prefer-5', ParserFactory::ONLY_PHP7 => 'only-7', ParserFactory::ONLY_PHP5 => 'only-5'])->end()->end();
        $analyzersConfigRoot = $root->children()->arrayNode('analyzers')->addDefaultsIfNotSet();
        $language_error = (new TreeBuilder())->root('language_error')->info("Contains all compiler notices. Those are raised when PHP with strict error reporting would create at least a Notice message. (mostly experimental)")->canBeDisabled();
        $analyzersConfigRoot->append($language_error);
        foreach ($analyzersConfiguration as $config) {
            $analyzersConfigRoot->append($config);
        }
        return $treeBuilder;
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $analyzerConfiguration = Analyzer\Factory::getPassesConfigurations();
     $configuration = new Configuration([], $analyzerConfiguration);
     $configTree = $configuration->getConfigTreeBuilder($analyzerConfiguration)->buildTree();
     $dumper = new YamlReferenceDumper();
     $output->writeln($dumper->dumpNode($configTree));
 }