From fb18d2ee1ea82a2a89364ea595ac808504f2db40 Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Mon, 10 Aug 2020 07:09:37 -0400 Subject: [PATCH] Code style fixes --- .php_cs.dist | 2 -- src/Message/ServerRequest.php | 9 ++++-- src/Message/Uri.php | 2 +- src/Routing/Route/TemplateRoute.php | 2 -- src/Routing/Router.php | 5 ++- src/Server.php | 12 +++++-- test/tests/integration/RoutingTest.php | 32 +++++++++++++------ .../tests/unit/Dispatching/DispatcherTest.php | 6 ++-- test/tests/unit/Message/MessageTest.php | 6 ++-- .../unit/Routing/Route/MethodMapTest.php | 6 ++-- test/tests/unit/Routing/Route/RouteTest.php | 4 ++- test/tests/unit/Routing/RouterTest.php | 5 +-- 12 files changed, 62 insertions(+), 29 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 953b9d1..989dd81 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -7,9 +7,7 @@ $finder = PhpCsFixer\Finder::create() return PhpCsFixer\Config::create() ->setFinder($finder) - ->setRiskyAllowed(true) ->setRules([ '@PSR2' => true, - 'strict_param' => true, 'array_syntax' => ['syntax' => 'short'], ]); diff --git a/src/Message/ServerRequest.php b/src/Message/ServerRequest.php index 8e8e458..ba64930 100644 --- a/src/Message/ServerRequest.php +++ b/src/Message/ServerRequest.php @@ -195,7 +195,8 @@ class ServerRequest extends Request implements ServerRequestInterface { if (!$this->isValidUploadedFilesTree($uploadedFiles)) { throw new \InvalidArgumentException( - "withUploadedFiles expects an array tree with UploadedFileInterface leaves."); + "withUploadedFiles expects an array tree with UploadedFileInterface leaves." + ); } $request = clone $this; @@ -413,7 +414,11 @@ class ServerRequest extends Request implements ServerRequestInterface } else { // All expected keys are present and are not arrays. This is an uploaded file. $uploadedFile = new UploadedFile( - $value["name"], $value["type"], $value["size"], $value["tmp_name"], $value["error"] + $value["name"], + $value["type"], + $value["size"], + $value["tmp_name"], + $value["error"] ); $branch[$name] = $uploadedFile; } diff --git a/src/Message/Uri.php b/src/Message/Uri.php index 78007b8..4574e56 100644 --- a/src/Message/Uri.php +++ b/src/Message/Uri.php @@ -130,7 +130,7 @@ class Uri implements UriInterface $port = $this->getPort(); if ($port !== null) { $scheme = $this->getScheme(); - if (($scheme === "http" && $port !== 80 ) || ($scheme === "https" && $port !== 443)) { + if (($scheme === "http" && $port !== 80) || ($scheme === "https" && $port !== 443)) { $authority .= ":" . $port; } } diff --git a/src/Routing/Route/TemplateRoute.php b/src/Routing/Route/TemplateRoute.php index 9396f11..d2fb3a5 100644 --- a/src/Routing/Route/TemplateRoute.php +++ b/src/Routing/Route/TemplateRoute.php @@ -69,7 +69,6 @@ class TemplateRoute extends Route // Store named captures to the variables. foreach ($keys as $key) { - $value = $matches[$key]; if (isset($this->explosions[$key])) { @@ -79,7 +78,6 @@ class TemplateRoute extends Route $value = urldecode($value); $variables[$key] = $value; } - } return $variables; diff --git a/src/Routing/Router.php b/src/Routing/Router.php index b368d6e..172d214 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -113,7 +113,10 @@ class Router } $stack = array_merge($this->stack, [$route]); return $this->dispatcher->dispatch( - $stack, $request, $response, $next + $stack, + $request, + $response, + $next ); } diff --git a/src/Server.php b/src/Server.php index 1c104b5..613dc98 100644 --- a/src/Server.php +++ b/src/Server.php @@ -29,7 +29,8 @@ class Server /** @var mixed[] List array of middleware */ private $stack; - public function __construct() { + public function __construct() + { $this->stack = []; $this->response = new Response(); $this->dispatcher = new Dispatcher(); @@ -84,7 +85,11 @@ class Server $response = $this->response; $response = $this->dispatcher->dispatch( - $this->stack, $request, $response, $next); + $this->stack, + $request, + $response, + $next + ); $this->transmitter->transmit($request, $response); } @@ -116,7 +121,8 @@ class Server * @param string $name * @return Server */ - public function setPathVariablesAttributeName(string $name): Server { + public function setPathVariablesAttributeName(string $name): Server + { $this->pathVariablesAttributeName = $name; return $this; } diff --git a/test/tests/integration/RoutingTest.php b/test/tests/integration/RoutingTest.php index 65ca2bb..cbc238c 100644 --- a/test/tests/integration/RoutingTest.php +++ b/test/tests/integration/RoutingTest.php @@ -108,7 +108,9 @@ class RoutingTest extends TestCase ->register('GET', '/oscar', new StringHandler('Oscar')); $this->server->add(new HeaderAdderMiddleware( - 'Content-type', 'application/cat')); + 'Content-type', + 'application/cat' + )); $this->server->add($router); $this->request = $this->request @@ -118,15 +120,19 @@ class RoutingTest extends TestCase $response = $this->respond(); $this->assertEquals('Molly', (string) $response->getBody()); - $this->assertEquals('application/cat', - $response->getHeaderLine('Content-type')); + $this->assertEquals( + 'application/cat', + $response->getHeaderLine('Content-type') + ); } public function testDispatchesMiddlewareSpecificToRouter() { $catRouter = $this->server->createRouter() ->add(new HeaderAdderMiddleware( - 'Content-type', 'application/cat')) + 'Content-type', + 'application/cat' + )) ->register('GET', '/molly', new StringHandler('Molly')) ->register('GET', '/oscar', new StringHandler('Oscar')) ->continueOnNotFound(); @@ -134,7 +140,9 @@ class RoutingTest extends TestCase $dogRouter = $this->server->createRouter() ->add(new HeaderAdderMiddleware( - 'Content-type', 'application/dog')) + 'Content-type', + 'application/dog' + )) ->register('GET', '/bear', new StringHandler('Bear')); $this->server->add($dogRouter); @@ -145,15 +153,19 @@ class RoutingTest extends TestCase $response = $this->respond(); $this->assertEquals('Bear', (string) $response->getBody()); - $this->assertEquals('application/dog', - $response->getHeaderLine('Content-type')); + $this->assertEquals( + 'application/dog', + $response->getHeaderLine('Content-type') + ); } public function testResponds404WhenNoRouteMatched() { $catRouter = $this->server->createRouter() ->add(new HeaderAdderMiddleware( - 'Content-type', 'application/cat')) + 'Content-type', + 'application/cat' + )) ->register('GET', '/molly', new StringHandler('Molly')) ->register('GET', '/oscar', new StringHandler('Oscar')) ->continueOnNotFound(); @@ -161,7 +173,9 @@ class RoutingTest extends TestCase $dogRouter = $this->server->createRouter() ->add(new HeaderAdderMiddleware( - 'Content-type', 'application/dog')) + 'Content-type', + 'application/dog' + )) ->register('GET', '/bear', new StringHandler('Bear')); $this->server->add($dogRouter); diff --git a/test/tests/unit/Dispatching/DispatcherTest.php b/test/tests/unit/Dispatching/DispatcherTest.php index 6fd5c6c..63c6019 100644 --- a/test/tests/unit/Dispatching/DispatcherTest.php +++ b/test/tests/unit/Dispatching/DispatcherTest.php @@ -70,7 +70,8 @@ class DispatcherTest extends TestCase // ------------------------------------------------------------------------- // PSR-15 Middleware - public function testDispatchesPsr15MiddlewareWithDelegate() { + public function testDispatchesPsr15MiddlewareWithDelegate() + { $this->next->upstreamResponse = $this->stubResponse; $middleware = new MiddlewareDouble(); @@ -78,7 +79,8 @@ class DispatcherTest extends TestCase $this->assertSame($this->stubResponse, $response); } - public function testDispatchesPsr15MiddlewareFromFactoryWithDelegate() { + public function testDispatchesPsr15MiddlewareFromFactoryWithDelegate() + { $this->next->upstreamResponse = $this->stubResponse; $factory = function () { return new MiddlewareDouble(); diff --git a/test/tests/unit/Message/MessageTest.php b/test/tests/unit/Message/MessageTest.php index 6bdc81b..093331e 100644 --- a/test/tests/unit/Message/MessageTest.php +++ b/test/tests/unit/Message/MessageTest.php @@ -41,7 +41,8 @@ class MessageTest extends TestCase $this->assertNotEquals( $message1->getHeader('Content-type'), - $message2->getHeader('Content-type')); + $message2->getHeader('Content-type') + ); } // ------------------------------------------------------------------------ @@ -121,7 +122,8 @@ class MessageTest extends TestCase $cookies = $message->getHeader('Set-Cookie'); $this->assertTrue( in_array('cat=Molly', $cookies) && - in_array('dog=Bear', $cookies)); + in_array('dog=Bear', $cookies) + ); } public function testWithoutHeaderRemovesHeader() diff --git a/test/tests/unit/Routing/Route/MethodMapTest.php b/test/tests/unit/Routing/Route/MethodMapTest.php index 6da2b8f..285279d 100644 --- a/test/tests/unit/Routing/Route/MethodMapTest.php +++ b/test/tests/unit/Routing/Route/MethodMapTest.php @@ -27,7 +27,8 @@ class MethodMapTest extends TestCase $this->dispatcher = new Dispatcher(); } - private function getMethodMap() { + private function getMethodMap() + { return new MethodMap($this->dispatcher); } @@ -194,7 +195,8 @@ class MethodMapTest extends TestCase ]; } - private function assertContainsEach($expectedList, $actual) { + private function assertContainsEach($expectedList, $actual) + { foreach ($expectedList as $expected) { if (strpos($actual, $expected) === false) { $this->assertTrue(false, "'$actual' does not contain expected '$expected'"); diff --git a/test/tests/unit/Routing/Route/RouteTest.php b/test/tests/unit/Routing/Route/RouteTest.php index 694e53a..8c9af5d 100644 --- a/test/tests/unit/Routing/Route/RouteTest.php +++ b/test/tests/unit/Routing/Route/RouteTest.php @@ -28,7 +28,9 @@ class RouteTest extends TestCase ->willReturn(new Response()); $this->route = new StaticRoute( - self::TARGET, $this->methodMap->reveal()); + self::TARGET, + $this->methodMap->reveal() + ); } public function testReturnsTarget() diff --git a/test/tests/unit/Routing/RouterTest.php b/test/tests/unit/Routing/RouterTest.php index 3780ff1..2387e7e 100644 --- a/test/tests/unit/Routing/RouterTest.php +++ b/test/tests/unit/Routing/RouterTest.php @@ -414,7 +414,8 @@ class RouterTest extends TestCase $this->route->__invoke( $middlewareRequest, $middlewareResponse, - Argument::any())->shouldHaveBeenCalled(); + Argument::any() + )->shouldHaveBeenCalled(); } public function testDoesNotCallRouterMiddlewareWhenNoRouteMatches() @@ -447,7 +448,7 @@ class RouterTest extends TestCase class RouterWithFactory extends Router { - static $routeFactory; + public static $routeFactory; protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactoryInterface {