<commit_before><?php

/**
 * This file is part of the Boomgo PHP ODM for MongoDB.
 *
 * http://boomgo.org
 * https://github.com/Retentio/Boomgo
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Boomgo\Console\Command;

use Symfony\Component\Console\Command\Command,
    Symfony\Component\Console\Input\InputInterface,
    Symfony\Component\Console\Input\InputArgument,
    Symfony\Component\Console\Input\InputOption,
    Symfony\Component\Console\Output\OutputInterface;
use Boomgo\Builder\MapBuilder,
    Boomgo\Builder\MapperGenerator;
use TwigGenerator\Builder\Generator;

/**
 * Mapper Generator Command
 *
 * @author <NAME> <<EMAIL>>
 */
class MapperGeneratorCommand extends Command
{
    /**
     * Constructor
     *
     * @param string $name Command name
     */
    public function __construct($name = null)
    {
        parent::__construct($name);

        $this->setDescription('Mapper generator command');
        $this->setHelp('generate:mappers Generate mappers');
        $this->addArgument('mapping-directory', InputArgument::REQUIRED, 'Mapping sources absolute directory path');
        $this->addArgument('models-directory', InputArgument::VALUE_OPTIONAL, 'Base model/document directory', null);
        $this->addOption('models-namespace', null, InputOption::VALUE_OPTIONAL, 'Model/document namespace (i.e Document or Model)', 'Document');
        $this->addOption('mappers-namespace', null, InputOption::VALUE_OPTIONAL, 'Mappers namespace, default "Mapper"', 'Mapper');
        $this->addOption('parser', null, InputOption::VALUE_OPTIONAL, 'Mapping parser', 'annotation');
        $this->addOption('formatter', null, InputOption::VALUE_OPTIONAL, 'Mapping formatter', 'Underscore2Camel');
    }

    /**
     * Execute the command
     *
     * @param InputInterface  $input
     * @param OutputInterface $output
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $params = array();
        $params = array_merge($input->getArguments(), $input->getOptions());

        if (!is_dir($params['mapping-directory'])) {
            throw new \InvalidArgumentException('Invalid mapping sources directory');
        }

        if (null == $params['models-directory']) {
            $params['models-directory'] = $params['mapping-directory'];
        }

        $parserClass = (strpos($params['parser'], '\\') === false) ? '\\Boomgo\\Parser\\'.ucfirst($params['parser']).'Parser' : $params['parser'];
        $formatterClass = (strpos($params['formatter'], '\\') === false) ? '\\Boomgo\\Formatter\\'.ucfirst($params['formatter']).'Formatter' : $params['formatter'];

        $formatter = new $formatterClass;
        $parser = new $parserClass;

        $mapBuilder = new MapBuilder($parser, $formatter);
        $twigGenerator = new Generator();
        $mapperGenerator = new MapperGenerator($mapBuilder, $twigGenerator);<commit_msg>Set CamelCase standard formatter as default in the mapper generation.<commit_after><?php

/**
 * This file is part of the Boomgo PHP ODM for MongoDB.
 *
 * http://boomgo.org
 * https://github.com/Retentio/Boomgo
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Boomgo\Console\Command;

use Symfony\Component\Console\Command\Command,
    Symfony\Component\Console\Input\InputInterface,
    Symfony\Component\Console\Input\InputArgument,
    Symfony\Component\Console\Input\InputOption,
    Symfony\Component\Console\Output\OutputInterface;
use Boomgo\Builder\MapBuilder,
    Boomgo\Builder\MapperGenerator;
use TwigGenerator\Builder\Generator;

/**
 * Mapper Generator Command
 *
 * @author <NAME> <<EMAIL>>
 */
class MapperGeneratorCommand extends Command
{
    /**
     * Constructor
     *
     * @param string $name Command name
     */
    public function __construct($name = null)
    {
        parent::__construct($name);

        $this->setDescription('Mapper generator command');
        $this->setHelp('generate:mappers Generate mappers');
        $this->addArgument('mapping-directory', InputArgument::REQUIRED, 'Mapping sources absolute directory path');
        $this->addArgument('models-directory', InputArgument::VALUE_OPTIONAL, 'Base model/document directory', null);
        $this->addOption('models-namespace', null, InputOption::VALUE_OPTIONAL, 'Model/document namespace (i.e Document or Model)', 'Document');
        $this->addOption('mappers-namespace', null, InputOption::VALUE_OPTIONAL, 'Mappers namespace, default "Mapper"', 'Mapper');
        $this->addOption('parser', null, InputOption::VALUE_OPTIONAL, 'Mapping parser', 'annotation');
        $this->addOption('formatter', null, InputOption::VALUE_OPTIONAL, 'Mapping formatter', 'CamelCase');
    }

    /**
     * Execute the command
     *
     * @param InputInterface  $input
     * @param OutputInterface $output
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $params = array();
        $params = array_merge($input->getArguments(), $input->getOptions());

        if (!is_dir($params['mapping-directory'])) {
            throw new \InvalidArgumentException('Invalid mapping sources directory');
        }

        if (null == $params['models-directory']) {
            $params['models-directory'] = $params['mapping-directory'];
        }

        $parserClass = (strpos($params['parser'], '\\') === false) ? '\\Boomgo\\Parser\\'.ucfirst($params['parser']).'Parser' : $params['parser'];
        $formatterClass = (strpos($params['formatter'], '\\') === false) ? '\\Boomgo\\Formatter\\'.ucfirst($params['formatter']).'Formatter' : $params['formatter'];

        $formatter = new $formatterClass;
        $parser = new $parserClass;

        $mapBuilder = new MapBuilder($parser, $formatter);
        $twigGenerator = new Generator();
        $mapperGenerator = new MapperGenerator($mapBuilder, $twigGenerator);
{'fraction_non_alphanumeric': 0.14830021349975364, 'fraction_numerical': 0.00016423057973394647, 'mean_word_length': 3.7172734314484894, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7146016', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1666, 'n_words': 366}