Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phpstan 0.12 errors #2960

Merged
merged 6 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Slim/CallableResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function isMiddleware($toResolve): bool
*
* @throws RuntimeException
*
* @return array [Instance, Method Name]
* @return array<object|string|null> [Instance, Method Name]
*/
private function resolveSlimNotation(string $toResolve): array
{
Expand Down
2 changes: 1 addition & 1 deletion Slim/Error/Renderers/JsonErrorRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __invoke(Throwable $exception, bool $displayErrorDetails): strin

/**
* @param Throwable $exception
* @return array
* @return array<string|int>
*/
private function formatExceptionFragment(Throwable $exception): array
{
Expand Down
8 changes: 8 additions & 0 deletions Slim/Exception/HttpBadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@

class HttpBadRequestException extends HttpSpecializedException
{
/**
* @var int
*/
protected $code = 400;

/**
* @var string
*/
protected $message = 'Bad request.';

protected $title = '400 Bad Request';
protected $description = 'The server cannot or will not process the request due to an apparent client error.';
}
8 changes: 8 additions & 0 deletions Slim/Exception/HttpForbiddenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@

class HttpForbiddenException extends HttpSpecializedException
{
/**
* @var int
*/
protected $code = 403;

/**
* @var string
*/
protected $message = 'Forbidden.';

protected $title = '403 Forbidden';
protected $description = 'You are not permitted to perform the requested operation.';
}
8 changes: 8 additions & 0 deletions Slim/Exception/HttpInternalServerErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@

class HttpInternalServerErrorException extends HttpSpecializedException
{
/**
* @var int
*/
protected $code = 500;

/**
* @var string
*/
protected $message = 'Internal server error.';

protected $title = '500 Internal Server Error';
protected $description = 'Unexpected condition encountered preventing server from fulfilling request.';
}
14 changes: 11 additions & 3 deletions Slim/Exception/HttpMethodNotAllowedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,33 @@
class HttpMethodNotAllowedException extends HttpSpecializedException
{
/**
* @var array
* @var string[]
*/
protected $allowedMethods = [];

/**
* @var int
*/
protected $code = 405;

/**
* @var string
*/
protected $message = 'Method not allowed.';

protected $title = '405 Method Not Allowed';
protected $description = 'The request method is not supported for the requested resource.';

/**
* @return array
* @return string[]
*/
public function getAllowedMethods(): array
{
return $this->allowedMethods;
}

/**
* @param array $methods
* @param string[] $methods
* @return self
*/
public function setAllowedMethods(array $methods): HttpMethodNotAllowedException
Expand Down
8 changes: 8 additions & 0 deletions Slim/Exception/HttpNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@

class HttpNotFoundException extends HttpSpecializedException
{
/**
* @var int
*/
protected $code = 404;

/**
* @var string
*/
protected $message = 'Not found.';

protected $title = '404 Not Found';
protected $description = 'The requested resource could not be found. Please verify the URI and try again.';
}
8 changes: 8 additions & 0 deletions Slim/Exception/HttpNotImplementedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@

class HttpNotImplementedException extends HttpSpecializedException
{
/**
* @var int
*/
protected $code = 501;

/**
* @var string
*/
protected $message = 'Not implemented.';

protected $title = '501 Not Implemented';
protected $description = 'The server does not support the functionality required to fulfill the request.';
}
8 changes: 8 additions & 0 deletions Slim/Exception/HttpUnauthorizedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@

class HttpUnauthorizedException extends HttpSpecializedException
{
/**
* @var int
*/
protected $code = 401;

/**
* @var string
*/
protected $message = 'Unauthorized.';

protected $title = '401 Unauthorized';
protected $description = 'The request requires valid user authentication.';
}
4 changes: 2 additions & 2 deletions Slim/Handlers/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ErrorHandler implements ErrorHandlerInterface
protected $logErrorRenderer = PlainTextErrorRenderer::class;

/**
* @var array
* @var array<string|callable>
*/
protected $errorRenderers = [
'application/json' => JsonErrorRenderer::class,
Expand Down Expand Up @@ -122,7 +122,7 @@ class ErrorHandler implements ErrorHandlerInterface
*/
protected $responseFactory;

/*
/**
* @var LoggerInterface
*/
protected $logger;
Expand Down
2 changes: 1 addition & 1 deletion Slim/Handlers/Strategies/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(bool $appendRouteArgumentsToRequestAttributes = fals
* @param callable $callable
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param array $routeArguments
* @param array<mixed> $routeArguments
*
* @return ResponseInterface
*/
Expand Down
2 changes: 1 addition & 1 deletion Slim/Handlers/Strategies/RequestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RequestResponse implements InvocationStrategyInterface
* @param callable $callable
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param array $routeArguments
* @param array<mixed> $routeArguments
*
* @return ResponseInterface
*/
Expand Down
2 changes: 1 addition & 1 deletion Slim/Handlers/Strategies/RequestResponseArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RequestResponseArgs implements InvocationStrategyInterface
* @param callable $callable
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param array $routeArguments
* @param array<mixed> $routeArguments
*
* @return ResponseInterface
*/
Expand Down
2 changes: 1 addition & 1 deletion Slim/Interfaces/DispatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function dispatch(string $method, string $uri): RoutingResults;
* Get allowed methods for a given uri
*
* @param string $uri
* @return array
* @return string[]
*/
public function getAllowedMethods(string $uri): array;
}
2 changes: 1 addition & 1 deletion Slim/Interfaces/InvocationStrategyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface InvocationStrategyInterface
* @param callable $callable The callable to invoke using the strategy.
* @param ServerRequestInterface $request The request object.
* @param ResponseInterface $response The response object.
* @param array $routeArguments The route's placeholder arguments
* @param array<mixed> $routeArguments The route's placeholder arguments
*
* @return ResponseInterface The response from the callable.
*/
Expand Down
2 changes: 1 addition & 1 deletion Slim/Interfaces/Psr17FactoryProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Psr17FactoryProviderInterface
public static function getFactories(): array;

/**
* @var string[]
* @param string[] $factories
*/
public static function setFactories(array $factories): void;

Expand Down
2 changes: 1 addition & 1 deletion Slim/Interfaces/RouteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function addMiddleware(MiddlewareInterface $middleware): RouteInterface;
/**
* Prepare the route for use
*
* @param array $arguments
* @param string[] $arguments
* @return RouteInterface
*/
public function prepare(array $arguments): RouteInterface;
Expand Down
17 changes: 8 additions & 9 deletions Slim/Interfaces/RouteParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ interface RouteParserInterface
/**
* Build the path for a named route excluding the base path
*
*
* @param string $routeName Route name
* @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
* @param string $routeName Route name
* @param string[] $data Named argument replacement data
* @param string[] $queryParams Optional query string parameters
*
* @return string
*
Expand All @@ -34,9 +33,9 @@ public function relativeUrlFor(string $routeName, array $data = [], array $query
/**
* Build the path for a named route including the base path
*
* @param string $routeName Route name
* @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
* @param string $routeName Route name
* @param string[] $data Named argument replacement data
* @param string[] $queryParams Optional query string parameters
*
* @return string
*
Expand All @@ -50,8 +49,8 @@ public function urlFor(string $routeName, array $data = [], array $queryParams =
*
* @param UriInterface $uri
* @param string $routeName Route name
* @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
* @param string[] $data Named argument replacement data
* @param string[] $queryParams Optional query string parameters
*
* @return string
*/
Expand Down
6 changes: 3 additions & 3 deletions Slim/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
class Logger extends AbstractLogger
{
/**
* @param mixed $level
* @param string $message
* @param array $context
* @param mixed $level
* @param string $message
* @param array<mixed> $context
*
* @return void
*
Expand Down
2 changes: 1 addition & 1 deletion Slim/Middleware/BodyParsingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function registerDefaultBodyParsers(): void

/**
* @param ServerRequestInterface $request
* @return null|array|object
* @return null|array<mixed>|object
*/
protected function parseBody(ServerRequestInterface $request)
{
Expand Down
51 changes: 40 additions & 11 deletions Slim/MiddlewareDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function seedMiddlewareStack(RequestHandlerInterface $kernel): void
/**
* Invoke the middleware stack
*
* @param ServerRequestInterface $request
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
Expand Down Expand Up @@ -105,6 +105,7 @@ public function add($middleware): MiddlewareDispatcherInterface
return $this->addCallable($middleware);
}

/** @phpstan-ignore-next-line */
throw new RuntimeException(
'A middleware must be an object/class name referencing an implementation of ' .
'MiddlewareInterface or a callable with a matching signature.'
Expand All @@ -124,9 +125,15 @@ public function add($middleware): MiddlewareDispatcherInterface
public function addMiddleware(MiddlewareInterface $middleware): MiddlewareDispatcherInterface
{
$next = $this->tip;
$this->tip = new class ($middleware, $next) implements RequestHandlerInterface
{
$this->tip = new class ($middleware, $next) implements RequestHandlerInterface {
/**
* @var MiddlewareInterface
*/
private $middleware;

/**
* @var RequestHandlerInterface
*/
private $next;

public function __construct(MiddlewareInterface $middleware, RequestHandlerInterface $next)
Expand Down Expand Up @@ -162,11 +169,25 @@ public function addDeferred(string $middleware): self
$next,
$this->container,
$this->callableResolver
) implements RequestHandlerInterface
{
) implements RequestHandlerInterface {
/**
* @var string
*/
private $middleware;

/**
* @var RequestHandlerInterface
*/
private $next;

/**
* @var ContainerInterface|null
*/
private $container;

/**
* @var CallableResolverInterface|null
*/
private $callableResolver;

public function __construct(
Expand Down Expand Up @@ -236,10 +257,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface
}

if (!is_callable($callable)) {
throw new RuntimeException(sprintf(
'Middleware %s is not resolvable',
$this->middleware
));
throw new RuntimeException(
sprintf(
'Middleware %s is not resolvable',
$this->middleware
)
);
}

return $callable($request, $this->next);
Expand Down Expand Up @@ -267,9 +290,15 @@ public function addCallable(callable $middleware): self
$middleware = $middleware->bindTo($this->container);
}

$this->tip = new class ($middleware, $next) implements RequestHandlerInterface
{
$this->tip = new class ($middleware, $next) implements RequestHandlerInterface {
/**
* @var callable
*/
private $middleware;

/**
* @var RequestHandlerInterface
*/
private $next;

public function __construct(callable $middleware, RequestHandlerInterface $next)
Expand Down
Loading