<commit_before><?php
namespace Caffeinated\Modules\Console\Commands;

use Caffeinated\Modules\Modules;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

class ModuleSeedCommand extends Command
{
	/**
	 * @var string $name The console command name.
	 */
	protected $name = 'module:seed';

	/**
	 * @var string $description The console command description.
	 */
	protected $description = 'Seed the database with records for a specific or all modules';

	/**
	 * @var \Caffeinated\Modules\Modules
	 */
	protected $module;

	/**
	 * Create a new command instance.
	 *
	 * @param \Caffeinated\Modules\Modules $module
	 */
	public function __construct(Modules $module)
	{
		parent::__construct();

		$this->module = $module;
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function fire()
	{
		$module     = $this->argument('module');
		$moduleName = Str::studly($module);

		if (isset($module)) {
			if (! $this->module->exists($module)) {
				return $this->error("Module [$moduleName] does not exist.");
			}

			if ($this->module->isEnabled($module)) {
				$this->seed($module);
			} elseif ($this->option('force')) {
				$this->seed($module);
			}

			return;
		} else {
			if ($this->option('force')) {
				$modules = $this->module->all();
			} else {
				$modules = $this->module->getByEnabled();
			}

			foreach ($modules as $module) {
				$this->seed($module['slug']);
			}
		}
	}

	/**
	 * Seed the specific module.
	 *
	 * @param  string $module
	 * @return array
	 */
	protected function seed($module)
	{
		$params     = array();
		$moduleName = Str::studly($module);
		$namespace  = $this->module->getNamespace();
		$rootSeeder = $moduleName.'DatabaseSeeder';
		$fullPath   = $namespace.$moduleName.'\Database\Seeds\\'.$rootSeeder;

		if (class_exists($fullPath)) {
			if ($this->option('class')) {
				$params['--class'] = $this->option('class');
			} else {
				$params['--class'] = $fullPath;
			}

			if ($option = $this->option('database')) {
				$params['--database'] = $option;
			}

	        if ($option = $this->option('force')) {
	            $params['--force'] = $option;
	        }

			$this->call('db:seed', $params);
		}
	}

	/**
	 * Get the console command arguments.
	 *<commit_msg>Fix #80<commit_after><?php
namespace Caffeinated\Modules\Console\Commands;

use Caffeinated\Modules\Modules;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

class ModuleSeedCommand extends Command
{
	/**
	 * @var string $name The console command name.
	 */
	protected $name = 'module:seed';

	/**
	 * @var string $description The console command description.
	 */
	protected $description = 'Seed the database with records for a specific or all modules';

	/**
	 * @var \Caffeinated\Modules\Modules
	 */
	protected $module;

	/**
	 * Create a new command instance.
	 *
	 * @param \Caffeinated\Modules\Modules $module
	 */
	public function __construct(Modules $module)
	{
		parent::__construct();

		$this->module = $module;
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function fire()
	{
		$module     = $this->argument('module');
		$moduleName = studly_case($module);

		if (isset($module)) {
			if (! $this->module->exists($module)) {
				return $this->error("Module [$moduleName] does not exist.");
			}

			if ($this->module->isEnabled($module)) {
				$this->seed($module);
			} elseif ($this->option('force')) {
				$this->seed($module);
			}

			return;
		} else {
			if ($this->option('force')) {
				$modules = $this->module->all();
			} else {
				$modules = $this->module->enabled();
			}

			foreach ($modules as $module) {
				$this->seed($module['slug']);
			}
		}
	}

	/**
	 * Seed the specific module.
	 *
	 * @param  string $module
	 * @return array
	 */
	protected function seed($module)
	{
		$params     = array();
		$moduleName = studly_case($module);
		$namespace  = $this->module->getNamespace();
		$rootSeeder = $moduleName.'DatabaseSeeder';
		$fullPath   = $namespace.$moduleName.'\Database\Seeds\\'.$rootSeeder;

		if (class_exists($fullPath)) {
			if ($this->option('class')) {
				$params['--class'] = $this->option('class');
			} else {
				$params['--class'] = $fullPath;
			}

			if ($option = $this->option('database')) {
				$params['--database'] = $option;
			}

	        if ($option = $this->option('force')) {
	            $params['--force'] = $option;
	        }

			$this->call('db:seed', $params);
		}
	}

	/**
	 * Get the console command arguments.
	 *
{'fraction_non_alphanumeric': 0.18189636637282305, 'fraction_numerical': 0.00043001505052676843, 'mean_word_length': 3.206148282097649, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '7149584', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1484, 'n_words': 313}