<commit_before><?php
/**
 * Laravel IDE Helper Generator
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 <NAME> / Fruitcake Studio (http://www.fruitcakestudio.nl)
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
 * @link      https://github.com/barryvdh/laravel-ide-helper
 */

namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\ClassLoader\ClassMapGenerator;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Context;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer;
/**
 * A command to generate autocomplete information for your IDE
 *
 * @author <NAME> <<EMAIL>>
 */
class ModelsCommand extends Command {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'ide-helper:models';
    protected $filename = '_ide_helper_models.php';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generate autocompletion for models';

    protected $properties = array();
    protected $methods = array();
    protected $write = false;
    protected $dirs = array();
    protected $reset;



    /**
     * Execute the console command.
     *
     * @return void
     */
    public function fire()
    {
        $filename = $this->option('filename');
        $this->write = $this->option('write');
        $this->dirs = array_merge($this->laravel['config']->get('laravel-ide-helper::model_locations'), $this->option('dir'));
        $model = $this->argument('model');
        $ignore = $this->option('ignore');
        $this->reset = $this->option('reset');

        //If filename is default and Write is not specified, ask what to do
        if(!$this->write && $filename === $this->filename && !$this->option('nowrite')){
            if($this->confirm("Do you want to overwrite the existing model files for '$model'? Choose no to write to $filename instead? (Yes/No): ")){
                $this->write = true;
            }
        }

        $content = $this->generateDocs($model, $ignore);

        if(!$this->write){
            $written = \File::put($filename, $content);
            if($written !== false){
                $this->info("Model information was written to $filename");
            }else{
                $this->error("Failed to write model information to $filename");
            }
        }
    }


    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return array(
            array('model', InputArgument::OPTIONAL, 'Which models to include', '*'),
        );
    }

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return array(
            array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', $this->filename),
            array('dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The model dir', array()),
            array('write', 'W', InputOption::VALUE_NONE, 'Write to Model file'),
            array('nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'),
            array('reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'),
            array('ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''),
        );
    }

    protected function generateDocs($model, $ignore = ''){


        $output = "<?php
/**
 * An helper file for your Eloquent Models
 * Copy the phpDocs from this file to the correct Model,
 * And remove them from this file, to prevent double declarations.
 *
 * @author <NAME> <<EMAIL>>
 */
\n\n";

        if($model === '*'){
            $models = $this->loadModels();
        }else{
            $models = explode(',', $model);
        }

        $ignore = explode(',', $ignore);

        foreach($models as $name){
            if(in_array($name, $ignore)){
                $this->comment("Ignoring model '$name'");
                continue;
            }else{
                $this->comment("Loading model '$name'");
            }
            $this->properties = array();
            $this->methods = array();
            if(class_exists($name)){
                try {
                    // handle abstract classes, interfaces, ...
                    $reflectionClass = new \ReflectionClass($name);
                    if (!$reflectionClass->IsInstantiable()) {
                        throw new \Exception($name . ' is not instanciable.');
                    }

                    $model = new $name();<commit_msg>Check if the class is a model before instantiating<commit_after><?php
/**
 * Laravel IDE Helper Generator
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 <NAME> / Fruitcake Studio (http://www.fruitcakestudio.nl)
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
 * @link      https://github.com/barryvdh/laravel-ide-helper
 */

namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\ClassLoader\ClassMapGenerator;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Context;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer;
/**
 * A command to generate autocomplete information for your IDE
 *
 * @author <NAME> <<EMAIL>>
 */
class ModelsCommand extends Command {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'ide-helper:models';
    protected $filename = '_ide_helper_models.php';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generate autocompletion for models';

    protected $properties = array();
    protected $methods = array();
    protected $write = false;
    protected $dirs = array();
    protected $reset;



    /**
     * Execute the console command.
     *
     * @return void
     */
    public function fire()
    {
        $filename = $this->option('filename');
        $this->write = $this->option('write');
        $this->dirs = array_merge($this->laravel['config']->get('laravel-ide-helper::model_locations'), $this->option('dir'));
        $model = $this->argument('model');
        $ignore = $this->option('ignore');
        $this->reset = $this->option('reset');

        //If filename is default and Write is not specified, ask what to do
        if(!$this->write && $filename === $this->filename && !$this->option('nowrite')){
            if($this->confirm("Do you want to overwrite the existing model files for '$model'? Choose no to write to $filename instead? (Yes/No): ")){
                $this->write = true;
            }
        }

        $content = $this->generateDocs($model, $ignore);

        if(!$this->write){
            $written = \File::put($filename, $content);
            if($written !== false){
                $this->info("Model information was written to $filename");
            }else{
                $this->error("Failed to write model information to $filename");
            }
        }
    }


    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return array(
            array('model', InputArgument::OPTIONAL, 'Which models to include', '*'),
        );
    }

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return array(
            array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', $this->filename),
            array('dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The model dir', array()),
            array('write', 'W', InputOption::VALUE_NONE, 'Write to Model file'),
            array('nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'),
            array('reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'),
            array('ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''),
        );
    }

    protected function generateDocs($model, $ignore = ''){


        $output = "<?php
/**
 * An helper file for your Eloquent Models
 * Copy the phpDocs from this file to the correct Model,
 * And remove them from this file, to prevent double declarations.
 *
 * @author <NAME> <<EMAIL>>
 */
\n\n";

        if($model === '*'){
            $models = $this->loadModels();
        }else{
            $models = explode(',', $model);
        }

        $ignore = explode(',', $ignore);

        foreach($models as $name){
            if(in_array($name, $ignore)){
                $this->comment("Ignoring model '$name'");
                continue;
            }else{
                $this->comment("Loading model '$name'");
            }
            $this->properties = array();
            $this->methods = array();
            if(class_exists($name)){
                try {
                    // handle abstract classes, interfaces, ...
                    $reflectionClass = new \ReflectionClass($name);
                    if (!$reflectionClass->IsInstantiable()) {
                        throw new \Exception($name . ' is not instanciable.');
                    }elseif(!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')){
                        $this->comment("Class '$name' is not a model");
                        continue;
                    }

                    $model = new $name();
{'fraction_non_alphanumeric': 0.14462098977836252, 'fraction_numerical': 0.0008096346523631211, 'mean_word_length': 2.2830564784053156, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 79, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '3218422', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2641, 'n_words': 695}