From 9d9320ed93e9aef0e089f3f7023d183d934139dc Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 12 Feb 2018 16:39:30 -0600 Subject: [PATCH] Do not pass second argument to `getAttribute()` Since the default is to return a `null`, which evaluates as false-y for purposes of conditionals, we can omit it. --- src/MethodNotAllowedMiddleware.php | 2 +- test/MethodNotAllowedMiddlewareTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MethodNotAllowedMiddleware.php b/src/MethodNotAllowedMiddleware.php index b2b70d8..0754a2f 100644 --- a/src/MethodNotAllowedMiddleware.php +++ b/src/MethodNotAllowedMiddleware.php @@ -42,7 +42,7 @@ public function __construct(ResponseInterface $responsePrototype) public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface { - $routeResult = $request->getAttribute(RouteResult::class, false); + $routeResult = $request->getAttribute(RouteResult::class); if (! $routeResult || ! $routeResult->isMethodFailure()) { return $handler->handle($request); } diff --git a/test/MethodNotAllowedMiddlewareTest.php b/test/MethodNotAllowedMiddlewareTest.php index ac5c124..cd13564 100644 --- a/test/MethodNotAllowedMiddlewareTest.php +++ b/test/MethodNotAllowedMiddlewareTest.php @@ -44,7 +44,7 @@ public function setUp() public function testDelegatesToHandlerIfNoRouteResultPresentInRequest() { - $this->request->getAttribute(RouteResult::class, false)->willReturn(false); + $this->request->getAttribute(RouteResult::class)->willReturn(null); $this->handler->handle(Argument::that([$this->request, 'reveal']))->will([$this->response, 'reveal']); $this->response->withStatus(Argument::any())->shouldNotBeCalled(); @@ -61,7 +61,7 @@ public function testDelegatesToHandlerIfRouteResultNotAMethodFailure() $result = $this->prophesize(RouteResult::class); $result->isMethodFailure()->willReturn(false); - $this->request->getAttribute(RouteResult::class, false)->will([$result, 'reveal']); + $this->request->getAttribute(RouteResult::class)->will([$result, 'reveal']); $this->handler->handle(Argument::that([$this->request, 'reveal']))->will([$this->response, 'reveal']); $this->response->withStatus(Argument::any())->shouldNotBeCalled(); @@ -79,7 +79,7 @@ public function testReturns405ResponseWithAllowHeaderIfResultDueToMethodFailure( $result->isMethodFailure()->willReturn(true); $result->getAllowedMethods()->willReturn(['GET', 'POST']); - $this->request->getAttribute(RouteResult::class, false)->will([$result, 'reveal']); + $this->request->getAttribute(RouteResult::class)->will([$result, 'reveal']); $this->handler->handle(Argument::that([$this->request, 'reveal']))->shouldNotBeCalled(); $this->response->withStatus(StatusCode::STATUS_METHOD_NOT_ALLOWED)->will([$this->response, 'reveal']);