<commit_before><?php
/**
 * @package: chapi
 *
 * @author:  msiebeneicher
 * @since:   2015-09-20
 *
 * @link:    http://
 */

namespace Chapi\Commands;

use Chapi\Commands\AbstractCommand;
use Chapi\Component\Command\JobUtils;
use Chapi\Entity\Chronos\JobEntity;
use Chapi\Service\JobRepository\JobEntityValidatorServiceInterface;
use Chapi\Service\JobRepository\JobRepositoryInterface;

class ValidationCommand extends AbstractCommand
{

    /**
     * @var array[]
     */
    private $aInvalidJobs = [];

    /**
     * Configures the current command.
     */
    protected function configure()
    {
        $this->setName('validate')
            ->setDescription('Validate local jobs')
        ;

        JobUtils::configureJobNamesArgument($this, 'Jobs to validate');
    }

    /**
     * @inheritDoc
     */
    protected function process()
    {
        $_aJobNames = JobUtils::getJobNames($this->oInput, $this);
        $_aJobsToValidate = (JobUtils::isWildcard($_aJobNames))
            ? $this->getLocalJobs()
            : $_aJobNames
        ;

        if ($this->hasInvalidJobs($_aJobsToValidate))
        {
            $this->oOutput->writeln("<comment>Founded invalid jobs:</comment>\n");

            foreach ($this->getInvalidJobsByJobNames($_aJobsToValidate) as $_sJobName => $_aInvalidProperties)
            {
                $this->printInvalidJobProperties($_sJobName, $_aInvalidProperties);
            }

            return 1;
        }

        //else
        $this->oOutput->writeln("<info>All checked jobs looks valid</info>");
        return 0;
    }

    /**
     * @param string[] $aJobs
     * @return bool
     */
    private function hasInvalidJobs(array $aJobs)
    {
        $_aInvalidJobs = $this->getInvalidJobsByJobNames($aJobs);
        return (count($_aInvalidJobs) > 0);
    }

    /**
     * @param array $aJobs
     * @return array
     */
    private function getInvalidJobsByJobNames(array $aJobs)
    {
        $_sKey = md5(implode('.', $aJobs));

        if (isset($this->aInvalidJobs[$_sKey]))
        {
            return $this->aInvalidJobs[$_sKey];
        }

        $_aInvalidJobs = [];<commit_msg>fix not require double quotes<commit_after><?php
/**
 * @package: chapi
 *
 * @author:  msiebeneicher
 * @since:   2015-09-20
 *
 * @link:    http://
 */

namespace Chapi\Commands;

use Chapi\Commands\AbstractCommand;
use Chapi\Component\Command\JobUtils;
use Chapi\Entity\Chronos\JobEntity;
use Chapi\Service\JobRepository\JobEntityValidatorServiceInterface;
use Chapi\Service\JobRepository\JobRepositoryInterface;

class ValidationCommand extends AbstractCommand
{

    /**
     * @var array[]
     */
    private $aInvalidJobs = [];

    /**
     * Configures the current command.
     */
    protected function configure()
    {
        $this->setName('validate')
            ->setDescription('Validate local jobs')
        ;

        JobUtils::configureJobNamesArgument($this, 'Jobs to validate');
    }

    /**
     * @inheritDoc
     */
    protected function process()
    {
        $_aJobNames = JobUtils::getJobNames($this->oInput, $this);
        $_aJobsToValidate = (JobUtils::isWildcard($_aJobNames))
            ? $this->getLocalJobs()
            : $_aJobNames
        ;

        if ($this->hasInvalidJobs($_aJobsToValidate))
        {
            $this->oOutput->writeln("<comment>Founded invalid jobs:</comment>\n");

            foreach ($this->getInvalidJobsByJobNames($_aJobsToValidate) as $_sJobName => $_aInvalidProperties)
            {
                $this->printInvalidJobProperties($_sJobName, $_aInvalidProperties);
            }

            return 1;
        }

        //else
        $this->oOutput->writeln('<info>All checked jobs looks valid</info>');
        return 0;
    }

    /**
     * @param string[] $aJobs
     * @return bool
     */
    private function hasInvalidJobs(array $aJobs)
    {
        $_aInvalidJobs = $this->getInvalidJobsByJobNames($aJobs);
        return (count($_aInvalidJobs) > 0);
    }

    /**
     * @param array $aJobs
     * @return array
     */
    private function getInvalidJobsByJobNames(array $aJobs)
    {
        $_sKey = md5(implode('.', $aJobs));

        if (isset($this->aInvalidJobs[$_sKey]))
        {
            return $this->aInvalidJobs[$_sKey];
        }

        $_aInvalidJobs = [];
{'fraction_non_alphanumeric': 0.13506012950971322, 'fraction_numerical': 0.005550416281221091, 'mean_word_length': 2.3449342614075794, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 43, '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': '5267324', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1306, 'n_words': 220}