summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-02-21 10:48:06 +0100
committerGitHub <noreply@github.com>2018-02-21 10:48:06 +0100
commit09857e5a95b0a200adb2955ace3b69be2603d3d6 (patch)
tree2c7ffbbf68a1eee6ddacf9329984d71f63a27be2 /lib
parent6591a3bc366874ead2de646ae1ca920277c17bff (diff)
parentbb0c7b2943f4a56989dbad66a2d392a28dee5e91 (diff)
downloadnextcloud-server-09857e5a95b0a200adb2955ace3b69be2603d3d6.tar.gz
nextcloud-server-09857e5a95b0a200adb2955ace3b69be2603d3d6.zip
Merge pull request #8465 from nextcloud/strict_dispatcher
Make AppFramework/Http/Dispatcher strict
Diffstat (limited to 'lib')
-rw-r--r--lib/private/AppFramework/Http/Dispatcher.php24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/private/AppFramework/Http/Dispatcher.php b/lib/private/AppFramework/Http/Dispatcher.php
index ecf8462ebb6..6219ba47a41 100644
--- a/lib/private/AppFramework/Http/Dispatcher.php
+++ b/lib/private/AppFramework/Http/Dispatcher.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -44,9 +45,16 @@ use OCP\IRequest;
*/
class Dispatcher {
+ /** @var MiddlewareDispatcher */
private $middlewareDispatcher;
+
+ /** @var Http */
private $protocol;
+
+ /** @var ControllerMethodReflector */
private $reflector;
+
+ /** @var IRequest */
private $request;
/**
@@ -78,8 +86,8 @@ class Dispatcher {
* the response output
* @throws \Exception
*/
- public function dispatch(Controller $controller, $methodName) {
- $out = array(null, array(), null);
+ public function dispatch(Controller $controller, string $methodName): array {
+ $out = [null, [], null];
try {
// prefill reflector with everything thats needed for the
@@ -97,7 +105,7 @@ class Dispatcher {
} catch(\Exception $exception){
$response = $this->middlewareDispatcher->afterException(
$controller, $methodName, $exception);
- if (is_null($response)) {
+ if ($response === null) {
throw $exception;
}
}
@@ -126,11 +134,11 @@ class Dispatcher {
* @param string $methodName the method on the controller that should be executed
* @return Response
*/
- private function executeController($controller, $methodName) {
- $arguments = array();
+ private function executeController(Controller $controller, string $methodName): Response {
+ $arguments = [];
// valid types that will be casted
- $types = array('int', 'integer', 'bool', 'boolean', 'float');
+ $types = ['int', 'integer', 'bool', 'boolean', 'float'];
foreach($this->reflector->getParameters() as $param => $default) {
@@ -151,14 +159,14 @@ class Dispatcher {
) {
$value = false;
- } elseif($value !== null && in_array($type, $types)) {
+ } elseif($value !== null && \in_array($type, $types, true)) {
settype($value, $type);
}
$arguments[] = $value;
}
- $response = call_user_func_array(array($controller, $methodName), $arguments);
+ $response = \call_user_func_array([$controller, $methodName], $arguments);
// format response
if($response instanceof DataResponse || !($response instanceof Response)) {