<commit_before><?php namespace Way\Generators\Commands;

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Way\Generators\Parsers\MigrationNameParser;
use Way\Generators\Parsers\MigrationFieldsParser;
use Way\Generators\Generator;
use Way\Generators\SchemaCreator;


class MigrationGeneratorCommand extends GeneratorCommand {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'generate:migration';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generate a new migration';

    /**
     * @var \Way\Generators\ModelGenerator
     */
    protected $generator;
    /**
     * @var MigrationNameParser
     */
    private $migrationNameParser;
    /**
     * @var SchemaWriter
     */
    private $schemaCreator;

    /**
     * @param Generator $generator
     * @param MigrationNameParser $migrationNameParser
     * @param MigrationFieldsParser $migrationFieldsParser
     * @param SchemaCreator $schemaCreator
     */
    public function __construct(
        Generator $generator,
        MigrationNameParser $migrationNameParser,
        MigrationFieldsParser $migrationFieldsParser,
        SchemaCreator $schemaCreator
    )
    {
        $this->generator = $generator;
        $this->migrationNameParser = $migrationNameParser;
        $this->migrationFieldsParser = $migrationFieldsParser;
        $this->schemaCreator = $schemaCreator;

        parent::__construct($generator);
    }


    /**
     * The path where the file will be created
     *
     * @return mixed
     */
    protected function getFileGenerationPath()
    {
        return $this->option('path') . '/' . ucwords(camel_case($this->argument('migrationName'))) . '.php';
    }

    /**
     * Fetch the template data
     *
     * @return array
     */
    protected function getTemplateData()
    {
        $migrationName = $this->argument('migrationName');
        $migrationData = $this->migrationNameParser->parse($migrationName);
        $fields = $this->migrationFieldsParser->parse($this->option('fields'));

        return [
            'CLASS' => ucwords(camel_case($migrationName)),
            'UP'    => $this->schemaCreator->up($migrationData, $fields),
            'DOWN'  => $this->schemaCreator->down($migrationData, $fields)
        ];
    }

    /**
     * Get the console command arguments.
     *<commit_msg>Add date prefix to migration file names<commit_after><?php namespace Way\Generators\Commands;

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Way\Generators\Parsers\MigrationNameParser;
use Way\Generators\Parsers\MigrationFieldsParser;
use Way\Generators\Generator;
use Way\Generators\SchemaCreator;


class MigrationGeneratorCommand extends GeneratorCommand {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'generate:migration';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generate a new migration';

    /**
     * @var \Way\Generators\ModelGenerator
     */
    protected $generator;
    /**
     * @var MigrationNameParser
     */
    private $migrationNameParser;
    /**
     * @var SchemaWriter
     */
    private $schemaCreator;

    /**
     * @param Generator $generator
     * @param MigrationNameParser $migrationNameParser
     * @param MigrationFieldsParser $migrationFieldsParser
     * @param SchemaCreator $schemaCreator
     */
    public function __construct(
        Generator $generator,
        MigrationNameParser $migrationNameParser,
        MigrationFieldsParser $migrationFieldsParser,
        SchemaCreator $schemaCreator
    )
    {
        $this->generator = $generator;
        $this->migrationNameParser = $migrationNameParser;
        $this->migrationFieldsParser = $migrationFieldsParser;
        $this->schemaCreator = $schemaCreator;

        parent::__construct($generator);
    }


    /**
     * The path where the file will be created
     *
     * @return mixed
     */
    protected function getFileGenerationPath()
    {
        $fileName = $this->getDatePrefix() . '_' . $this->argument('migrationName') . '.php';

        return $this->option('path') . "/$fileName";
    }

    /**
     * Get the date prefix for the migration.
     *
     * @return string
     */
    protected function getDatePrefix()
    {
        return date('Y_m_d_His');
    }

    /**
     * Fetch the template data
     *
     * @return array
     */
    protected function getTemplateData()
    {
        $migrationName = $this->argument('migrationName');
        $migrationData = $this->migrationNameParser->parse($migrationName);
        $fields = $this->migrationFieldsParser->parse($this->option('fields'));

        return [
            'CLASS' => ucwords(camel_case($migrationName)),
            'UP'    => $this->schemaCreator->up($migrationData, $fields),
            'DOWN'  => $this->schemaCreator->down($migrationData, $fields)
        ];
    }

    /**
     * Get the console command arguments.
     *
{'fraction_non_alphanumeric': 0.11790814357390969, 'fraction_numerical': 0.0, 'mean_word_length': 2.614365411436541, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, 'https://': 0, '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': '5041644', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1426, 'n_words': 283}