Skip to content

Commit

Permalink
Disallow null returns where should not be possible
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar authored and Milan Felix Šulc committed Jul 28, 2018
1 parent 4ce259c commit dc56f0c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions phpstan.neon
Expand Up @@ -5,14 +5,22 @@ includes:

parameters:
ignoreErrors:
# Missing strict comparison
- '#^Construct empty\(\) is not allowed. Use more strict comparison.$#'
- '#^Only booleans are allowed in#'
- '#string|null given.$#'

# Magic access
- '#^Access to private property \$previous of parent class Exception.$#'

# Shoudl not happen - $method and $class are just missing in __construct
- '#^Cannot call method getMethod\(\) on Apitte\\Core\\Schema\\EndpointHandler\|null.$#'
- '#^Cannot call method getClass\(\) on Apitte\\Core\\Schema\\EndpointHandler\|null.$#'

# There is no apitte/negotiation dependency
- '#^Return typehint of method Apitte\\Core\\Http\\ApiResponse::getEntity\(\) has invalid type Apitte\\Negotiation\\Http\\AbstractEntity.$#'
- '#^Parameter \$entity of method Apitte\\Core\\Http\\ApiResponse::withEntity\(\) has invalid typehint type Apitte\\Negotiation\\Http\\AbstractEntity.$#'
- '#^Call to static method from\(\) on an unknown class Apitte\\Negotiation\\Http\\#'

# Maybe will cause application fail - DecoratorManager::decorateResponse could return null, but DecoratedDispatcher is not always able to handle it.
- '#Method Apitte\\Core\\Dispatcher\\DecoratedDispatcher::handle\(\) should return Psr\\Http\\Message\\ResponseInterface but returns Psr\\Http\\Message\\ResponseInterface|null.#'
4 changes: 2 additions & 2 deletions src/Dispatcher/CoreDispatcher.php
Expand Up @@ -24,7 +24,7 @@ public function __construct(IRouter $router, IHandler $handler)
$this->handler = $handler;
}

public function dispatch(ServerRequestInterface $request, ResponseInterface $response): ?ResponseInterface
public function dispatch(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
// Try match request to our routes
$matchedRequest = $this->match($request, $response);
Expand All @@ -43,7 +43,7 @@ protected function match(ServerRequestInterface $request, ResponseInterface $res
return $this->router->match($request);
}

protected function handle(ServerRequestInterface $request, ResponseInterface $response): ?ResponseInterface
protected function handle(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$response = $this->handler->handle($request, $response);

Expand Down
4 changes: 2 additions & 2 deletions src/Dispatcher/DecoratedDispatcher.php
Expand Up @@ -36,7 +36,7 @@ public function __construct(IRouter $router, IHandler $handler, DecoratorManager
* @param ApiRequest|ServerRequestInterface $request
* @param ApiResponse|ResponseInterface $response
*/
public function dispatch(ServerRequestInterface $request, ResponseInterface $response): ?ResponseInterface
public function dispatch(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
try {
// Route and call handler
Expand Down Expand Up @@ -64,7 +64,7 @@ public function dispatch(ServerRequestInterface $request, ResponseInterface $res
* @param ApiRequest $request
* @param ApiResponse $response
*/
protected function handle(ServerRequestInterface $request, ResponseInterface $response): ?ResponseInterface
protected function handle(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
// Pass endpoint to response
if (($endpoint = $request->getAttribute(RequestAttributes::ATTR_ENDPOINT, null))) {
Expand Down
2 changes: 1 addition & 1 deletion src/Dispatcher/IDispatcher.php
Expand Up @@ -8,6 +8,6 @@
interface IDispatcher
{

public function dispatch(ServerRequestInterface $request, ResponseInterface $response): ?ResponseInterface;
public function dispatch(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface;

}

0 comments on commit dc56f0c

Please sign in to comment.