<commit_before><?php

namespace LazyRecord\Migration;

use RuntimeException;
use ReflectionClass;
use CLIFramework\Logger;
use LazyRecord\Schema;
use LazyRecord\TableParser\TableParser;
use LazyRecord\Schema\Comparator;
use ClassTemplate\ClassFile;
use CodeGen\Expr\MethodCallExpr;
use CodeGen\Statement\Statement;
use CodeGen\Raw;
use SQLBuilder\Universal\Query\AlterTableQuery;
use SQLBuilder\ArgumentArray;
use Doctrine\Common\Inflector\Inflector;

class MigrationGenerator
{
    public $logger;

    public $migrationDir;

    public function __construct(Logger $logger, $migrationDir)
    {
        $this->migrationDir = $migrationDir;
        if (!file_exists($this->migrationDir)) {
            mkdir($this->migrationDir, 0755, true);
        }
        $this->logger = $logger;
    }

    /**
     * Returns code template directory.
     */
    protected function getTemplateDirs()
    {
        $refl = new ReflectionClass('LazyRecord\Schema\SchemaGenerator');
        $path = $refl->getFilename();

        return dirname($path).DIRECTORY_SEPARATOR.'Templates';
    }

    public function generateFilename($taskName, $time = null)
    {
        $date = date('Y-m-d');
        if (is_integer($time)) {
            $date = date('Ymd', $time);
        } elseif (is_string($time)) {
            $date = $time;
        }
        $name = Inflector::tableize($taskName);

        return sprintf('%s_%s.php', $date, $taskName);
    }

    /**
     * @return ClassTemplate\ClassFile
     */
    public function createClassTemplate($taskName, $time = null)
    {
        if (!$time) {
            $time = time();
        } elseif (is_string($time)) {
            $time = strtotime($time);
        }
        $className = $taskName.'_'.$time;
        $template = new ClassFile($className);
        $template->useClass('SQLBuilder\\Universal\\Syntax\\Column');<commit_msg>Extract migration filename format<commit_after><?php

namespace LazyRecord\Migration;

use RuntimeException;
use ReflectionClass;
use CLIFramework\Logger;
use LazyRecord\Schema;
use LazyRecord\TableParser\TableParser;
use LazyRecord\Schema\Comparator;
use ClassTemplate\ClassFile;
use CodeGen\Expr\MethodCallExpr;
use CodeGen\Statement\Statement;
use CodeGen\Raw;
use SQLBuilder\Universal\Query\AlterTableQuery;
use SQLBuilder\ArgumentArray;
use Doctrine\Common\Inflector\Inflector;

class MigrationGenerator
{
    protected $logger;

    protected $migrationDir;

    protected $filenameFormat = '@date@_@name@.php';

    public function __construct(Logger $logger, $migrationDir)
    {
        $this->migrationDir = $migrationDir;
        if (!file_exists($this->migrationDir)) {
            mkdir($this->migrationDir, 0755, true);
        }
        $this->logger = $logger;
    }

    /**
     * Returns code template directory.
     */
    protected function getTemplateDirs()
    {
        $refl = new ReflectionClass('LazyRecord\Schema\SchemaGenerator');
        $path = $refl->getFilename();

        return dirname($path).DIRECTORY_SEPARATOR.'Templates';
    }

    public function generateFilename($taskName, $time = null)
    {
        if (is_integer($time)) {
            $date = date('Ymd', $time);
        } elseif (is_string($time)) {
            $date = $time;
        } else {
            $date = date('Ymd');
        }
        $name = Inflector::tableize($taskName);
        return str_replace([ 
            '@date@', '@name@'
        ], [ $date, $name ], $this->filenameFormat);
    }

    /**
     * @return ClassTemplate\ClassFile
     */
    public function createClassTemplate($taskName, $time = null)
    {
        if (!$time) {
            $time = time();
        } elseif (is_string($time)) {
            $time = strtotime($time);
        }
        $className = $taskName.'_'.$time;
        $template = new ClassFile($className);
        $template->useClass('SQLBuilder\\Universal\\Syntax\\Column');
{'fraction_non_alphanumeric': 0.13357307988697661, 'fraction_numerical': 0.0020549704597996403, 'mean_word_length': 2.755062680810029, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '3294891', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1156, 'n_words': 221}