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()
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
]);

View File

@ -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;
}

View File

@ -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;

View File

@ -113,7 +113,10 @@ class Router
}
$stack = array_merge($this->stack, [$route]);
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 */
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;
}

View File

@ -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);

View File

@ -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();

View File

@ -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()

View File

@ -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'");

View File

@ -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()

View File

@ -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
{