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 / 11
CleanDatabase
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 11
 configure
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 execute
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 8
<?php
namespace Eywa\Console\Database {
    use Eywa\Database\Base\Base;
    use Eywa\Exception\Kedavra;
    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 CleanDatabase extends Command
    {
        protected static $defaultName = 'db:clean';
        protected function configure(): void
        {
            $this->setDescription("Truncate all tables")
            ->addArgument('env', InputArgument::REQUIRED, 'The base environment');
        }
        /**
         * @param InputInterface $input
         * @param OutputInterface $output
         * @return int
         * @throws Kedavra
         */
        public function execute(InputInterface $input, OutputInterface $output)
        {
            $env = strval($input->getArgument('env'));
            not_in(['dev','prod','any'], $env, true, "Only dev, prod or any must be used");
            $io = new SymfonyStyle($input, $output);
            if ((new Base($env))->clean()) {
                $io->success('All tables are now empty');
                return 0;
            }
            $io->error('Failed to clean the database');
            return 1;
        }
    }
}