Skip to content

Commit 96fb891

Browse files
authored
MAGETWO-66751: Zend instead of regex in getGetterReturnType #6344
2 parents e1ce3ec + f307b07 commit 96fb891

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

lib/internal/Magento/Framework/Reflection/TypeProcessor.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ protected function dataObjectGetterDescriptionToFieldDescription($shortDescripti
288288
* 'type' => <string>$type,
289289
* 'isRequired' => $isRequired,
290290
* 'description' => $description
291+
* 'parameterCount' => $numberOfRequiredParameters
291292
* )</pre>
292293
* @throws \InvalidArgumentException
293294
*/
@@ -309,23 +310,13 @@ public function getGetterReturnType($methodReflection)
309310
}
310311
/** @var \Zend\Code\Reflection\DocBlock\Tag\ReturnTag $returnAnnotation */
311312
$returnAnnotation = current($returnAnnotations);
312-
$returnType = $returnAnnotation->getType();
313-
/*
314-
* Adding this code as a workaround since \Zend\Code\Reflection\DocBlock\Tag\ReturnTag::initialize does not
315-
* detect and return correct type for array of objects in annotation.
316-
* eg @return \Magento\Webapi\Service\Entity\SimpleData[] is returned with type
317-
* \Magento\Webapi\Service\Entity\SimpleData instead of \Magento\Webapi\Service\Entity\SimpleData[]
318-
*/
319-
$escapedReturnType = str_replace('[]', '\[\]', $returnType);
320-
$escapedReturnType = str_replace('\\', '\\\\', $escapedReturnType);
321-
322-
if (preg_match("/.*\\@return\\s+({$escapedReturnType}).*/i", $methodDocBlock->getContents(), $matches)) {
323-
$returnType = $matches[1];
324-
}
325-
$isNotRequired = (bool)preg_match("/.*\@return\s+\S+\|null.*/i", $methodDocBlock->getContents(), $matches);
313+
$types = $returnAnnotation->getTypes();
314+
$returnType = current($types);
315+
$nullable = in_array('null', $types);
316+
326317
return [
327318
'type' => $returnType,
328-
'isRequired' => !$isNotRequired,
319+
'isRequired' => !$nullable,
329320
'description' => $returnAnnotation->getDescription(),
330321
'parameterCount' => $methodReflection->getNumberOfRequiredParameters()
331322
];

0 commit comments

Comments
 (0)