summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-07-02 11:54:17 +0200
committerRoeland Jago Douma <rullzer@owncloud.com>2015-12-24 09:20:26 +0100
commit23c754aed3bfa5c795a03e63183158d028a6a408 (patch)
treec35d37f023edee6fa4784929b85fd88b8bd8676d /lib
parent9cdc3f0558b8c278e91037c2330b876da7ca99e2 (diff)
downloadnextcloud-server-23c754aed3bfa5c795a03e63183158d028a6a408.tar.gz
nextcloud-server-23c754aed3bfa5c795a03e63183158d028a6a408.zip
prefer scalar type hints over phpdoc annotation
use method exists lookup to be safe and not break on old hhvm versions add test that checks if type hint is preferred over annotation
Diffstat (limited to 'lib')
-rw-r--r--lib/private/appframework/utility/controllermethodreflector.php22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/private/appframework/utility/controllermethodreflector.php b/lib/private/appframework/utility/controllermethodreflector.php
index 63cf5ac24f0..1118332f930 100644
--- a/lib/private/appframework/utility/controllermethodreflector.php
+++ b/lib/private/appframework/utility/controllermethodreflector.php
@@ -60,16 +60,18 @@ class ControllerMethodReflector implements IControllerMethodReflector{
// extract type parameter information
preg_match_all('/@param\h+(?P<type>\w+)\h+\$(?P<var>\w+)/', $docs, $matches);
- // this is just a fix for PHP 5.3 (array_combine raises warning if called with
- // two empty arrays
- if($matches['var'] === array() && $matches['type'] === array()) {
- $this->types = array();
- } else {
- $this->types = array_combine($matches['var'], $matches['type']);
- }
+ $this->types = array_combine($matches['var'], $matches['type']);
- // get method parameters
foreach ($reflection->getParameters() as $param) {
+ // extract type information from PHP 7 scalar types and prefer them
+ // over phpdoc annotations
+ if (method_exists($param, 'getType')) {
+ $type = $param->getType();
+ if ($type !== null) {
+ $this->types[$param->getName()] = (string) $type;
+ }
+ }
+
if($param->isOptional()) {
$default = $param->getDefaultValue();
} else {
@@ -82,9 +84,9 @@ class ControllerMethodReflector implements IControllerMethodReflector{
/**
* Inspects the PHPDoc parameters for types
- * @param string $parameter the parameter whose type comments should be
+ * @param string $parameter the parameter whose type comments should be
* parsed
- * @return string|null type in the type parameters (@param int $something)
+ * @return string|null type in the type parameters (@param int $something)
* would return int or null if not existing
*/
public function getType($parameter) {