From 2906e42356c575ac4346ddc22432deabfceb21a4 Mon Sep 17 00:00:00 2001 From: Alex Gusev Date: Thu, 25 Aug 2016 19:33:39 +0300 Subject: [PATCH 1/3] Refactoring of getGetterReturnType method - \Zend\Code\Reflection\DocBlock\Tag\ReturnTag::getType is deprecated since 2.0.4 - array mark ('[]') is returned in the type name - '|null' is the item in the types array --- lib/internal/Magento/Framework/Reflection/TypeProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php index 173892316cd46..b631c1da0b8a1 100644 --- a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php @@ -309,7 +309,7 @@ public function getGetterReturnType($methodReflection) } /** @var \Zend\Code\Reflection\DocBlock\Tag\ReturnTag $returnAnnotation */ $returnAnnotation = current($returnAnnotations); - $returnType = $returnAnnotation->getType(); + // $returnType = $returnAnnotation->getType(); /* * Adding this code as a workaround since \Zend\Code\Reflection\DocBlock\Tag\ReturnTag::initialize does not * detect and return correct type for array of objects in annotation. From 27a6e8db54ec387171e8e702cff46d7db2d736a4 Mon Sep 17 00:00:00 2001 From: Alex Gusev Date: Thu, 25 Aug 2016 19:43:23 +0300 Subject: [PATCH 2/3] Use Zend reflection instead of regex'es. --- .../Framework/Reflection/TypeProcessor.php | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php index b631c1da0b8a1..91d4c6f778696 100644 --- a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php @@ -309,23 +309,13 @@ public function getGetterReturnType($methodReflection) } /** @var \Zend\Code\Reflection\DocBlock\Tag\ReturnTag $returnAnnotation */ $returnAnnotation = current($returnAnnotations); - // $returnType = $returnAnnotation->getType(); - /* - * Adding this code as a workaround since \Zend\Code\Reflection\DocBlock\Tag\ReturnTag::initialize does not - * detect and return correct type for array of objects in annotation. - * eg @return \Magento\Webapi\Service\Entity\SimpleData[] is returned with type - * \Magento\Webapi\Service\Entity\SimpleData instead of \Magento\Webapi\Service\Entity\SimpleData[] - */ - $escapedReturnType = str_replace('[]', '\[\]', $returnType); - $escapedReturnType = str_replace('\\', '\\\\', $escapedReturnType); - - if (preg_match("/.*\\@return\\s+({$escapedReturnType}).*/i", $methodDocBlock->getContents(), $matches)) { - $returnType = $matches[1]; - } - $isNotRequired = (bool)preg_match("/.*\@return\s+\S+\|null.*/i", $methodDocBlock->getContents(), $matches); + $types = $returnAnnotation->getTypes(); + $returnType = current($types); + $nullable = in_array('null', $types); + return [ 'type' => $returnType, - 'isRequired' => !$isNotRequired, + 'isRequired' => !$nullable, 'description' => $returnAnnotation->getDescription(), 'parameterCount' => $methodReflection->getNumberOfRequiredParameters() ]; From ab0ff78dfad00b612522a5b787f09bc4eef49809 Mon Sep 17 00:00:00 2001 From: Alex Gusev Date: Fri, 26 Aug 2016 11:59:36 +0300 Subject: [PATCH 3/3] Add missed entry to docs for @return --- lib/internal/Magento/Framework/Reflection/TypeProcessor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php index 91d4c6f778696..1990cdb039784 100644 --- a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php @@ -288,6 +288,7 @@ protected function dataObjectGetterDescriptionToFieldDescription($shortDescripti * 'type' => $type, * 'isRequired' => $isRequired, * 'description' => $description + * 'parameterCount' => $numberOfRequiredParameters * ) * @throws \InvalidArgumentException */