<commit_before><?php
/**
 * phpDocumentor
 *
 * PHP Version 5.3
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010-2011 <NAME> / Naenius (http://www.naenius.com)
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
 * @link      http://phpdoc.org
 */
namespace phpDocumentor\Command\Project;

use \Symfony\Component\Console\Input\InputArgument;
use \Symfony\Component\Console\Input\InputInterface;
use \Symfony\Component\Console\Input\InputOption;
use \Symfony\Component\Console\Output\OutputInterface;

/**
 * Transforms the structure file into the specified output format
 *
 * This task will execute the transformation rules described in the given
 * template (defaults to 'responsive') with the given source (defaults to
 * output/structure.xml) and writes these to the target location (defaults to
 * 'output').
 *
 * It is possible for the user to receive additional information using the
 * verbose option or stop additional information using the quiet option. Please
 * take note that the quiet option also disables logging to file.
 */
class TransformCommand extends \phpDocumentor\Command\ConfigurableCommand
{
    /**
     * Initializes this command and sets the name, description, options and
     * arguments.
     *
     * @return void
     */
    protected function configure()
    {
        $this->setName('project:transform')
            ->setAliases(array('transform'))
            ->setDescription(
                'Converts the PHPDocumentor structure file to documentation'
            )
            ->setHelp(
<<<TEXT
This task will execute the transformation rules described in the given
template (defaults to 'responsive') with the given source (defaults to
output/structure.xml) and writes these to the target location (defaults to
'output').

It is possible for the user to receive additional information using the
verbose option or stop additional information using the quiet option. Please
take note that the quiet option also disables logging to file.
TEXT
            );

        $this->addOption(
            'source',
            's',
            InputOption::VALUE_OPTIONAL,
            'Path where the XML source file is located (optional)'
        );
        $this->addOption(
            'target',
            't',
            InputOption::VALUE_OPTIONAL,
            'Path where to store the generated output (optional)'
        );
        $this->addOption(
            'template',
            null,
            InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
            'Name of the template to use (optional)'
        );
        $this->addOption(
            'parseprivate',
            null,
            InputOption::VALUE_NONE,
            'Whether to parse DocBlocks marked with @internal tag'
        );
        $this->addOption(
            'progressbar',
            'p',
            InputOption::VALUE_NONE,
            'Whether to show a progress bar; will automatically quiet logging to stdout'
        );

        parent::configure();
    }

    /**
     * Executes the business logic involved with this command.
     *
     * @param \Symfony\Component\Console\Input\InputInterface   $input
     * @param \Symfony\Component\Console\Output\OutputInterface $output
     *
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // invoke parent to load custom config
        parent::execute($input, $output);

        /** @var \phpDocumentor\Console\Helper\ProgressHelper $progress  */
        $progress = $this->getProgressBar($input);
        if (!$progress) {
            $this->connectOutputToLogging($output);
        }

        $output->write('Initializing transformer ..');

        // initialize transformer
        $transformer = new \phpDocumentor\Transformer\Transformer();
        $transformer->setTemplatesPath(__DIR__.'/../../../../data/templates');

        $target = $this->getOption($input, 'target', 'transformer/target');
        if (!$this->isAbsolute($target)) {
            $target = getcwd().DIRECTORY_SEPARATOR.$target;
        }
        $transformer->setTarget($target);

        $source = realpath($this->getOption($input, 'source', 'parser/target'));
        if (file_exists($source) and is_dir($source)) {
            $source .= DIRECTORY_SEPARATOR . 'structure.xml';
        }
        $transformer->setSource($source);

        $templates = $this->getTemplates($input);

        $transformer->setTemplates($templates);
        $transformer->setParseprivate($input->getOption('parseprivate'));

        // add links to external docs
        $external_class_documentation = (array)$this->getConfigValueFromPath(
            'transformer/external-class-documentation'
        );
        if (!isset($external_class_documentation[0])) {
            $external_class_documentation = array($external_class_documentation);
        }

        foreach ($external_class_documentation as $doc) {
            if (empty($doc)) {
                continue;
            }

            $transformer->setExternalClassDoc((string)$doc['prefix'], (string)$doc['uri']);
        }

        $output->writeln(' OK');
        $output->write('Processing behaviours ..');
        $this->getService('event_dispatcher')->addListener(
            'transformer.transform.pre',
            function () use ($output) {
                $output->writeln(' OK');
                $output->writeln('Executing transformations');
            }
        );

        if ($progress) {
            $progress->start($output, count($transformer->getTransformations()));
        }

        $transformer->execute();

        if ($progress) {
            $progress->finish();
        }

        return 0;
    }

    /**
     * Retrieves the templates to be used by analyzing the options and the configuration.
     *
     * @param \Symfony\Component\Console\Input\ArgvInput $input
     *
     * @return string[]
     */
    protected function getTemplates(\Symfony\Component\Console\Input\InputInterface $input)
    {
        $templates = $input->getOption('template');
        if (!$templates) {
            $value = $this->getConfigValueFromPath('transformations/template');
            if ($value) {
                foreach ($value as $template) {
                    if (is_array($template)) {
                        $templates[] = $template['name'];
                    }
                }
            }
        }

        if (!$templates) {
            $templates = array('responsive');
        }

        return $templates;
    }

    /**
     * Adds the transformer.transformation.post event to advance the progressbar.
     *
     * @param \Symfony\Component\Console\Input\InputInterface $input
     *
     * @return \Symfony\Component\Console\Helper\HelperInterface|null
     */
    protected function getProgressBar(InputInterface $input)<commit_msg>fix transformations/template tag handling: getConfigValueFromPath returns array of strings<commit_after><?php
/**
 * phpDocumentor
 *
 * PHP Version 5.3
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010-2011 <NAME> / Naenius (http://www.naenius.com)
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
 * @link      http://phpdoc.org
 */
namespace phpDocumentor\Command\Project;

use \Symfony\Component\Console\Input\InputArgument;
use \Symfony\Component\Console\Input\InputInterface;
use \Symfony\Component\Console\Input\InputOption;
use \Symfony\Component\Console\Output\OutputInterface;

/**
 * Transforms the structure file into the specified output format
 *
 * This task will execute the transformation rules described in the given
 * template (defaults to 'responsive') with the given source (defaults to
 * output/structure.xml) and writes these to the target location (defaults to
 * 'output').
 *
 * It is possible for the user to receive additional information using the
 * verbose option or stop additional information using the quiet option. Please
 * take note that the quiet option also disables logging to file.
 */
class TransformCommand extends \phpDocumentor\Command\ConfigurableCommand
{
    /**
     * Initializes this command and sets the name, description, options and
     * arguments.
     *
     * @return void
     */
    protected function configure()
    {
        $this->setName('project:transform')
            ->setAliases(array('transform'))
            ->setDescription(
                'Converts the PHPDocumentor structure file to documentation'
            )
            ->setHelp(
<<<TEXT
This task will execute the transformation rules described in the given
template (defaults to 'responsive') with the given source (defaults to
output/structure.xml) and writes these to the target location (defaults to
'output').

It is possible for the user to receive additional information using the
verbose option or stop additional information using the quiet option. Please
take note that the quiet option also disables logging to file.
TEXT
            );

        $this->addOption(
            'source',
            's',
            InputOption::VALUE_OPTIONAL,
            'Path where the XML source file is located (optional)'
        );
        $this->addOption(
            'target',
            't',
            InputOption::VALUE_OPTIONAL,
            'Path where to store the generated output (optional)'
        );
        $this->addOption(
            'template',
            null,
            InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
            'Name of the template to use (optional)'
        );
        $this->addOption(
            'parseprivate',
            null,
            InputOption::VALUE_NONE,
            'Whether to parse DocBlocks marked with @internal tag'
        );
        $this->addOption(
            'progressbar',
            'p',
            InputOption::VALUE_NONE,
            'Whether to show a progress bar; will automatically quiet logging to stdout'
        );

        parent::configure();
    }

    /**
     * Executes the business logic involved with this command.
     *
     * @param \Symfony\Component\Console\Input\InputInterface   $input
     * @param \Symfony\Component\Console\Output\OutputInterface $output
     *
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // invoke parent to load custom config
        parent::execute($input, $output);

        /** @var \phpDocumentor\Console\Helper\ProgressHelper $progress  */
        $progress = $this->getProgressBar($input);
        if (!$progress) {
            $this->connectOutputToLogging($output);
        }

        $output->write('Initializing transformer ..');

        // initialize transformer
        $transformer = new \phpDocumentor\Transformer\Transformer();
        $transformer->setTemplatesPath(__DIR__.'/../../../../data/templates');

        $target = $this->getOption($input, 'target', 'transformer/target');
        if (!$this->isAbsolute($target)) {
            $target = getcwd().DIRECTORY_SEPARATOR.$target;
        }
        $transformer->setTarget($target);

        $source = realpath($this->getOption($input, 'source', 'parser/target'));
        if (file_exists($source) and is_dir($source)) {
            $source .= DIRECTORY_SEPARATOR . 'structure.xml';
        }
        $transformer->setSource($source);

        $templates = $this->getTemplates($input);

        $transformer->setTemplates($templates);
        $transformer->setParseprivate($input->getOption('parseprivate'));

        // add links to external docs
        $external_class_documentation = (array)$this->getConfigValueFromPath(
            'transformer/external-class-documentation'
        );
        if (!isset($external_class_documentation[0])) {
            $external_class_documentation = array($external_class_documentation);
        }

        foreach ($external_class_documentation as $doc) {
            if (empty($doc)) {
                continue;
            }

            $transformer->setExternalClassDoc((string)$doc['prefix'], (string)$doc['uri']);
        }

        $output->writeln(' OK');
        $output->write('Processing behaviours ..');
        $this->getService('event_dispatcher')->addListener(
            'transformer.transform.pre',
            function () use ($output) {
                $output->writeln(' OK');
                $output->writeln('Executing transformations');
            }
        );

        if ($progress) {
            $progress->start($output, count($transformer->getTransformations()));
        }

        $transformer->execute();

        if ($progress) {
            $progress->finish();
        }

        return 0;
    }

    /**
     * Retrieves the templates to be used by analyzing the options and the configuration.
     *
     * @param \Symfony\Component\Console\Input\ArgvInput $input
     *
     * @return string[]
     */
    protected function getTemplates(\Symfony\Component\Console\Input\InputInterface $input)
    {
        $templates = $input->getOption('template');
        if (!$templates) {
            $value = $this->getConfigValueFromPath('transformations/template');
            if ($value) {
                foreach ($value as $template) {
                    $templates[] = $template;
                }
            }
        }

        if (!$templates) {
            $templates = array('responsive');
        }

        return $templates;
    }

    /**
     * Adds the transformer.transformation.post event to advance the progressbar.
     *
     * @param \Symfony\Component\Console\Input\InputInterface $input
     *
     * @return \Symfony\Component\Console\Helper\HelperInterface|null
     */
    protected function getProgressBar(InputInterface $input)
{'fraction_non_alphanumeric': 0.11594940389648153, 'fraction_numerical': 0.0017446932247746438, 'mean_word_length': 2.319739382239382, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2491824', 'n_tokens_mistral': 3539, 'n_tokens_neox': 3428, 'n_words': 893}