Skip to content

Commit 27a6e8d

Browse files
committed
Use Zend reflection instead of regex'es.
1 parent 2906e42 commit 27a6e8d

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -309,23 +309,13 @@ public function getGetterReturnType($methodReflection)
309309
}
310310
/** @var \Zend\Code\Reflection\DocBlock\Tag\ReturnTag $returnAnnotation */
311311
$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);
312+
$types = $returnAnnotation->getTypes();
313+
$returnType = current($types);
314+
$nullable = in_array('null', $types);
315+
326316
return [
327317
'type' => $returnType,
328-
'isRequired' => !$isNotRequired,
318+
'isRequired' => !$nullable,
329319
'description' => $returnAnnotation->getDescription(),
330320
'parameterCount' => $methodReflection->getNumberOfRequiredParameters()
331321
];

0 commit comments

Comments
 (0)