<commit_before><?php namespace Gliverich\Console\Commands;

/**
 *This class defines command options that are available for controller command
 *
 *@author <NAME> <<EMAIL>>
 *@copyright 2015 - 2020 <NAME>
 *@category Gliverich
 *@package Gliverich\Console\Command\Controller
 *@link https://github.com/gliver-mvc/console
 *@license http://opensource.org/licenses/MIT MIT License
 *@version 1.0.1
 */

use Drivers\Registry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Finder\Finder;

class Controller extends Command
{
    protected function configure()
    { 
        $this
            ->setName('controller')
            ->setDescription('Create controllers class and method templates, with associated views and models.')
            ->addArgument(
                'name',
                InputArgument::OPTIONAL,
                'What is the name of the controller class that you would like to create or modify?'
            )
            ->addArgument(
                    'methods',
                    InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
                    'What methods would you like to create  for this controller class (separate multiple method names with a space)?'
                )
            ->addOption(
               'init',
               null,
               InputOption::VALUE_NONE,
               'Specify this option when you are creating a controller class for the first time.'
            )
            ->addOption(
               'append',
               null,
               InputOption::VALUE_NONE,
               'Specify this option when you would like to modify a controller class that already exists.'
            )
            ->addOption(
               'complete',
               null,
               InputOption::VALUE_NONE,
               'Specify this option if you want to create a controller class together with associated model and views all in once command.'
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {

        //define array to contain all the controllers names
        $controllers = array();

        //get the controllers directory
        $controllerDirName = Registry::getConfig()['root'] . "/application/controllers";

        //create an instance of the Finder() class
        $finder = new Finder();

        //look for all files in this directory that comply with the rules defined
        $finder->files()->in($controllerDirName)->name('*.php')->contains('extends')->notContains('use Drivers\Controllers\Implementation');

        //loop through the result set getting the class names one at a time
        foreach ($finder as $file) {

            //add controller name to the controller array
            $controllers[substr($file->getRelativePathname(), 0, -14)] = array(

                'RealPath' => $file->getRealpath(),
                'ResultObject' => $file

            );

        }




        //check if a controller name was specified
        if( $name = $input->getArgument('name') ){

            //check if this is a create request
            if ($input->getOption('init')) {

                //create an instance of the FileSystem Class
                $FileSystem = new Filesystem();

                //check if this class already exists
                if( isset( $controllers[$name]) ){

                    //composer to send to output
                    $output->writeln('A Controller with this name already exists! Do you want to overwrite it?');

                }

                //check if a file with a similar name already exists
                elseif(   $FileSystem->exists( $controllerDirName . "/" . $name . "Controller.php") ){

                    //composer to send to output
                    $output->writeln('A File with similar name already exists! Do you want to overwrite it?');

                }

                //this is a completely new controller, go ahead and get parameters and create controller class
                else{


                }

            }

            //this is an append request
            elseif ( $input->getOption('append') ) {

                //first, begin by checking if this controller exists
                if( isset( $controllers[$name]) ){


                    //check if the methods to be appended we provided
                    if( $methods = $input->getArgument('methods') ){

                        //define variable to contain appended method contents
                        $methodAppendString = '';

                        //loop through the methods composing the method content
                        foreach($methods as $methodName ){


                        }

                        //get the result object for this controller from the controllers array
                        $ResultObject = $controllers[$name]['ResultObject'];

                        //get the contents of this file
                        $FileContents = $ResultObject->getContents();

                        //send this to the output
                        $output->writeln($FileContents);

                    }

                    //there were not methods provided to be appended, write error message to output
                    else{<commit_msg>Writing command to append method templates to a class<commit_after><?php namespace Gliverich\Console\Commands;

/**
 *This class defines command options that are available for controller command
 *
 *@author <NAME> <<EMAIL>>
 *@copyright 2015 - 2020 <NAME>
 *@category Gliverich
 *@package Gliverich\Console\Command\Controller
 *@link https://github.com/gliver-mvc/console
 *@license http://opensource.org/licenses/MIT MIT License
 *@version 1.0.1
 */

use Drivers\Registry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Finder\Finder;

class Controller extends Command
{
    protected function configure()
    { 
        $this
            ->setName('controller')
            ->setDescription('Create controllers class and method templates, with associated views and models.')
            ->addArgument(
                'name',
                InputArgument::OPTIONAL,
                'What is the name of the controller class that you would like to create or modify?'
            )
            ->addArgument(
                    'methods',
                    InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
                    'What methods would you like to create  for this controller class (separate multiple method names with a space)?'
                )
            ->addOption(
               'init',
               null,
               InputOption::VALUE_NONE,
               'Specify this option when you are creating a controller class for the first time.'
            )
            ->addOption(
               'append',
               null,
               InputOption::VALUE_NONE,
               'Specify this option when you would like to modify a controller class that already exists.'
            )
            ->addOption(
               'complete',
               null,
               InputOption::VALUE_NONE,
               'Specify this option if you want to create a controller class together with associated model and views all in once command.'
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {

        //define array to contain all the controllers names
        $controllers = array();

        //get the controllers directory
        $controllerDirName = Registry::getConfig()['root'] . "/application/controllers";

        //create an instance of the Finder() class
        $finder = new Finder();

        //create an instance of the FileSystem Class
        $FileSystem = new Filesystem();

        //look for all files in this directory that comply with the rules defined
        $finder->files()->in($controllerDirName)->name('*.php')->contains('extends')->notContains('use Drivers\Controllers\Implementation');

        //loop through the result set getting the class names one at a time
        foreach ($finder as $file) {

            //add controller name to the controller array
            $controllers[substr($file->getRelativePathname(), 0, -14)] = array(

                'RealPath' => $file->getRealpath(),
                'ResultObject' => $file

            );

        }




        //check if a controller name was specified
        if( $name = $input->getArgument('name') ){

            //check if this is a create request
            if ($input->getOption('init')) {

                //check if this class already exists
                if( isset( $controllers[$name]) ){

                    //composer to send to output
                    $output->writeln('A Controller with this name already exists! Do you want to overwrite it?');

                }

                //check if a file with a similar name already exists
                elseif(   $FileSystem->exists( $controllerDirName . "/" . $name . "Controller.php") ){

                    //composer to send to output
                    $output->writeln('A File with similar name already exists! Do you want to overwrite it?');

                }

                //this is a completely new controller, go ahead and get parameters and create controller class
                else{


                }

            }

            //this is an append request
            elseif ( $input->getOption('append') ) {

                //first, begin by checking if this controller exists
                if( isset( $controllers[$name]) ){


                    //check if the methods to be appended were provided
                    if( $methods = $input->getArgument('methods') ){

                        //compose method template code
                        $methodTemplateCode = "\n\t/**\n\t*Describe what this method does here...\n\t*\n\t*@param null\n\t*@return void\n\t*/\n\tpublic function ";
                        //define variable to contain appended method contents
                        $methodAppendString = '';

                        //loop through the methods composing the method content
                        foreach($methods as $methodName ){

                            //compose the method append string
                            $methodAppendString .= $methodTemplateCode . 'get' . ucfirst(strtolower($methodName)) . "() {\n\t\n\t\n\t}" . 
                                                    $methodTemplateCode . 'post' . ucfirst(strtolower($methodName) ). "() {\n\t\n\t\n\t} ";

                        } 

                        //get the result object for this controller from the controllers array
                        $ResultObject = $controllers[$name]['ResultObject'];

                        //get the contents of this file
                        $FileContents = $ResultObject->getContents();

                        //append new file contents
                        $FileContents .= $methodAppendString; 

                        //enclose this action in a try catch block to be able to handle errors
                        try {

                            //append contents to controller in style...
                            $FileSystem->dumpFile( $controllers[$name]['RealPath'], $FileContents);

                            //send this to the output
                            $output->writeln("Roger! Appending new methods to class successful!");

                        } 
                        catch (IOExceptionInterface $e) {

                            //send this to the output
                            $output->writeln("An error occured while appending methods to your controller class!");

                        }

                    }

                    //there were not methods provided to be appended, write error message to output
                    else{
{'fraction_non_alphanumeric': 0.08965791567223548, 'fraction_numerical': 0.0022275258552108194, 'mean_word_length': 1.6735431731178223, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 63, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5795197', 'n_tokens_mistral': 2940, 'n_tokens_neox': 2731, 'n_words': 987}