<commit_before><?php namespace DragonFly\Lists\Console\Commands;

use Illuminate\Console\Command;
use Memio\Model\Phpdoc\VariableTag;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Memio\Memio\Config\Build;
use Memio\Model\File;
use Memio\Model\Object;
use Memio\Model\Method;
use Memio\Model\Argument;
use Memio\Model\Property;
use Memio\Model\Phpdoc\MethodPhpdoc;
use Memio\Model\Phpdoc\Description;
use Memio\Model\Phpdoc\ReturnTag;
use Memio\Model\Phpdoc\ParameterTag;
use Memio\Model\Phpdoc\PropertyPhpdoc;

class GenerateTable extends Command
{
    use \Illuminate\Console\AppNamespaceDetectorTrait;
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'make:table';
    
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generate a dataTable definition';
    
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    
    protected $uses = [];
    
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire()
    {
        $table_name = ucfirst($this->argument('name'));
        $model_name = $this->option('model');
        $fields = explode(',', $this->option('fields'));
        
        $app_namespace = $this->getAppNamespace();
        
        $extends = Object::make('DragonFly\Lists\Table');
        $model = Object::make($model_name);
        
        // Add use statements
        $this->uses[] = 'use ' . $extends->getFullyQualifiedName() . ';';
        $this->uses[] = 'use ' . $model->getFullyQualifiedName() . ';';
        
        // Prepare the methods definition
        $methods = $this->prepareMethods($table_name, $model, $fields);
        
        // Initialise the object definition
        $table = Object::make($app_namespace . 'Http\Tables\\' . $table_name)
                       ->extend($extends);

        // Add a kernel identifier
        $kernel_id = ($this->option('kernel')) ?: strtolower(snake_case($table_name));

        // Check if the kernel identifier is defined already
        if (app('Illuminate\Contracts\Http\Kernel')->isTableDefined($kernel_id))
        {
            $this->error('Seems like there\'s already a table defined in your Http kernel with the identifier: "' . $kernel_id . '"');

            return;
        }

        $table->addProperty(
            Property::make('kernel_identifier')
                    ->makeProtected()
                    ->setDefaultValue("'" . $kernel_id . "'")
                    ->setPhpdoc(
                        PropertyPhpdoc::make()
                                      ->setVariableTag(VariableTag::make('string The identifier used for routing through the kernel.'))
                    )
        );

        if ($this->option('route') !== false)
        {
            $table->addProperty(
                Property::make('route')
                        ->makeProtected()
                        ->setDefaultValue("'" . $this->option('route') . "'")
                        ->setPhpdoc(
                            PropertyPhpdoc::make()
                                          ->setVariableTag(VariableTag::make('string The name of the route to use for data requests'))
                        )
            );
        }

        // Add the methods to the object definition
        foreach ($methods as $name => $def)
        {
            $method = Method::make($name);
            
            // Add arguments, if any
            if (isset($def['arguments']))
            {
                foreach ($def['arguments'] as $argument)
                {
                    $method->addArgument($argument);
                }
            }

            // Add PHPDOCs to the method
            $docs = MethodPhpdoc::make();
            
            foreach ($def['docs'] as $doc)
            {
                call_user_func([$docs, $doc['type']], $doc['value']);
            }
            $method->setPhpdoc($docs);
            
            // Add body
            $method->setBody($def['body']);
            
            $table->addMethod($method);
        }
        
        // make the main instance
        $file = File::make(app_path('Http/Tables/' . $table_name . '.php'))
                    ->setStructure($table);
        
        
        // Parse everything into a string
        $prettyPrinter = Build::prettyPrinter();
        $generatedCode = $prettyPrinter->generateCode($file);
        
        // Add use statements
        $class = str_replace('namespace ' . $app_namespace . 'Tables;', "\n" . 'namespace ' . $app_namespace . 'Tables;' . "\n\n" . implode("\n", $this->uses), $generatedCode);

        if (!file_exists($file->getFilename()) || $this->option('overwrite'))
        {
            // Save the new class
            file_put_contents($file->getFilename(), $class);

            $this->info($app_namespace . 'Tables\\' . $table_name . ' was created successfully!');
            $this->comment('It\'s time to add it in your Http kernel:');
            $this->comment("'$kernel_id' => '" . $app_namespace . "Tables\\$table_name'");
        }
        else
        {<commit_msg>fixed namespace error when generating table definitions<commit_after><?php namespace DragonFly\Lists\Console\Commands;

use Illuminate\Console\Command;
use Memio\Model\Phpdoc\VariableTag;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Memio\Memio\Config\Build;
use Memio\Model\File;
use Memio\Model\Object;
use Memio\Model\Method;
use Memio\Model\Argument;
use Memio\Model\Property;
use Memio\Model\Phpdoc\MethodPhpdoc;
use Memio\Model\Phpdoc\Description;
use Memio\Model\Phpdoc\ReturnTag;
use Memio\Model\Phpdoc\ParameterTag;
use Memio\Model\Phpdoc\PropertyPhpdoc;

class GenerateTable extends Command
{
    use \Illuminate\Console\AppNamespaceDetectorTrait;
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'make:table';
    
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generate a dataTable definition';
    
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    
    protected $uses = [];
    
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire()
    {
        $table_name = ucfirst($this->argument('name'));
        $model_name = $this->option('model');
        $fields = explode(',', $this->option('fields'));
        
        $app_namespace = $this->getAppNamespace();
        
        $extends = Object::make('DragonFly\Lists\Table');
        $model = Object::make($model_name);
        
        // Add use statements
        $this->uses[] = 'use ' . $extends->getFullyQualifiedName() . ';';
        $this->uses[] = 'use ' . $model->getFullyQualifiedName() . ';';
        
        // Prepare the methods definition
        $methods = $this->prepareMethods($table_name, $model, $fields);
        
        // Initialise the object definition
        $table = Object::make($app_namespace . 'Http\Tables\\' . $table_name)
                       ->extend($extends);

        // Add a kernel identifier
        $kernel_id = ($this->option('kernel')) ?: strtolower(snake_case($table_name));

        // Check if the kernel identifier is defined already
        if (app('Illuminate\Contracts\Http\Kernel')->isTableDefined($kernel_id))
        {
            $this->error('Seems like there\'s already a table defined in your Http kernel with the identifier: "' . $kernel_id . '"');

            return;
        }

        $table->addProperty(
            Property::make('kernel_identifier')
                    ->makeProtected()
                    ->setDefaultValue("'" . $kernel_id . "'")
                    ->setPhpdoc(
                        PropertyPhpdoc::make()
                                      ->setVariableTag(VariableTag::make('string The identifier used for routing through the kernel.'))
                    )
        );

        if ($this->option('route') !== false)
        {
            $table->addProperty(
                Property::make('route')
                        ->makeProtected()
                        ->setDefaultValue("'" . $this->option('route') . "'")
                        ->setPhpdoc(
                            PropertyPhpdoc::make()
                                          ->setVariableTag(VariableTag::make('string The name of the route to use for data requests'))
                        )
            );
        }

        // Add the methods to the object definition
        foreach ($methods as $name => $def)
        {
            $method = Method::make($name);
            
            // Add arguments, if any
            if (isset($def['arguments']))
            {
                foreach ($def['arguments'] as $argument)
                {
                    $method->addArgument($argument);
                }
            }

            // Add PHPDOCs to the method
            $docs = MethodPhpdoc::make();
            
            foreach ($def['docs'] as $doc)
            {
                call_user_func([$docs, $doc['type']], $doc['value']);
            }
            $method->setPhpdoc($docs);
            
            // Add body
            $method->setBody($def['body']);
            
            $table->addMethod($method);
        }
        
        // make the main instance
        $file = File::make(app_path('Http/Tables/' . $table_name . '.php'))
                    ->setStructure($table);
        
        
        // Parse everything into a string
        $prettyPrinter = Build::prettyPrinter();
        $generatedCode = $prettyPrinter->generateCode($file);

        // Add use statements
        $class = str_replace('namespace ' . $app_namespace . 'Http\Tables;', "\n" . 'namespace ' . $app_namespace . 'Http\Tables;' . "\n\n" . implode("\n", $this->uses), $generatedCode);


        if (!file_exists($file->getFilename()) || $this->option('overwrite'))
        {
            // Save the new class
            file_put_contents($file->getFilename(), $class);

            $this->info($app_namespace . 'Tables\\' . $table_name . ' was created successfully!');
            $this->comment('It\'s time to add it in your Http kernel:');
            $this->comment("'$kernel_id' => '" . $app_namespace . "Http\Tables\\$table_name'");
        }
        else
        {
{'fraction_non_alphanumeric': 0.1392630003741115, 'fraction_numerical': 0.0, 'mean_word_length': 1.7410920276852089, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1772573', 'n_tokens_mistral': 2909, 'n_tokens_neox': 2850, 'n_words': 598}