Skip to content
This repository has been archived by the owner on Jun 30, 2020. It is now read-only.

Commit

Permalink
code styles
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Mar 1, 2016
1 parent 28690b2 commit 858eabf
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/Middleware/Csrf.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
return $next($request, $response);
}

$tokens =& self::getStorage($request, self::KEY);
$tokens = &self::getStorage($request, self::KEY);

if (Utils\Helpers::isPost($request) && !$this->validateRequest($request, $tokens)) {
return $response->withStatus(403);
Expand All @@ -85,6 +85,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res

if (!$this->autoInsert) {
$request = self::setAttribute($request, self::KEY_GENERATOR, $generator);

return $next($request, $response);
}

Expand Down
1 change: 1 addition & 0 deletions src/Middleware/FormTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res

if (!$this->autoInsert) {
$request = self::setAttribute($request, self::KEY_GENERATOR, $generator);

return $next($request, $response);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/Geolocate.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res

if ($ip !== null) {
if ($this->saveInSession) {
$ips =& self::getStorage($request, self::KEY);
$ips = &self::getStorage($request, self::KEY);

if (isset($ips[$ip])) {
$address = new AddressCollection($ips[$ip]);
Expand Down
1 change: 1 addition & 0 deletions src/Middleware/Honeypot.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res

if (!$this->autoInsert) {
$request = self::setAttribute($request, self::KEY_GENERATOR, $generator);

return $next($request, $response);
}

Expand Down
74 changes: 37 additions & 37 deletions src/Middleware/Whoops.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Whoops
use Utils\StreamTrait;

/**
* @var Run|null To handle errors using whoops
* @var Run|null The provided instance of Whoops
*/
private $whoops;

Expand Down Expand Up @@ -61,43 +61,43 @@ public function catchErrors($catchErrors = true)
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
ob_start();
$level = ob_get_level();

$method = Run::EXCEPTION_HANDLER;
$whoops = $this->getWhoopsInstance($request);

$whoops->allowQuit(false);
$whoops->writeToOutput(false);
$whoops->sendHttpCode(false);

//Catch errors means register whoops globally
if ($this->catchErrors) {
$whoops->register();
}

try {
$response = $next($request, $response);
} catch (\Throwable $exception) {
$body = self::createStream();
$body->write($whoops->$method($exception));
$response = $response->withStatus(500)->withBody($body);
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
ob_start();
$level = ob_get_level();

$method = Run::EXCEPTION_HANDLER;
$whoops = $this->getWhoopsInstance($request);

$whoops->allowQuit(false);
$whoops->writeToOutput(false);
$whoops->sendHttpCode(false);

//Catch errors means register whoops globally
if ($this->catchErrors) {
$whoops->register();
}

try {
$response = $next($request, $response);
} catch (\Throwable $exception) {
$body = self::createStream();
$body->write($whoops->$method($exception));
$response = $response->withStatus(500)->withBody($body);
} catch (\Exception $exception) {
$body = self::createStream();
$body->write($whoops->$method($exception));
$response = $response->withStatus(500)->withBody($body);
} finally {
Utils\Helpers::getOutput($level);
}

if ($this->catchErrors) {
$whoops->unregister();
}

return $response;
}
$body = self::createStream();
$body->write($whoops->$method($exception));
$response = $response->withStatus(500)->withBody($body);
} finally {
Utils\Helpers::getOutput($level);
}

if ($this->catchErrors) {
$whoops->unregister();
}

return $response;
}

/**
* Returns the whoops instance or create one.
Expand Down
2 changes: 1 addition & 1 deletion tests/LazyLoadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function ($request, $response, $next) {
);

$this->assertEquals($url, (string) $response->getBody());

if ($passed) {
$this->assertTrue($response->hasHeader('X-Response-Time'));
} else {
Expand Down
12 changes: 7 additions & 5 deletions tests/SessionStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function testAuraSessionStorage()
}
}

class Middleware1 {
class Middleware1
{
use Utils\StorageTrait;

public function __invoke($request, $response, $next)
Expand All @@ -46,14 +47,15 @@ public function __invoke($request, $response, $next)
}
}

class Middleware2 {
class Middleware2
{
use Utils\StorageTrait;

public function __invoke($request, $response, $next)
{
$storage =& self::getStorage($request, 'test');
$storage = &self::getStorage($request, 'test');
$storage['value'] = 'Hello';

return $next($request, $response);
}
}
}
4 changes: 4 additions & 0 deletions tests/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function testUuid1()
Middleware::Uuid(),
function ($request, $response, $next) {
$response->getBody()->write($request->getHeaderLine('X-Uuid'));

return $next($request, $response);
},
]
Expand All @@ -30,6 +31,7 @@ public function testUuid3()
Middleware::Uuid(3, Uuid::NAMESPACE_DNS, 'oscarotero.com'),
function ($request, $response, $next) {
$response->getBody()->write($request->getHeaderLine('X-Uuid'));

return $next($request, $response);
},
]
Expand All @@ -46,6 +48,7 @@ public function testUuid4()
Middleware::Uuid(4),
function ($request, $response, $next) {
$response->getBody()->write($request->getHeaderLine('X-Uuid'));

return $next($request, $response);
},
]
Expand All @@ -62,6 +65,7 @@ public function testUuid5()
Middleware::Uuid(5, Uuid::NAMESPACE_DNS, 'oscarotero.com'),
function ($request, $response, $next) {
$response->getBody()->write($request->getHeaderLine('X-Uuid'));

return $next($request, $response);
},
]
Expand Down

0 comments on commit 858eabf

Please sign in to comment.