<commit_before><?php
namespace King23\Http\Middleware\Whoops;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;

/**
 * Class Whoops
 * simple middleware to use whoops within king23 based apps
 *
 * this should also work with other psr-7 middlewars as long as they use
 * the request,response,callable-next signature
 *
 * @package King23\Whoops
 */
class Whoops
{
    /**
     * @param ServerRequestInterface $request
     * @param ResponseInterface $response
     * @param callable $next
     * @return ResponseInterface
     */
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response,callable $next)
    {
        try {
            $next($request, $response);
        } catch (\Exception $e){
            $whoops = $this->getWhoops();
            $body = $whoops->handleException($e);

            $response->getBody()->write($body);
            return $response->withStatus(500);
        }
        return $response;
    }

    /**
     * @return Run
     */
    protected function getWhoops()
    {<commit_msg>quickfix<commit_after><?php
namespace King23\Http\Middleware\Whoops;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;

/**
 * Class Whoops
 * simple middleware to use whoops within king23 based apps
 *
 * this should also work with other psr-7 middlewars as long as they use
 * the request,response,callable-next signature
 *
 * @package King23\Whoops
 */
class Whoops
{
    /**
     * @param ServerRequestInterface $request
     * @param ResponseInterface $response
     * @param callable $next
     * @return ResponseInterface
     */
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response,callable $next)
    {
        try {
            $response = $next($request, $response);
        } catch (\Exception $e){
            $whoops = $this->getWhoops();
            $body = $whoops->handleException($e);

            $response->getBody()->write($body);
            return $response->withStatus(500);
        }
        return $response;
    }

    /**
     * @return Run
     */
    protected function getWhoops()
    {
{'fraction_non_alphanumeric': 0.11213315812527376, 'fraction_numerical': 0.008760402978537012, 'mean_word_length': 2.7877280265339968, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '2263665', 'n_tokens_mistral': 651, 'n_tokens_neox': 638, 'n_words': 161}