<commit_before><?php

namespace Thruster\Component\HttpMiddleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
 * Class RequestMiddlewares
 *
 * @package Thruster\Component\HttpMiddleware
 * @author  <NAME> <<EMAIL>>
 */
class RequestMiddlewares
{
    /**
     * @var Middlewares
     */
    protected $preMiddlewares;

    /**
     * @var Middlewares
     */
    protected $postMiddlewares;

    /**
     * @return Middlewares
     */
    public function getPreMiddlewares() : Middlewares
    {
        if ($this->preMiddlewares) {
            return $this->preMiddlewares;
        }
        
        $this->preMiddlewares = new Middlewares()  ;
        
        return $this->preMiddlewares;
    }

    /**
     * @param Middlewares $preMiddlewares
     *
     * @return $this
     */
    public function setPreMiddlewares(Middlewares $preMiddlewares)
    {
        $this->preMiddlewares = $preMiddlewares;

        return $this;
    }

    /**
     * @return Middlewares
     */
    public function getPostMiddlewares() : Middlewares
    {
        if ($this->postMiddlewares) {
            return $this->postMiddlewares;
        }
        
        $this->postMiddlewares = new Middlewares();
        
        return $this->postMiddlewares;
    }

    /**
     * @param Middlewares $postMiddlewares
     *
     * @return $this
     */
    public function setPostMiddlewares(Middlewares $postMiddlewares)
    {
        $this->postMiddlewares = $postMiddlewares;

        return $this;
    }

    /**
     * @param callable $middleware
     *
     * @return $this
     */
    public function pre(callable $middleware)
    {
        $this->getPreMiddlewares()->add($middleware);

        return $this;
    }

    /**
     * @param callable $middleware
     *
     * @return $this
     */
    public function post(callable $middleware)
    {
        $this->getPostMiddlewares()->add($middleware);

        return $this;
    }

    /**
     * @param ServerRequestInterface $request
     * @param ResponseInterface      $response
     * @param callable               $requestHandler
     * @param callable               $next
     *
     * @return ResponseInterface
     */
    public function __invoke(
        ServerRequestInterface $request,
        ResponseInterface $response,
        callable $requestHandler = null,
        callable $next = null
    ) : ResponseInterface
    {
        return $this->preMiddlewares->__invoke(
            $request,
            $response,
            function (ServerRequestInterface $request, ResponseInterface $response) use ($requestHandler, $next) {
                if (null !== $requestHandler) {
                    $response = $requestHandler($request, $response);
                }

                return $this->postMiddlewares->__invoke($request, $response, $next);
            }
        );
    }
}<commit_msg>Fixed property to method<commit_after><?php

namespace Thruster\Component\HttpMiddleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
 * Class RequestMiddlewares
 *
 * @package Thruster\Component\HttpMiddleware
 * @author  <NAME> <<EMAIL>>
 */
class RequestMiddlewares
{
    /**
     * @var Middlewares
     */
    protected $preMiddlewares;

    /**
     * @var Middlewares
     */
    protected $postMiddlewares;

    /**
     * @return Middlewares
     */
    public function getPreMiddlewares() : Middlewares
    {
        if ($this->preMiddlewares) {
            return $this->preMiddlewares;
        }
        
        $this->preMiddlewares = new Middlewares()  ;
        
        return $this->preMiddlewares;
    }

    /**
     * @param Middlewares $preMiddlewares
     *
     * @return $this
     */
    public function setPreMiddlewares(Middlewares $preMiddlewares)
    {
        $this->preMiddlewares = $preMiddlewares;

        return $this;
    }

    /**
     * @return Middlewares
     */
    public function getPostMiddlewares() : Middlewares
    {
        if ($this->postMiddlewares) {
            return $this->postMiddlewares;
        }
        
        $this->postMiddlewares = new Middlewares();
        
        return $this->postMiddlewares;
    }

    /**
     * @param Middlewares $postMiddlewares
     *
     * @return $this
     */
    public function setPostMiddlewares(Middlewares $postMiddlewares)
    {
        $this->postMiddlewares = $postMiddlewares;

        return $this;
    }

    /**
     * @param callable $middleware
     *
     * @return $this
     */
    public function pre(callable $middleware)
    {
        $this->getPreMiddlewares()->add($middleware);

        return $this;
    }

    /**
     * @param callable $middleware
     *
     * @return $this
     */
    public function post(callable $middleware)
    {
        $this->getPostMiddlewares()->add($middleware);

        return $this;
    }

    /**
     * @param ServerRequestInterface $request
     * @param ResponseInterface      $response
     * @param callable               $requestHandler
     * @param callable               $next
     *
     * @return ResponseInterface
     */
    public function __invoke(
        ServerRequestInterface $request,
        ResponseInterface $response,
        callable $requestHandler = null,
        callable $next = null
    ) : ResponseInterface
    {
        return $this->getPreMiddlewares()->__invoke(
            $request,
            $response,
            function (ServerRequestInterface $request, ResponseInterface $response) use ($requestHandler, $next) {
                if (null !== $requestHandler) {
                    $response = $requestHandler($request, $response);
                }

                return $this->getPostMiddlewares()->__invoke($request, $response, $next);
            }
        );
    }
}
{'fraction_non_alphanumeric': 0.11090128755364807, 'fraction_numerical': 0.0, 'mean_word_length': 1.9663951120162932, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 45, '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': '3798586', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1646, 'n_words': 311}