Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 24
GenerateView
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 24
 configure
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 execute
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 20
<?php
namespace Eywa\Console\Generate {
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputArgument;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    use Symfony\Component\Console\Style\SymfonyStyle;
    class GenerateView extends Command
    {
        protected static $defaultName = "make:view";
        protected function configure(): void
        {
            $this->setDescription('Generate a view')
                ->addArgument('view', InputArgument::REQUIRED, 'the view name')
                ->addArgument('dir', InputArgument::OPTIONAL, 'the view dir');
        }
        /**
         * @param InputInterface $input
         * @param OutputInterface $output
         *
         * @return int|void|null
         */
        public function execute(InputInterface $input, OutputInterface $output)
        {
            $io = new SymfonyStyle($input, $output);
            $io->title('Generation of the view');
            $dir = ucfirst(strval($input->getArgument('dir'))) ?? '';
            if (def($dir)) {
                if (!is_dir(base('app', 'Views', $dir))) {
                    mkdir(base('app', 'Views', $dir));
                }
            }
            $view = collect(explode('.', strval($input->getArgument('view'))))->first();
            append($view, '.html');
            $view = def($dir) ? base('app', 'Views', $dir, $view) : base('app', 'Views', $view);
            if (file_exists($view)) {
                $io->error(sprintf('The %s view already exist', $view));
                return 1;
            }
            if (touch($view)) {
                $io->success(
                    sprintf(
                        'The %s view has been generated successfully',
                        strval($input->getArgument('view'))
                    )
                );
                return 0;
            }
            $io->error(sprintf('The %s view generation has failed', strval($input->getArgument('view'))));
            return 1;
        }
    }
}