<commit_before><?php
/**
 * Copyright (C) 2015 <NAME>
 *
 * Defines the pipeline
 */
namespace Opulence\Pipelines;
use Closure;
use Opulence\IoC\IoCException;
use Opulence\IoC\IContainer;

class Pipeline implements IPipeline
{
    /** @var IContainer The dependency injection container to use */
    private $container;
    /** @var array The list of stages to send input through */
    private $stages = [];
    /** @var string The method to call if the stages are not closures */
    private $methodToCall = null;

    /**
     * @param IContainer $container The dependency injection container to use
     * @param Closure[]|array $stages The list of stages to send input through
     * @param string $methodToCall The method to call if the pipes are not closures
     */
    public function __construct(IContainer $container, array $stages, $methodToCall = null)
    {
        $this->container = $container;
        $this->setStages($stages, $methodToCall);
    }

    /**
     * {@inheritdoc}
     */
    public function send($input, Closure $callback = null)
    {
        return call_user_func(
            array_reduce(
                array_reverse($this->stages),
                $this->createStageCallback(),
                function ($input) use ($callback)
                {
                    if($callback === null)
                    {
                        return $input;
                    }

                    return call_user_func($callback, $input);
                }
            ),
            $input
        );
    }

    /**
     * {@inheritdoc}
     */
    public function setStages(array $stages, $methodToCall = null)
    {
        $this->stages = $stages;
        $this->methodToCall = $methodToCall;
    }

    /**
     * Creates a callback for an individual stage
     *
     * @return Closure The callback
     * @throws PipelineException Thrown if there was a problem creating a stage
     */
    private function createStageCallback()
    {
        return function ($stages, $stage)
        {
            return function ($input) use ($stages, $stage)
            {
                if($stage instanceof Closure)
                {
                    return call_user_func($stage, $input, $stages);
                }
                else
                {
                    if($this->methodToCall === null)
                    {
                        throw new PipelineException("Method must not be null");<commit_msg>Separated ViewFactory into several subclasses, renamed all "{@inheritdoc}" PHPDoc to "@inheritdoc"<commit_after><?php
/**
 * Copyright (C) 2015 <NAME>
 *
 * Defines the pipeline
 */
namespace Opulence\Pipelines;
use Closure;
use Opulence\IoC\IoCException;
use Opulence\IoC\IContainer;

class Pipeline implements IPipeline
{
    /** @var IContainer The dependency injection container to use */
    private $container;
    /** @var array The list of stages to send input through */
    private $stages = [];
    /** @var string The method to call if the stages are not closures */
    private $methodToCall = null;

    /**
     * @param IContainer $container The dependency injection container to use
     * @param Closure[]|array $stages The list of stages to send input through
     * @param string $methodToCall The method to call if the pipes are not closures
     */
    public function __construct(IContainer $container, array $stages, $methodToCall = null)
    {
        $this->container = $container;
        $this->setStages($stages, $methodToCall);
    }

    /**
     * @inheritdoc
     */
    public function send($input, Closure $callback = null)
    {
        return call_user_func(
            array_reduce(
                array_reverse($this->stages),
                $this->createStageCallback(),
                function ($input) use ($callback)
                {
                    if($callback === null)
                    {
                        return $input;
                    }

                    return call_user_func($callback, $input);
                }
            ),
            $input
        );
    }

    /**
     * @inheritdoc
     */
    public function setStages(array $stages, $methodToCall = null)
    {
        $this->stages = $stages;
        $this->methodToCall = $methodToCall;
    }

    /**
     * Creates a callback for an individual stage
     *
     * @return Closure The callback
     * @throws PipelineException Thrown if there was a problem creating a stage
     */
    private function createStageCallback()
    {
        return function ($stages, $stage)
        {
            return function ($input) use ($stages, $stage)
            {
                if($stage instanceof Closure)
                {
                    return call_user_func($stage, $input, $stages);
                }
                else
                {
                    if($this->methodToCall === null)
                    {
                        throw new PipelineException("Method must not be null");
{'fraction_non_alphanumeric': 0.09821964392878575, 'fraction_numerical': 0.0016003200640128026, 'mean_word_length': 1.7427317608337904, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '6362677', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1263, 'n_words': 387}