Skip to content
Merged
Changes from all 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
21 changes: 6 additions & 15 deletions lib/internal/Magento/Framework/Reflection/TypeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ protected function dataObjectGetterDescriptionToFieldDescription($shortDescripti
* 'type' => <string>$type,
* 'isRequired' => $isRequired,
* 'description' => $description
* 'parameterCount' => $numberOfRequiredParameters
* )</pre>
* @throws \InvalidArgumentException
*/
Expand All @@ -309,23 +310,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()
];
Expand Down