Skip to content
Permalink
Browse files

add php7.0 type definitions

  • Loading branch information...
danopz committed Apr 3, 2018
1 parent 898023e commit f7d432e0b93688d5fe8a529ebba406cfd645641f
Showing with 343 additions and 262 deletions.
  1. +38 −31 Slim/App.php
  2. +5 −2 Slim/CallableResolver.php
  3. +2 −0 Slim/DeferredCallable.php
  4. +5 −3 Slim/Error/AbstractErrorRenderer.php
  5. +9 −6 Slim/Error/Renderers/HtmlErrorRenderer.php
  6. +8 −4 Slim/Error/Renderers/JsonErrorRenderer.php
  7. +8 −4 Slim/Error/Renderers/PlainTextErrorRenderer.php
  8. +7 −3 Slim/Error/Renderers/XmlErrorRenderer.php
  9. +3 −0 Slim/Exception/HttpBadRequestException.php
  10. +19 −12 Slim/Exception/HttpException.php
  11. +3 −0 Slim/Exception/HttpForbiddenException.php
  12. +3 −0 Slim/Exception/HttpInternalServerErrorException.php
  13. +5 −2 Slim/Exception/HttpMethodNotAllowedException.php
  14. +3 −0 Slim/Exception/HttpNotFoundException.php
  15. +3 −0 Slim/Exception/HttpNotImplementedException.php
  16. +6 −4 Slim/Exception/HttpSpecializedException.php
  17. +3 −0 Slim/Exception/HttpUnauthorizedException.php
  18. +18 −16 Slim/Handlers/ErrorHandler.php
  19. +6 −3 Slim/Handlers/Strategies/RequestResponse.php
  20. +6 −3 Slim/Handlers/Strategies/RequestResponseArgs.php
  21. +4 −1 Slim/Interfaces/CallableResolverInterface.php
  22. +9 −7 Slim/Interfaces/ErrorHandlerInterface.php
  23. +11 −5 Slim/Interfaces/ErrorRendererInterface.php
  24. +5 −2 Slim/Interfaces/InvocationStrategyInterface.php
  25. +4 −1 Slim/Interfaces/RouteGroupInterface.php
  26. +12 −11 Slim/Interfaces/RouteInterface.php
  27. +14 −11 Slim/Interfaces/RouterInterface.php
  28. +10 −4 Slim/Middleware/ContentLengthMiddleware.php
  29. +15 −12 Slim/Middleware/ErrorMiddleware.php
  30. +8 −2 Slim/Middleware/MethodOverrideMiddleware.php
  31. +13 −8 Slim/Middleware/OutputBufferingMiddleware.php
  32. +11 −3 Slim/Middleware/RoutingMiddleware.php
  33. +7 −4 Slim/MiddlewareAwareTrait.php
  34. +7 −4 Slim/Routable.php
  35. +19 −24 Slim/Route.php
  36. +4 −1 Slim/RouteGroup.php
  37. +25 −34 Slim/Router.php
  38. +1 −0 tests/Handlers/ErrorHandlerTest.php
  39. +2 −2 tests/Mocks/InvocationStrategyTest.php
  40. +2 −2 tests/Mocks/MockErrorRenderer.php
  41. +0 −9 tests/RouteTest.php
  42. +0 −22 tests/RouterTest.php
@@ -6,13 +6,18 @@
* @copyright Copyright (c) 2011-2018 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
*/
declare(strict_types=1);
namespace Slim;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UriInterface;
use Slim\Exception\HttpMethodNotAllowedException;
use Slim\Exception\HttpNotFoundException;
use Slim\Http\Headers;
use Slim\Http\Request;
use Slim\Http\Response;
@@ -41,12 +46,12 @@ class App
private $container;
/**
* @var \Slim\Interfaces\CallableResolverInterface
* @var CallableResolverInterface
*/
protected $callableResolver;
/**
* @var \Slim\Interfaces\RouterInterface
* @var RouterInterface
*/
protected $router;
@@ -121,7 +126,7 @@ public function add($callable)
* @param string $key
* @return bool
*/
public function hasSetting($key)
public function hasSetting(string $key): bool
{
return isset($this->settings[$key]);
}
@@ -131,7 +136,7 @@ public function hasSetting($key)
*
* @return array
*/
public function getSettings()
public function getSettings(): array
{
return $this->settings;
}
@@ -143,7 +148,7 @@ public function getSettings()
* @param mixed $defaultValue
* @return mixed
*/
public function getSetting($key, $defaultValue = null)
public function getSetting(string $key, $defaultValue = null)
{
return $this->hasSetting($key) ? $this->settings[$key] : $defaultValue;
}
@@ -164,7 +169,7 @@ public function addSettings(array $settings)
* @param string $key
* @param mixed $value
*/
public function addSetting($key, $value)
public function addSetting(string $key, $value)
{
$this->settings[$key] = $value;
}
@@ -186,9 +191,9 @@ public function setCallableResolver(CallableResolverInterface $resolver)
/**
* Get callable resolver
*
* @return CallableResolver|null
* @return CallableResolverInterface
*/
public function getCallableResolver()
public function getCallableResolver(): CallableResolverInterface
{
if (! $this->callableResolver instanceof CallableResolverInterface) {
$this->callableResolver = new CallableResolver($this->container);
@@ -212,7 +217,7 @@ public function setRouter(RouterInterface $router)
*
* @return RouterInterface
*/
public function getRouter()
public function getRouter(): RouterInterface
{
if (! $this->router instanceof RouterInterface) {
$router = new Router();
@@ -239,9 +244,9 @@ public function getRouter()
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
* @return RouteInterface
*/
public function get($pattern, $callable)
public function get(string $pattern, $callable): RouteInterface
{
return $this->map(['GET'], $pattern, $callable);
}
@@ -252,9 +257,9 @@ public function get($pattern, $callable)
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
* @return RouteInterface
*/
public function post($pattern, $callable)
public function post(string $pattern, $callable): RouteInterface
{
return $this->map(['POST'], $pattern, $callable);
}
@@ -265,9 +270,9 @@ public function post($pattern, $callable)
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
* @return RouteInterface
*/
public function put($pattern, $callable)
public function put(string $pattern, $callable): RouteInterface
{
return $this->map(['PUT'], $pattern, $callable);
}
@@ -278,9 +283,9 @@ public function put($pattern, $callable)
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
* @return RouteInterface
*/
public function patch($pattern, $callable)
public function patch(string $pattern, $callable): RouteInterface
{
return $this->map(['PATCH'], $pattern, $callable);
}
@@ -291,9 +296,9 @@ public function patch($pattern, $callable)
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
* @return RouteInterface
*/
public function delete($pattern, $callable)
public function delete(string $pattern, $callable): RouteInterface
{
return $this->map(['DELETE'], $pattern, $callable);
}
@@ -304,9 +309,9 @@ public function delete($pattern, $callable)
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
* @return RouteInterface
*/
public function options($pattern, $callable)
public function options(string $pattern, $callable): RouteInterface
{
return $this->map(['OPTIONS'], $pattern, $callable);
}
@@ -317,9 +322,9 @@ public function options($pattern, $callable)
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
* @return RouteInterface
*/
public function any($pattern, $callable)
public function any(string $pattern, $callable): RouteInterface
{
return $this->map(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], $pattern, $callable);
}
@@ -333,7 +338,7 @@ public function any($pattern, $callable)
*
* @return RouteInterface
*/
public function map(array $methods, $pattern, $callable)
public function map(array $methods, string $pattern, $callable): RouteInterface
{
// Bind route callable to container, if present
if ($this->container instanceof ContainerInterface && $callable instanceof \Closure) {
@@ -355,7 +360,7 @@ public function map(array $methods, $pattern, $callable)
*
* @return RouteInterface
*/
public function redirect($from, $to, $status = 302)
public function redirect(string $from, $to, int $status = 302): RouteInterface
{
$handler = function ($request, ResponseInterface $response) use ($to, $status) {
return $response->withHeader('Location', (string)$to)->withStatus($status);
@@ -376,7 +381,7 @@ public function redirect($from, $to, $status = 302)
*
* @return RouteGroupInterface
*/
public function group($pattern, $callable)
public function group(string $pattern, $callable): RouteGroupInterface
{
/** @var RouteGroup $group */
$router = $this->getRouter();
@@ -403,7 +408,7 @@ public function group($pattern, $callable)
* @param RequestInterface|null $request
* @return ResponseInterface
*/
public function run(RequestInterface $request = null)
public function run(RequestInterface $request = null): ResponseInterface
{
// create request
if ($request === null) {
@@ -429,7 +434,7 @@ public function run(RequestInterface $request = null)
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function respond(ResponseInterface $response)
public function respond(ResponseInterface $response): ResponseInterface
{
// Send response
if (!headers_sent()) {
@@ -502,8 +507,10 @@ public function respond(ResponseInterface $response)
* @param ResponseInterface $response The most recent Response object
*
* @return ResponseInterface
* @throws HttpMethodNotAllowedException
* @throws HttpNotFoundException
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
// Get the route info
$routeInfo = $request->getAttribute('routeInfo');
@@ -530,7 +537,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
*
* @throws \RuntimeException
*/
protected function finalize(ResponseInterface $response)
protected function finalize(ResponseInterface $response): ResponseInterface
{
if ($this->isEmptyResponse($response)) {
return $response->withoutHeader('Content-Type')->withoutHeader('Content-Length');
@@ -548,7 +555,7 @@ protected function finalize(ResponseInterface $response)
* @param ResponseInterface $response
* @return bool
*/
protected function isEmptyResponse(ResponseInterface $response)
protected function isEmptyResponse(ResponseInterface $response): bool
{
if (method_exists($response, 'isEmpty')) {
return $response->isEmpty();
@@ -6,10 +6,13 @@
* @copyright Copyright (c) 2011-2018 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
*/
declare(strict_types=1);
namespace Slim;
use RuntimeException;
use Psr\Container\ContainerInterface;
use RuntimeException;
use Slim\Interfaces\CallableResolverInterface;
/**
@@ -44,7 +47,7 @@ public function __construct(ContainerInterface $container = null)
* @throws RuntimeException if the callable does not exist
* @throws RuntimeException if the callable is not resolvable
*/
public function resolve($toResolve)
public function resolve($toResolve): callable
{
$resolved = $toResolve;
@@ -7,6 +7,8 @@
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
*/
declare(strict_types=1);
namespace Slim;
use Slim\Interfaces\CallableResolverInterface;
@@ -6,11 +6,13 @@
* @copyright Copyright (c) 2011-2018 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
*/
declare(strict_types=1);
namespace Slim\Error;
use Slim\Http\Body;
use Slim\Interfaces\ErrorRendererInterface;
use Exception;
use Throwable;
/**
@@ -22,11 +24,11 @@
abstract class AbstractErrorRenderer implements ErrorRendererInterface
{
/**
* @param Exception|Throwable $exception
* @param Throwable $exception
* @param bool $displayErrorDetails
* @return Body
*/
public function renderWithBody($exception, $displayErrorDetails)
public function renderWithBody(Throwable $exception, bool $displayErrorDetails): Body
{
$output = $this->render($exception, $displayErrorDetails);
$body = new Body(fopen('php://temp', 'r+'));
@@ -6,22 +6,25 @@
* @copyright Copyright (c) 2011-2018 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
*/
declare(strict_types=1);
namespace Slim\Error\Renderers;
use Slim\Error\AbstractErrorRenderer;
use Exception;
use Throwable;
/**
* Default Slim application HTML Error Renderer
*/
class HtmlErrorRenderer extends AbstractErrorRenderer
{
/**
* @param \Exception|\Throwable $exception
* @param Throwable $exception
* @param bool $displayErrorDetails
* @return string
*/
public function render($exception, $displayErrorDetails)
public function render(Throwable $exception, bool $displayErrorDetails): string
{
$title = 'Slim Application Error';
@@ -41,7 +44,7 @@ public function render($exception, $displayErrorDetails)
* @param string $html
* @return string
*/
public function renderHtmlBody($title = '', $html = '')
public function renderHtmlBody(string $title = '', string $html = ''): string
{
return sprintf(
"<html>" .
@@ -67,10 +70,10 @@ public function renderHtmlBody($title = '', $html = '')
}
/**
* @param Exception $exception
* @param Throwable $exception
* @return string
*/
private function renderExceptionFragment($exception)
private function renderExceptionFragment(Throwable $exception): string
{
$html = sprintf('<div><strong>Type:</strong> %s</div>', get_class($exception));

0 comments on commit f7d432e

Please sign in to comment.
You can’t perform that action at this time.