<commit_before><?php
/**
 * @author <NAME> <<EMAIL>>
 * @copyright Zicht online <http://zicht.nl>
 */

namespace Zicht\Tool\Container;

use \Symfony\Component\Process\Process;

/**
 * Runs the commands in the shell.
 */
class Executor
{
    /**
     * Constructor
     *
     * @param Container $container
     */
    public function __construct(Container $container)
    {
        $this->container = $container;
    }


    /**
     * Executes the passed command line in the shell.
     *
     * @param string $cmd
     * @param null &$captureOutput
     * @return int
     *
     * @throws ExecutionAbortedException
     * @throws \UnexpectedValueException
     */
    public function execute($cmd, &$captureOutput = null)
    {
        $ret = 0;
        if ($this->container->resolve('interactive')) {
            passthru($cmd, $ret);
        } else {
            $process = $this->createProcess();
            $process->setStdin($cmd);
            if (null !== $captureOutput) {
                $process->run(function($type, $data) use(&$captureOutput) {
                    $captureOutput .= $data;
                });
            } else {
                $process->run(array($this, 'processCallback'));
            }
            $ret = $process->getExitCode();
        }
        if ($ret != 0) {
            if ($ret == Container::ABORT_EXIT_CODE) {
                throw new ExecutionAbortedException("Command '$cmd' was aborted");
            } else {
                throw new \UnexpectedValueException("Command '$cmd' failed with exit code {$ret}");
            }
        }
        return $ret;
    }


    /**
     * Create the process instance to use for non-interactive handling
     *
     * @return \Symfony\Component\Process\Process
     */<commit_msg>added a cast to the exit code.<commit_after><?php
/**
 * @author <NAME> <<EMAIL>>
 * @copyright Zicht online <http://zicht.nl>
 */

namespace Zicht\Tool\Container;

use \Symfony\Component\Process\Process;

/**
 * Runs the commands in the shell.
 */
class Executor
{
    /**
     * Constructor
     *
     * @param Container $container
     */
    public function __construct(Container $container)
    {
        $this->container = $container;
    }


    /**
     * Executes the passed command line in the shell.
     *
     * @param string $cmd
     * @param null &$captureOutput
     * @return int
     *
     * @throws ExecutionAbortedException
     * @throws \UnexpectedValueException
     */
    public function execute($cmd, &$captureOutput = null)
    {
        $ret = 0;
        if ($this->container->resolve('interactive')) {
            passthru($cmd, $ret);
        } else {
            $process = $this->createProcess();
            $process->setStdin($cmd);
            if (null !== $captureOutput) {
                $process->run(function($type, $data) use(&$captureOutput) {
                    $captureOutput .= $data;
                });
            } else {
                $process->run(array($this, 'processCallback'));
            }
            $ret = $process->getExitCode();
        }
        if ($ret != 0) {
            if ((int)$ret == Container::ABORT_EXIT_CODE) {
                throw new ExecutionAbortedException("Command '$cmd' was aborted");
            } else {
                throw new \UnexpectedValueException("Command '$cmd' failed with exit code {$ret}");
            }
        }
        return $ret;
    }


    /**
     * Create the process instance to use for non-interactive handling
     *
     * @return \Symfony\Component\Process\Process
     */
{'fraction_non_alphanumeric': 0.1356741573033708, 'fraction_numerical': 0.0011235955056179776, 'mean_word_length': 1.8397129186602872, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, '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': '4316796', 'n_tokens_mistral': 997, 'n_tokens_neox': 972, 'n_words': 232}