Code style fixes

This commit is contained in:
PJ Dietz 2020-08-10 07:09:37 -04:00
parent a73ad17ddd
commit fb18d2ee1e
12 changed files with 62 additions and 29 deletions

View File

@ -7,9 +7,7 @@ $finder = PhpCsFixer\Finder::create()
return PhpCsFixer\Config::create() return PhpCsFixer\Config::create()
->setFinder($finder) ->setFinder($finder)
->setRiskyAllowed(true)
->setRules([ ->setRules([
'@PSR2' => true, '@PSR2' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'], 'array_syntax' => ['syntax' => 'short'],
]); ]);

View File

@ -195,7 +195,8 @@ class ServerRequest extends Request implements ServerRequestInterface
{ {
if (!$this->isValidUploadedFilesTree($uploadedFiles)) { if (!$this->isValidUploadedFilesTree($uploadedFiles)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
"withUploadedFiles expects an array tree with UploadedFileInterface leaves."); "withUploadedFiles expects an array tree with UploadedFileInterface leaves."
);
} }
$request = clone $this; $request = clone $this;
@ -413,7 +414,11 @@ class ServerRequest extends Request implements ServerRequestInterface
} else { } else {
// All expected keys are present and are not arrays. This is an uploaded file. // All expected keys are present and are not arrays. This is an uploaded file.
$uploadedFile = new UploadedFile( $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; $branch[$name] = $uploadedFile;
} }

View File

@ -69,7 +69,6 @@ class TemplateRoute extends Route
// Store named captures to the variables. // Store named captures to the variables.
foreach ($keys as $key) { foreach ($keys as $key) {
$value = $matches[$key]; $value = $matches[$key];
if (isset($this->explosions[$key])) { if (isset($this->explosions[$key])) {
@ -79,7 +78,6 @@ class TemplateRoute extends Route
$value = urldecode($value); $value = urldecode($value);
$variables[$key] = $value; $variables[$key] = $value;
} }
} }
return $variables; return $variables;

View File

@ -113,7 +113,10 @@ class Router
} }
$stack = array_merge($this->stack, [$route]); $stack = array_merge($this->stack, [$route]);
return $this->dispatcher->dispatch( return $this->dispatcher->dispatch(
$stack, $request, $response, $next $stack,
$request,
$response,
$next
); );
} }

View File

@ -29,7 +29,8 @@ class Server
/** @var mixed[] List array of middleware */ /** @var mixed[] List array of middleware */
private $stack; private $stack;
public function __construct() { public function __construct()
{
$this->stack = []; $this->stack = [];
$this->response = new Response(); $this->response = new Response();
$this->dispatcher = new Dispatcher(); $this->dispatcher = new Dispatcher();
@ -84,7 +85,11 @@ class Server
$response = $this->response; $response = $this->response;
$response = $this->dispatcher->dispatch( $response = $this->dispatcher->dispatch(
$this->stack, $request, $response, $next); $this->stack,
$request,
$response,
$next
);
$this->transmitter->transmit($request, $response); $this->transmitter->transmit($request, $response);
} }
@ -116,7 +121,8 @@ class Server
* @param string $name * @param string $name
* @return Server * @return Server
*/ */
public function setPathVariablesAttributeName(string $name): Server { public function setPathVariablesAttributeName(string $name): Server
{
$this->pathVariablesAttributeName = $name; $this->pathVariablesAttributeName = $name;
return $this; return $this;
} }

View File

@ -108,7 +108,9 @@ class RoutingTest extends TestCase
->register('GET', '/oscar', new StringHandler('Oscar')); ->register('GET', '/oscar', new StringHandler('Oscar'));
$this->server->add(new HeaderAdderMiddleware( $this->server->add(new HeaderAdderMiddleware(
'Content-type', 'application/cat')); 'Content-type',
'application/cat'
));
$this->server->add($router); $this->server->add($router);
$this->request = $this->request $this->request = $this->request
@ -118,15 +120,19 @@ class RoutingTest extends TestCase
$response = $this->respond(); $response = $this->respond();
$this->assertEquals('Molly', (string) $response->getBody()); $this->assertEquals('Molly', (string) $response->getBody());
$this->assertEquals('application/cat', $this->assertEquals(
$response->getHeaderLine('Content-type')); 'application/cat',
$response->getHeaderLine('Content-type')
);
} }
public function testDispatchesMiddlewareSpecificToRouter() public function testDispatchesMiddlewareSpecificToRouter()
{ {
$catRouter = $this->server->createRouter() $catRouter = $this->server->createRouter()
->add(new HeaderAdderMiddleware( ->add(new HeaderAdderMiddleware(
'Content-type', 'application/cat')) 'Content-type',
'application/cat'
))
->register('GET', '/molly', new StringHandler('Molly')) ->register('GET', '/molly', new StringHandler('Molly'))
->register('GET', '/oscar', new StringHandler('Oscar')) ->register('GET', '/oscar', new StringHandler('Oscar'))
->continueOnNotFound(); ->continueOnNotFound();
@ -134,7 +140,9 @@ class RoutingTest extends TestCase
$dogRouter = $this->server->createRouter() $dogRouter = $this->server->createRouter()
->add(new HeaderAdderMiddleware( ->add(new HeaderAdderMiddleware(
'Content-type', 'application/dog')) 'Content-type',
'application/dog'
))
->register('GET', '/bear', new StringHandler('Bear')); ->register('GET', '/bear', new StringHandler('Bear'));
$this->server->add($dogRouter); $this->server->add($dogRouter);
@ -145,15 +153,19 @@ class RoutingTest extends TestCase
$response = $this->respond(); $response = $this->respond();
$this->assertEquals('Bear', (string) $response->getBody()); $this->assertEquals('Bear', (string) $response->getBody());
$this->assertEquals('application/dog', $this->assertEquals(
$response->getHeaderLine('Content-type')); 'application/dog',
$response->getHeaderLine('Content-type')
);
} }
public function testResponds404WhenNoRouteMatched() public function testResponds404WhenNoRouteMatched()
{ {
$catRouter = $this->server->createRouter() $catRouter = $this->server->createRouter()
->add(new HeaderAdderMiddleware( ->add(new HeaderAdderMiddleware(
'Content-type', 'application/cat')) 'Content-type',
'application/cat'
))
->register('GET', '/molly', new StringHandler('Molly')) ->register('GET', '/molly', new StringHandler('Molly'))
->register('GET', '/oscar', new StringHandler('Oscar')) ->register('GET', '/oscar', new StringHandler('Oscar'))
->continueOnNotFound(); ->continueOnNotFound();
@ -161,7 +173,9 @@ class RoutingTest extends TestCase
$dogRouter = $this->server->createRouter() $dogRouter = $this->server->createRouter()
->add(new HeaderAdderMiddleware( ->add(new HeaderAdderMiddleware(
'Content-type', 'application/dog')) 'Content-type',
'application/dog'
))
->register('GET', '/bear', new StringHandler('Bear')); ->register('GET', '/bear', new StringHandler('Bear'));
$this->server->add($dogRouter); $this->server->add($dogRouter);

View File

@ -70,7 +70,8 @@ class DispatcherTest extends TestCase
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// PSR-15 Middleware // PSR-15 Middleware
public function testDispatchesPsr15MiddlewareWithDelegate() { public function testDispatchesPsr15MiddlewareWithDelegate()
{
$this->next->upstreamResponse = $this->stubResponse; $this->next->upstreamResponse = $this->stubResponse;
$middleware = new MiddlewareDouble(); $middleware = new MiddlewareDouble();
@ -78,7 +79,8 @@ class DispatcherTest extends TestCase
$this->assertSame($this->stubResponse, $response); $this->assertSame($this->stubResponse, $response);
} }
public function testDispatchesPsr15MiddlewareFromFactoryWithDelegate() { public function testDispatchesPsr15MiddlewareFromFactoryWithDelegate()
{
$this->next->upstreamResponse = $this->stubResponse; $this->next->upstreamResponse = $this->stubResponse;
$factory = function () { $factory = function () {
return new MiddlewareDouble(); return new MiddlewareDouble();

View File

@ -41,7 +41,8 @@ class MessageTest extends TestCase
$this->assertNotEquals( $this->assertNotEquals(
$message1->getHeader('Content-type'), $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'); $cookies = $message->getHeader('Set-Cookie');
$this->assertTrue( $this->assertTrue(
in_array('cat=Molly', $cookies) && in_array('cat=Molly', $cookies) &&
in_array('dog=Bear', $cookies)); in_array('dog=Bear', $cookies)
);
} }
public function testWithoutHeaderRemovesHeader() public function testWithoutHeaderRemovesHeader()

View File

@ -27,7 +27,8 @@ class MethodMapTest extends TestCase
$this->dispatcher = new Dispatcher(); $this->dispatcher = new Dispatcher();
} }
private function getMethodMap() { private function getMethodMap()
{
return new MethodMap($this->dispatcher); 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) { foreach ($expectedList as $expected) {
if (strpos($actual, $expected) === false) { if (strpos($actual, $expected) === false) {
$this->assertTrue(false, "'$actual' does not contain expected '$expected'"); $this->assertTrue(false, "'$actual' does not contain expected '$expected'");

View File

@ -28,7 +28,9 @@ class RouteTest extends TestCase
->willReturn(new Response()); ->willReturn(new Response());
$this->route = new StaticRoute( $this->route = new StaticRoute(
self::TARGET, $this->methodMap->reveal()); self::TARGET,
$this->methodMap->reveal()
);
} }
public function testReturnsTarget() public function testReturnsTarget()

View File

@ -414,7 +414,8 @@ class RouterTest extends TestCase
$this->route->__invoke( $this->route->__invoke(
$middlewareRequest, $middlewareRequest,
$middlewareResponse, $middlewareResponse,
Argument::any())->shouldHaveBeenCalled(); Argument::any()
)->shouldHaveBeenCalled();
} }
public function testDoesNotCallRouterMiddlewareWhenNoRouteMatches() public function testDoesNotCallRouterMiddlewareWhenNoRouteMatches()
@ -447,7 +448,7 @@ class RouterTest extends TestCase
class RouterWithFactory extends Router class RouterWithFactory extends Router
{ {
static $routeFactory; public static $routeFactory;
protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactoryInterface protected function getRouteFactory(DispatcherInterface $dispatcher): RouteFactoryInterface
{ {