<commit_before><?php

namespace Obullo\Middleware;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

use Obullo\Router\Router;
use Laminas\Diactoros\Response\TextResponse;

class HttpMethodMiddleware implements MiddlewareInterface
{
	protected $router;

    /**
     * Constructor
     * 
     * @param Router     $router     router
     * @param Translator $translator translator
     */
    public function __construct(Router $router)
    {
        $this->router = $router;
    }

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
    {
    	$allowedMethods = $this->router->getMatchedRoute()
    		->getMethods();

    	if (! in_array($request->getMethod(), $allowedMethods)) {
		    $message = sprintf(
		        'Only Http %s Methods Allowed',
		        implode(', ', $allowedMethods)
		    );
		    return new TextResponse($message, 405);
		}
		return $handler->handle($request);
    }
}<commit_msg>Update HttpMethodMiddleware.php<commit_after><?php

namespace Obullo\Middleware;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

use Obullo\Router\Router;
use Laminas\Diactoros\Response\TextResponse;

class HttpMethodMiddleware implements MiddlewareInterface
{ 
	protected $router;
	
	/**
	* Constructor
	* 
	* @param Router     $router     router
	* @param Translator $translator translator
	*/
	public function __construct(Router $router)
	{
		$this->router = $router;
	}

	public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
	{
	$allowedMethods = $this->router->getMatchedRoute()
		->getMethods();

	if (! in_array($request->getMethod(), $allowedMethods)) {
		    $message = sprintf(
			'Only Http %s Methods Allowed',
			implode(', ', $allowedMethods)
		    );
		    return new TextResponse($message, 405);
		}
		return $handler->handle($request);
	}
}
{'fraction_non_alphanumeric': 0.11486169714017816, 'fraction_numerical': 0.0028129395218002813, 'mean_word_length': 4.033018867924528, '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': '7645820', 'n_tokens_mistral': 664, 'n_tokens_neox': 623, 'n_words': 129}