<commit_before><?php

namespace Sassnowski\Pipeline;


use InvalidArgumentException;
use RuntimeException;

class Pipeline
{
    /**
     * @var array
     */
    protected $steps;

    /**
     * @var mixed
     */
    protected $value;

    /**
     * Pipeline constructor.
     *
     * @param $value The value that should be piped through all steps.
     * @param array $steps
     */
    private function __construct($value = null, $steps = [])
    {
        $this->value = $value;
        $this->steps = $steps;
    }

    /**
     * Factory function to create a new pipeline with the provided initial value.
     * 
     * @param $init
     * @return static
     */
    static function pipe($init)
    {
        return new static($init);
    }

    /**
     * Creates a new pipeline without an initial value.
     * 
     * @return static
     */
    static function build()
    {
        return new static();
    }

    /**
     * Add a step to the pipeline.
     * 
     * @param $next The function that should be executed for this step.
     * @return $this
     */
    function through($next)
    {
        if (! is_callable($next))
        {
            throw new InvalidArgumentException("Unable to add step. All steps have to be callable.");
        }
        
        $newSteps = $this->steps;
        $newSteps[] = $next;
        
        return new static($this->value, $newSteps);
    }

    /**
     * Process the pipeline.
     *
     * @param null $value
     * @return mixed
     */
    function run($value = null)
    {
        $initial = $this->getValue($value);
        
        return array_reduce($this->steps, function ($acc, $next)<commit_msg>small typehinting fix<commit_after><?php

namespace Sassnowski\Pipeline;


use InvalidArgumentException;
use RuntimeException;

class Pipeline
{
    /**
     * @var array
     */
    protected $steps;

    /**
     * @var mixed
     */
    protected $value;

    /**
     * Pipeline constructor.
     *
     * @param mixed $value The value that should be piped through all steps.
     * @param array $steps
     */
    private function __construct($value = null, $steps = [])
    {
        $this->value = $value;
        $this->steps = $steps;
    }

    /**
     * Factory function to create a new pipeline with the provided initial value.
     * 
     * @param $init
     * @return static
     */
    static function pipe($init)
    {
        return new static($init);
    }

    /**
     * Creates a new pipeline without an initial value.
     * 
     * @return static
     */
    static function build()
    {
        return new static();
    }

    /**
     * Add a step to the pipeline.
     * 
     * @param callable $next The function that should be executed for this step.
     * @return $this
     */
    function through($next)
    {
        if (! is_callable($next))
        {
            throw new InvalidArgumentException("Unable to add step. All steps have to be callable.");
        }
        
        $newSteps = $this->steps;
        $newSteps[] = $next;
        
        return new static($this->value, $newSteps);
    }

    /**
     * Process the pipeline.
     *
     * @param null $value
     * @return mixed
     */
    function run($value = null)
    {
        $initial = $this->getValue($value);
        
        return array_reduce($this->steps, function ($acc, $next)
{'fraction_non_alphanumeric': 0.11701811701811701, 'fraction_numerical': 0.0, 'mean_word_length': 1.7629204265791631, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '1306454', 'n_tokens_mistral': 974, 'n_tokens_neox': 950, 'n_words': 285}