<commit_before><?php

namespace Psalm\Internal\ExecutionEnvironment;

use Psalm\SourceControl\Git\CommitInfo;
use Psalm\SourceControl\Git\GitInfo;
use Psalm\SourceControl\Git\RemoteInfo;

/**
 * Git repository info collector.
 *
 * @author <NAME> <<EMAIL>>
 */
class GitInfoCollector
{
    /**
     * Git command.
     *
     * @var SystemCommandExecutor
     */
    protected $executor;

    /**
     * Constructor.
     *
     * @param GitCommand $command Git command
     */
    public function __construct()
    {
        $this->executor = new SystemCommandExecutor();
    }

    // API

    /**
     * Collect git repository info.
     */
    public function collect() : GitInfo
    {
        $branch = $this->collectBranch();
        $commit = $this->collectCommit();
        $remotes = $this->collectRemotes();

        return new GitInfo($branch, $commit, $remotes);
    }

    /**
     * Collect branch name.
     *
     * @throws \RuntimeException
     */
    protected function collectBranch() : string
    {
        $branchesResult = $this->executor->execute('git branch');

        foreach ($branchesResult as $result) {
            if (strpos($result, '* ') === 0) {
                $exploded = explode('* ', $result, 2);

                return $exploded[1];
            }
        }

        throw new \RuntimeException();
    }

    /**
     * Collect commit info.
     *
     * @throws \RuntimeException
     */
    protected function collectCommit() : CommitInfo
    {
        $commitResult = $this->executor->execute("git log -1 --pretty=format:'%H%n%aN%n%ae%n%cN%n%ce%n%s'");

        if (count($commitResult) !== 6 || array_keys($commitResult) !== range(0, 5)) {
            throw new \RuntimeException();
        }

        if ($commitResult[0] === '\'') {
            $commitResult[0] = substr($commitResult[0], 1);
            $commitResult[5] = substr($commitResult[5], 0, -1);<commit_msg>Remove quotes in --pretty-format command<commit_after><?php

namespace Psalm\Internal\ExecutionEnvironment;

use Psalm\SourceControl\Git\CommitInfo;
use Psalm\SourceControl\Git\GitInfo;
use Psalm\SourceControl\Git\RemoteInfo;

/**
 * Git repository info collector.
 *
 * @author <NAME> <<EMAIL>>
 */
class GitInfoCollector
{
    /**
     * Git command.
     *
     * @var SystemCommandExecutor
     */
    protected $executor;

    /**
     * Constructor.
     *
     * @param GitCommand $command Git command
     */
    public function __construct()
    {
        $this->executor = new SystemCommandExecutor();
    }

    // API

    /**
     * Collect git repository info.
     */
    public function collect() : GitInfo
    {
        $branch = $this->collectBranch();
        $commit = $this->collectCommit();
        $remotes = $this->collectRemotes();

        return new GitInfo($branch, $commit, $remotes);
    }

    /**
     * Collect branch name.
     *
     * @throws \RuntimeException
     */
    protected function collectBranch() : string
    {
        $branchesResult = $this->executor->execute('git branch');

        foreach ($branchesResult as $result) {
            if (strpos($result, '* ') === 0) {
                $exploded = explode('* ', $result, 2);

                return $exploded[1];
            }
        }

        throw new \RuntimeException();
    }

    /**
     * Collect commit info.
     *
     * @throws \RuntimeException
     */
    protected function collectCommit() : CommitInfo
    {
        $commitResult = $this->executor->execute("git log -1 --pretty=format:%H%n%aN%n%ae%n%cN%n%ce%n%s");

        if (count($commitResult) !== 6 || array_keys($commitResult) !== range(0, 5)) {
            throw new \RuntimeException();
{'fraction_non_alphanumeric': 0.14821865651346205, 'fraction_numerical': 0.005983138428066358, 'mean_word_length': 2.1761658031088085, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '4262518', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1077, 'n_words': 226}