<commit_before><?php

namespace PhpGitHooks\Command;

use PhpGitHooks\Application\CodeSniffer\CheckCodeStyleCodeSnifferPreCommitExecutor;
use PhpGitHooks\Application\PhpCsFixer\FixCodeStyleCsFixerPreCommitExecutor;
use PhpGitHooks\Container;
use PhpGitHooks\Infrastructure\Git\ExtractCommitedFiles;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class QualityCodeTool.
 */
class QualityCodeTool extends Application
{
    /** @var  OutputInterface */
    private $output;
    /** @var  array */
    private $files;
    /** @var  Container */
    private $container;
    /** @var  OutputHandler */
    private $outputTitleHandler;

    const PHP_FILES_IN_SRC = '/^src\/(.*)(\.php)$/';
    const JSON_FILES_IN_SRC = '/^src\/(.*)(\.json)$/';
    const COMPOSER_FILES = '/^composer\.(json|lock)$/';

    public function __construct()
    {
        $this->container = new Container();
        $this->outputTitleHandler = new OutputHandler();

        parent::__construct('Code Quality Tool');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     */
    public function doRun(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;

        $this->output->writeln('<fg=white;options=bold;bg=red>Pre-commit tool</fg=white;options=bold;bg=red>');
        $this->extractCommitFiles();

        $this->execute();

        $this->output->writeln(GoodJobLogo::paint());
    }

    private function extractCommitFiles()
    {
        $this->outputTitleHandler->setTitle('Fetching files');
        $this->output->write($this->outputTitleHandler->getTitle());

        $commitFiles = new ExtractCommitedFiles();

        $this->files = $commitFiles->getFiles();

        if ($this->existsFiles()) {
            $result = '0k';
        } else {
            $result = 'No files changed';
        }

        if ($this->existsFiles()) {
            $this->output->writeln($this->outputTitleHandler->getSuccessfulStepMessage($result));
        }
    }

    /**
     * @return array
     */
    private function processingFiles()
    {
        $files = [
            'php' => false,
            'composer' => false,
            'json' => false
        ];

        foreach ($this->files as $file) {
            if (true === (bool)preg_match(self::PHP_FILES_IN_SRC, $file)) {
                $files['php'] = true;
            }

            if (true === (bool)preg_match(self::COMPOSER_FILES, $file)) {
                $files['composer'] = true;
            }

            if (true === (bool)preg_match(self::JSON_FILES_IN_SRC, $file)) {
                $files['json'] = true;
            }
        }

        return $files;
    }

    private function execute()
    {
        if (true === $this->isProcessingAnyComposerFile()) {
            $this->container->get('check.composer.files.pre.commit.executor')
                ->run($this->output, $this->files);
        }

        if (true === $this->isProcessingAnyJsonFile()) {
            $this->container->get('check.json.syntax.pre.commit.executor')
                ->run($this->output, $this->files, self::JSON_FILES_IN_SRC);
        }

        if (true === $this->isProcessingAnyPhpFile()) {
            $this->container->get('check.php.syntax.lint.pre.commit.executor')
                ->run($this->output, $this->files);

            /** @var FixCodeStyleCsFixerPreCommitExecutor $csFixer */
            $csFixer = $this->container->get('fix.code.style.cs.fixer.pre.commit.executor');
            $csFixer->run($this->output, $this->files, self::PHP_FILES_IN_SRC);

            /** @var CheckCodeStyleCodeSnifferPreCommitExecutor $codeSniffer */
            $codeSniffer = $this->container->get('check.code.style.code.sniffer.pre.commit.executor');
            $codeSniffer->run($this->output, $this->files, self::PHP_FILES_IN_SRC);

            $this->container->get('check.php.mess.detection.pre.commit.executor')
                ->run($this->output, $this->files, self::PHP_FILES_IN_SRC);

            $this->container->get('unit.test.pre.commit.executor')->run($this->output);
        }
    }

    /**
     * @return bool
     */
    private function isProcessingAnyComposerFile()
    {
        $files = $this->processingFiles();

        return $files['composer'];
    }

    /**
     * @return bool
     */
    private function isProcessingAnyPhpFile()
    {
        $files = $this->processingFiles();

        return $files['php'];
    }

    /**
     * @return bool
     */
    private function isProcessingAnyJsonFile()
    {
        $files = $this->processingFiles();

        return $files['json'];
    }

    /**
     * @return bool
     */
    private function existsFiles()
    {
        var_dump($this->files); die;
        return count($this->files) > 1;
    }
}<commit_msg>count messages to commit<commit_after><?php

namespace PhpGitHooks\Command;

use PhpGitHooks\Application\CodeSniffer\CheckCodeStyleCodeSnifferPreCommitExecutor;
use PhpGitHooks\Application\PhpCsFixer\FixCodeStyleCsFixerPreCommitExecutor;
use PhpGitHooks\Container;
use PhpGitHooks\Infrastructure\Git\ExtractCommitedFiles;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class QualityCodeTool.
 */
class QualityCodeTool extends Application
{
    /** @var  OutputInterface */
    private $output;
    /** @var  array */
    private $files;
    /** @var  Container */
    private $container;
    /** @var  OutputHandler */
    private $outputTitleHandler;

    const PHP_FILES_IN_SRC = '/^src\/(.*)(\.php)$/';
    const JSON_FILES_IN_SRC = '/^src\/(.*)(\.json)$/';
    const COMPOSER_FILES = '/^composer\.(json|lock)$/';

    public function __construct()
    {
        $this->container = new Container();
        $this->outputTitleHandler = new OutputHandler();

        parent::__construct('Code Quality Tool');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     */
    public function doRun(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;

        $this->output->writeln('<fg=white;options=bold;bg=red>Pre-commit tool</fg=white;options=bold;bg=red>');
        $this->extractCommitFiles();

        $this->execute();

        $this->output->writeln(GoodJobLogo::paint());
    }

    private function extractCommitFiles()
    {
        $this->outputTitleHandler->setTitle('Fetching files');
        $this->output->write($this->outputTitleHandler->getTitle());

        $commitFiles = new ExtractCommitedFiles();

        $this->files = $commitFiles->getFiles();

        if ($this->existsFiles()) {
            $result = '0k';
        } else {
            $result = 'No files changed';
        }

        if ($this->existsFiles()) {
            $this->output->writeln($this->outputTitleHandler->getSuccessfulStepMessage($result));
        }
    }

    /**
     * @return array
     */
    private function processingFiles()
    {
        $files = [
            'php' => false,
            'composer' => false,
            'json' => false
        ];

        foreach ($this->files as $file) {
            if (true === (bool)preg_match(self::PHP_FILES_IN_SRC, $file)) {
                $files['php'] = true;
            }

            if (true === (bool)preg_match(self::COMPOSER_FILES, $file)) {
                $files['composer'] = true;
            }

            if (true === (bool)preg_match(self::JSON_FILES_IN_SRC, $file)) {
                $files['json'] = true;
            }
        }

        return $files;
    }

    private function execute()
    {
        if (true === $this->isProcessingAnyComposerFile()) {
            $this->container->get('check.composer.files.pre.commit.executor')
                ->run($this->output, $this->files);
        }

        if (true === $this->isProcessingAnyJsonFile()) {
            $this->container->get('check.json.syntax.pre.commit.executor')
                ->run($this->output, $this->files, self::JSON_FILES_IN_SRC);
        }

        if (true === $this->isProcessingAnyPhpFile()) {
            $this->container->get('check.php.syntax.lint.pre.commit.executor')
                ->run($this->output, $this->files);

            /** @var FixCodeStyleCsFixerPreCommitExecutor $csFixer */
            $csFixer = $this->container->get('fix.code.style.cs.fixer.pre.commit.executor');
            $csFixer->run($this->output, $this->files, self::PHP_FILES_IN_SRC);

            /** @var CheckCodeStyleCodeSnifferPreCommitExecutor $codeSniffer */
            $codeSniffer = $this->container->get('check.code.style.code.sniffer.pre.commit.executor');
            $codeSniffer->run($this->output, $this->files, self::PHP_FILES_IN_SRC);

            $this->container->get('check.php.mess.detection.pre.commit.executor')
                ->run($this->output, $this->files, self::PHP_FILES_IN_SRC);

            $this->container->get('unit.test.pre.commit.executor')->run($this->output);
        }
    }

    /**
     * @return bool
     */
    private function isProcessingAnyComposerFile()
    {
        $files = $this->processingFiles();

        return $files['composer'];
    }

    /**
     * @return bool
     */
    private function isProcessingAnyPhpFile()
    {
        $files = $this->processingFiles();

        return $files['php'];
    }

    /**
     * @return bool
     */
    private function isProcessingAnyJsonFile()
    {
        $files = $this->processingFiles();

        return $files['json'];
    }

    /**
     * @return bool
     */
    private function existsFiles()
    {
        return count($this->files) > 1 ? true : false;
    }
}
{'fraction_non_alphanumeric': 0.15807735483212573, 'fraction_numerical': 0.0004082049188692724, 'mean_word_length': 2.3734939759036147, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 146, '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': '923059', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2880, 'n_words': 439}