<commit_before><?php

namespace Nails\Common\Console\Command\Make;

use Nails\Common\Exception\NailsException;
use Nails\Common\Exception\Database\ConnectionException;
use Nails\Console\Command\BaseMaker;
use Nails\Components;
use Nails\Factory;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Model extends BaseMaker
{
    const SERVICE_TOKEN          = 'MODELS';
    const SERVICE_RESOURCE_TOKEN = 'RESOURCES';
    const RESOURCE_PATH          = NAILS_COMMON_PATH . 'resources/console/';
    const MODEL_PATH             = NAILS_APP_PATH . 'src/Model/';
    const MODEL_RESOURCE_PATH    = NAILS_APP_PATH . 'src/Resource/';
    const ADMIN_PATH             = NAILS_APP_PATH . 'application/modules/admin/controllers/';

    // --------------------------------------------------------------------------

    /**
     * Configure the command
     */
    protected function configure(): void
    {
        $this
            ->setName('make:model')
            ->setDescription('Creates a new App model')
            ->addArgument(
                'modelName',
                InputArgument::OPTIONAL,
                'Define the name of the model to create'
            )
            ->addOption(
                'skip-db',
                null,
                InputOption::VALUE_OPTIONAL,
                'Skip database table creation',
                false
            )
            ->addOption(
                'skip-seeder',
                null,
                InputOption::VALUE_OPTIONAL,
                'Skip seeder creation',
                false
            )
            ->addOption(
                'auto-detect',
                null,
                InputOption::VALUE_OPTIONAL,
                'Automatically build models from the database'
            );

        if (Components::exists('nails/module-admin')) {
            $this->addOption(
                'skip-admin',
                null,
                InputOption::VALUE_OPTIONAL,
                'Skip admin creation',
                true
            );
        }
    }

    // --------------------------------------------------------------------------

    /**
     * Executes the app
     *
     * @param  InputInterface  $oInput  The Input Interface provided by Symfony
     * @param  OutputInterface $oOutput The Output Interface provided by Symfony
     *
     * @return int
     */
    protected function execute(InputInterface $oInput, OutputInterface $oOutput): int
    {
        parent::execute($oInput, $oOutput);

        // --------------------------------------------------------------------------

        //  Get options
        $bSkipDb    = stringToBoolean($oInput->getOption('skip-db'));
        $bSkipAdmin = !Components::exists('nails/module-admin') || stringToBoolean($oInput->getOption('skip-admin'));

        // --------------------------------------------------------------------------

        //  Test database connection
        if (!$bSkipDb) {
            try {
                Factory::service('PDODatabase');
            } catch (ConnectionException $e) {
                return $this->abort(
                    self::EXIT_CODE_FAILURE,
                    [
                        'Failed to connect to the database.',
                        $e->getMessage(),
                    ]
                );
            } catch (\Exception $e) {
                return $this->abort(
                    self::EXIT_CODE_FAILURE,
                    [
                        'An exception occurred when connecting to the database.',
                        $e->getMessage(),
                    ]
                );
            }
        }

        // --------------------------------------------------------------------------

        try {
            $this
                /**
                 * Validate the services file for resources first, so that the corrcet
                 * values are set on the second call.
                 */
                ->validateServiceFile(static::SERVICE_RESOURCE_TOKEN)
                ->validateServiceFile()
                ->createPath(self::MODEL_PATH);
            if (!$bSkipAdmin) {
                $this->createPath(self::ADMIN_PATH);
            }
            $this->createModel();<commit_msg>fix: Ensuring Resource path is created<commit_after><?php

namespace Nails\Common\Console\Command\Make;

use Nails\Common\Exception\NailsException;
use Nails\Common\Exception\Database\ConnectionException;
use Nails\Console\Command\BaseMaker;
use Nails\Components;
use Nails\Factory;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Model extends BaseMaker
{
    const SERVICE_TOKEN          = 'MODELS';
    const SERVICE_RESOURCE_TOKEN = 'RESOURCES';
    const RESOURCE_PATH          = NAILS_COMMON_PATH . 'resources/console/';
    const MODEL_PATH             = NAILS_APP_PATH . 'src/Model/';
    const MODEL_RESOURCE_PATH    = NAILS_APP_PATH . 'src/Resource/';
    const ADMIN_PATH             = NAILS_APP_PATH . 'application/modules/admin/controllers/';

    // --------------------------------------------------------------------------

    /**
     * Configure the command
     */
    protected function configure(): void
    {
        $this
            ->setName('make:model')
            ->setDescription('Creates a new App model')
            ->addArgument(
                'modelName',
                InputArgument::OPTIONAL,
                'Define the name of the model to create'
            )
            ->addOption(
                'skip-db',
                null,
                InputOption::VALUE_OPTIONAL,
                'Skip database table creation',
                false
            )
            ->addOption(
                'skip-seeder',
                null,
                InputOption::VALUE_OPTIONAL,
                'Skip seeder creation',
                false
            )
            ->addOption(
                'auto-detect',
                null,
                InputOption::VALUE_OPTIONAL,
                'Automatically build models from the database'
            );

        if (Components::exists('nails/module-admin')) {
            $this->addOption(
                'skip-admin',
                null,
                InputOption::VALUE_OPTIONAL,
                'Skip admin creation',
                true
            );
        }
    }

    // --------------------------------------------------------------------------

    /**
     * Executes the app
     *
     * @param  InputInterface  $oInput  The Input Interface provided by Symfony
     * @param  OutputInterface $oOutput The Output Interface provided by Symfony
     *
     * @return int
     */
    protected function execute(InputInterface $oInput, OutputInterface $oOutput): int
    {
        parent::execute($oInput, $oOutput);

        // --------------------------------------------------------------------------

        //  Get options
        $bSkipDb    = stringToBoolean($oInput->getOption('skip-db'));
        $bSkipAdmin = !Components::exists('nails/module-admin') || stringToBoolean($oInput->getOption('skip-admin'));

        // --------------------------------------------------------------------------

        //  Test database connection
        if (!$bSkipDb) {
            try {
                Factory::service('PDODatabase');
            } catch (ConnectionException $e) {
                return $this->abort(
                    self::EXIT_CODE_FAILURE,
                    [
                        'Failed to connect to the database.',
                        $e->getMessage(),
                    ]
                );
            } catch (\Exception $e) {
                return $this->abort(
                    self::EXIT_CODE_FAILURE,
                    [
                        'An exception occurred when connecting to the database.',
                        $e->getMessage(),
                    ]
                );
            }
        }

        // --------------------------------------------------------------------------

        try {
            $this
                /**
                 * Validate the services file for resources first, so that the corrcet
                 * values are set on the second call.
                 */
                ->validateServiceFile(static::SERVICE_RESOURCE_TOKEN)
                ->validateServiceFile()
                ->createPath(self::MODEL_PATH)
                ->createPath(self::MODEL_RESOURCE_PATH);
            if (!$bSkipAdmin) {
                $this->createPath(self::ADMIN_PATH);
            }
            $this->createModel();
{'fraction_non_alphanumeric': 0.17256090715167846, 'fraction_numerical': 0.0, 'mean_word_length': 1.1610868510431829, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '2545837', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2039, 'n_words': 425}