<commit_before><?php

namespace Smartbox\Integration\FrameworkBundle\Command;


use Smartbox\Integration\FrameworkBundle\Connectors\ConnectorInterface;
use Smartbox\Integration\FrameworkBundle\Routing\InternalRouter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\ArrayInput;
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\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouterInterface;

class ConnectorInfoCommand extends ContainerAwareCommand {

    protected function execute(InputInterface $input, OutputInterface $output){
        $connectorId = $input->getArgument('connector_id');
        $routerConnectors = $this->getContainer()->get('smartesb.router.connectors');

        if($connectorId){
            $connectors = array($connectorId);
        }else{
            $connectors = array_reduce($routerConnectors->getRouteCollection()->all(), function(array $res, Route $route){
                $connectorId = $route->getDefault(InternalRouter::KEY_CONNECTOR);
                if(!in_array($connectorId,$res)){
                    $res[] = substr($connectorId,1);
                }
                return $res;
            }, array());
        }
        $connectors = array_unique($connectors);

        foreach($connectors as $id){
            $this->explainConnector($id,$input,$output);
        }

    }

    protected function explainConnector($connectorId, $input, $output){
        $routerConnectors = $this->getContainer()->get('smartesb.router.connectors');

        /** @var ConnectorInterface $connector */
        $connector = $this->getContainer()->get($connectorId);
        $class = get_class($connector);
        $defaults = $connector->getDefaultOptions();

        $optionsExplained = '';

        foreach ($connector->getAvailableOptions() as $key => list($description, $possibleOptions)) {
            $optionsExplained.= "\n";
            $optionsExplained .= "\t- <comment>$key: </comment><info>$description</info>\n";

            if(array_key_exists($key,$defaults)){
                $default = $defaults[$key];
                $optionsExplained .= "\t\t- <comment>Default: </comment><info>$default</info>\n";
            }

            if(!empty($possibleOptions)){
                $optionsExplained .= "\t\t- <comment>Possible values: </comment>\n";<commit_msg>Fixed small issue in connectors info command<commit_after><?php

namespace Smartbox\Integration\FrameworkBundle\Command;


use Smartbox\Integration\FrameworkBundle\Connectors\ConnectorInterface;
use Smartbox\Integration\FrameworkBundle\Routing\InternalRouter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\ArrayInput;
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\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouterInterface;

class ConnectorInfoCommand extends ContainerAwareCommand {

    protected function execute(InputInterface $input, OutputInterface $output){
        $connectorId = $input->getArgument('connector_id');
        $routerConnectors = $this->getContainer()->get('smartesb.router.connectors');

        if($connectorId){
            $connectors = array($connectorId);
        }else{
            $connectors = array_reduce($routerConnectors->getRouteCollection()->all(), function(array $res, Route $route){
                $connectorId = $route->getDefault(InternalRouter::KEY_CONNECTOR);
                if(!in_array($connectorId,$res)){
                    $res[] = substr($connectorId,1);
                }
                return $res;
            }, array());
        }
        $connectors = array_unique($connectors);

        foreach($connectors as $id){
            $this->explainConnector($id,$input,$output);
        }

    }

    protected function explainConnector($connectorId, $input, $output){
        $routerConnectors = $this->getContainer()->get('smartesb.router.connectors');

        /** @var ConnectorInterface $connector */
        $connector = $this->getContainer()->get($connectorId);
        $class = get_class($connector);
        $defaults = $connector->getDefaultOptions();

        $optionsExplained = '';

        foreach ($connector->getAvailableOptions() as $key => list($description, $possibleOptions)) {
            $optionsExplained.= "\n";
            $optionsExplained .= "\t- <comment>$key: </comment><info>$description</info>\n";

            if(array_key_exists($key,$defaults)){
                $default = var_export($defaults[$key],true);
                $optionsExplained .= "\t\t- <comment>Default: </comment><info>$default</info>\n";
            }

            if(!empty($possibleOptions)){
                $optionsExplained .= "\t\t- <comment>Possible values: </comment>\n";
{'fraction_non_alphanumeric': 0.13488286969253294, 'fraction_numerical': 0.00036603221083455345, 'mean_word_length': 3.417946645109135, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 51, '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': '4417598', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1401, 'n_words': 223}