<commit_before><?php

namespace CleverAge\ProcessBundle\Task;

use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
use CleverAge\ProcessBundle\Model\FinalizableTaskInterface;
use CleverAge\ProcessBundle\Model\ProcessState;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
 * Wait for defined inputs before passing an aggregated output.
 * Should have been a BlockingTask, but due to limitations in the current model, it's a hack using skips and finalize.
 * @see README.md:Known issues
 */
class InputAggregatorTask extends AbstractConfigurableTask implements FinalizableTaskInterface
{
    /** @var array */
    protected $inputs = [];

    /** @var bool */
    protected $isResolved;

    /**
     * Store inputs and once everything has been received, pass to next task (only once)
     *
     * @param ProcessState $state
     */
    public function execute(ProcessState $state)
    {
        $previousState = $state->getPreviousState();
        if (!$previousState || !$previousState->getTaskConfiguration()) {
            throw new \UnexpectedValueException("This task cannot be used without a previous task");
        }

        $inputCode = $this->getInputCode($state);
        if (array_key_exists($inputCode, $this->inputs)) {
            throw new \UnexpectedValueException("The output from input '{$inputCode}' has already been defined, please use an aggregator if you have an iterable output");
        }

        $this->inputs[$inputCode] = $state->getInput();

        if ($this->isResolved($state)) {
            $state->setOutput($this->inputs);
        } else {
            $state->setSkipped(true);
        }

    }

    /**
     * If the task have not been executed, something went wrong
     *
     * @param ProcessState $state
     */
    public function finalize(ProcessState $state)
    {
        if (!$this->isResolved($state)) {
            throw new \UnexpectedValueException("This task has not been resolved");
        }
    }

    /**
     * @param OptionsResolver $resolver
     */
    protected function configureOptions(OptionsResolver $resolver)<commit_msg>Allow the InputAggregatorTask to be processed more than once<commit_after><?php

namespace CleverAge\ProcessBundle\Task;

use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
use CleverAge\ProcessBundle\Model\FinalizableTaskInterface;
use CleverAge\ProcessBundle\Model\ProcessState;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
 * Wait for defined inputs before passing an aggregated output.
 * Should have been a BlockingTask, but due to limitations in the current model, it's a hack using skips and finalize.
 * @see README.md:Known issues
 */
class InputAggregatorTask extends AbstractConfigurableTask implements FinalizableTaskInterface
{
    /** @var array */
    protected $inputs = [];

    /**
     * Store inputs and once everything has been received, pass to next task
     * Once an output has been generated this task is reset, and may wait for another loop
     *
     * @param ProcessState $state
     */
    public function execute(ProcessState $state)
    {
        $previousState = $state->getPreviousState();
        if (!$previousState || !$previousState->getTaskConfiguration()) {
            throw new \UnexpectedValueException("This task cannot be used without a previous task");
        }

        $inputCode = $this->getInputCode($state);
        if (array_key_exists($inputCode, $this->inputs)) {
            throw new \UnexpectedValueException("The output from input '{$inputCode}' has already been defined, please use an aggregator if you have an iterable output");
        }

        $this->inputs[$inputCode] = $state->getInput();

        if ($this->isResolved($state)) {
            $state->setOutput($this->inputs);
            $this->inputs = [];
        } else {
            $state->setSkipped(true);
        }

    }

    /**
     * If there is pending inputs, something went wrong
     *
     * @param ProcessState $state
     */
    public function finalize(ProcessState $state)
    {
        if (!empty($this->inputs) && !$this->isResolved($state)) {
            throw new \UnexpectedValueException("This task has not been resolved");
        }
    }

    /**
     * @param OptionsResolver $resolver
     */
    protected function configureOptions(OptionsResolver $resolver)
{'fraction_non_alphanumeric': 0.10386918470750806, 'fraction_numerical': 0.0, 'mean_word_length': 3.04, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3192860', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1112, 'n_words': 341}