<commit_before><?php

namespace Monolyth\Http;

use Zend\Diactoros\Server;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response\SapiEmitter;
use Zend\Diactoros\Response\EmptyResponse;
use League\Pipeline\Pipeline;
use League\Pipeline\PipelineBuilder;
use Whoops\Run;
use Whoops\Handler\HandlerInterface;
use Monolyth\Stage;

class Controller
{
    protected $pipeline;
    private $whoops;
    private $caught;
    private $errors = [];

    public function __construct(Pipeline $pipeline = null)
    {
        $this->pipeline = new PipelineBuilder;
        if (isset($pipeline)) {
            $this->pipeline->add($pipeline);
        }
    }

    public function pipe(callable $stage)
    {
        $this->pipeline->add(new Stage($stage));
        return $this;
    }

    public function run(callable $errorHandler = null)
    {
        $request = ServerRequestFactory::fromGlobals();
        try {
            $this->pipeline->build()
                ->pipe(new Stage(function (ResponseInterface $response = null) {
                    $emitter = new SapiEmitter;
                    if (is_null($response)) {
                        $response = new EmptyResponse(404);
                    }
                    if (session_status() == PHP_SESSION_ACTIVE) {
                        session_write_close();
                    }
                    return $emitter->emit($response);
                }))
                ->process($request);
        } catch (Exception $e) {
            if (isset($errorHandler)) {
                $response = $errorHandler($e, $request);
                $emitter = new SapiEmitter;
                return $emitter->emit($response);
            } else {
                throw $e;<commit_msg>in this case too<commit_after><?php

namespace Monolyth\Http;

use Zend\Diactoros\Server;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response\SapiEmitter;
use Zend\Diactoros\Response\EmptyResponse;
use League\Pipeline\Pipeline;
use League\Pipeline\PipelineBuilder;
use Whoops\Run;
use Whoops\Handler\HandlerInterface;
use Monolyth\Stage;

class Controller
{
    protected $pipeline;
    private $whoops;
    private $caught;
    private $errors = [];

    public function __construct(Pipeline $pipeline = null)
    {
        $this->pipeline = new PipelineBuilder;
        if (isset($pipeline)) {
            $this->pipeline->add($pipeline);
        }
    }

    public function pipe(callable $stage)
    {
        $this->pipeline->add(new Stage($stage));
        return $this;
    }

    public function run(callable $errorHandler = null)
    {
        $request = ServerRequestFactory::fromGlobals();
        try {
            $this->pipeline->build()
                ->pipe(new Stage(function (ResponseInterface $response = null) {
                    $emitter = new SapiEmitter;
                    if (is_null($response)) {
                        $response = new EmptyResponse(404);
                    }
                    if (session_status() == PHP_SESSION_ACTIVE) {
                        session_write_close();
                    }
                    return $emitter->emit($response);
                }))
                ->process($request);
        } catch (Exception $e) {
            if (isset($errorHandler)) {
                $response = $errorHandler($e, $request);
                $emitter = new SapiEmitter;
                if (session_status() == PHP_SESSION_ACTIVE) {
                    session_write_close();
                }
                return $emitter->emit($response);
            } else {
                throw $e;
{'fraction_non_alphanumeric': 0.1111407249466951, 'fraction_numerical': 0.0015991471215351812, 'mean_word_length': 1.9206225680933853, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '3359587', 'n_tokens_mistral': 1038, 'n_tokens_neox': 988, 'n_words': 204}