<commit_before><?php

namespace Stefanius\Brancher\Command;

use Guzzle\Http\Client;
use Stefanius\Brancher\Adapter\AdapterInterface;
use Stefanius\Brancher\Factory\AdapterFactory;
use Stefanius\Brancher\Issue\Issue;
use Stefanius\Slugifier\Manipulators\SlugManipulator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Yaml\Yaml;

abstract class BaseCommand extends Command
{
    /**
     * @return Client
     */
    protected function buildGuzzleClient()
    {
        return new Client();
    }

    /**
     * @return array
     */
    protected function getConfig()
    {
        return Yaml::parse(file_get_contents('/Users/sgrootveld/PhpstormProjects/brancher/.brancher'));
    }

    /**
     * @return AdapterInterface
     */
    protected function buildAdapter()
    {
        return AdapterFactory::Create($this->buildGuzzleClient(), $this->getConfig());
    }

    /**
     * @return SlugManipulator
     */
    protected function getSlugifier()
    {
        return new SlugManipulator();
    }

    /**
     * @param Issue $issue
     *
     * @return string
     */
    protected function getBranchSlug(Issue $issue)
    {
        return $this->getSlugifier()->manipulate($issue->getCode() . '-' . $issue->getTitle());
    }
    /**
     * @param Issue $issue
     *
     * @return Process
     */
    protected function getCreateBranchProcess(Issue $issue)
    {
        $slug = $this->getBranchSlug($issue);

        return new Process('git checkout -b ' . $slug);
    }

    /**
     * @param Issue $issue
     *
     * @return Process
     */
    protected function getBranchExistsProcess(Issue $issue)
    {
        $slug = $this->getBranchSlug($issue);

        return new Process('git rev-parse --verify ' . $slug);
    }

    /**
     * @param Issue $issue
     *
     * @return bool
     */
    protected function isBranchExists(Issue $issue)
    {
        $process = $this->getBranchExistsProcess($issue);
        $process->run();

        return strlen(trim($process->getErrorOutput())) === 0;
    }

    /**
     * @param Process $process
     *
     * @throws \Exception
     */
    protected function runProcess(Process $process)
    {
        $process->run();

        var_dump($process->getExitCode());
        if (strlen(trim($process->getErrorOutput())) > 0) {
            //throw new \Exception($process->getErrorOutput());
        }
    }
}<commit_msg>Improve errorchecking.<commit_after><?php

namespace Stefanius\Brancher\Command;

use Guzzle\Http\Client;
use Stefanius\Brancher\Adapter\AdapterInterface;
use Stefanius\Brancher\Factory\AdapterFactory;
use Stefanius\Brancher\Issue\Issue;
use Stefanius\Slugifier\Manipulators\SlugManipulator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Yaml\Yaml;

abstract class BaseCommand extends Command
{
    /**
     * @return Client
     */
    protected function buildGuzzleClient()
    {
        return new Client();
    }

    /**
     * @return array
     */
    protected function getConfig()
    {
        return Yaml::parse(file_get_contents('/Users/sgrootveld/PhpstormProjects/brancher/.brancher'));
    }

    /**
     * @return AdapterInterface
     */
    protected function buildAdapter()
    {
        return AdapterFactory::Create($this->buildGuzzleClient(), $this->getConfig());
    }

    /**
     * @return SlugManipulator
     */
    protected function getSlugifier()
    {
        return new SlugManipulator();
    }

    /**
     * @param Issue $issue
     *
     * @return string
     */
    protected function getBranchSlug(Issue $issue)
    {
        return $this->getSlugifier()->manipulate($issue->getCode() . '-' . $issue->getTitle());
    }
    /**
     * @param Issue $issue
     *
     * @return Process
     */
    protected function getCreateBranchProcess(Issue $issue)
    {
        $slug = $this->getBranchSlug($issue);

        return new Process('git checkout -b ' . $slug);
    }

    /**
     * @param Issue $issue
     *
     * @return Process
     */
    protected function getBranchExistsProcess(Issue $issue)
    {
        $slug = $this->getBranchSlug($issue);

        return new Process('git rev-parse --verify ' . $slug);
    }

    /**
     * @param Issue $issue
     *
     * @return bool
     */
    protected function isBranchExists(Issue $issue)
    {
        $process = $this->getBranchExistsProcess($issue);
        $process->run();

        return strlen(trim($process->getErrorOutput())) === 0;
    }

    /**
     * @param Process $process
     *
     * @throws \Exception
     */
    protected function runProcess(Process $process)
    {
        $process->run();

        if (strlen(trim($process->getErrorOutput())) > 0 && strpos($process->getErrorOutput(), 'fatal') !== false) {
            throw new \Exception($process->getErrorOutput());
        }
    }
}
{'fraction_non_alphanumeric': 0.13626194834248526, 'fraction_numerical': 0.0008135041692088672, 'mean_word_length': 2.427177700348432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '4432862', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1460, 'n_words': 269}