8 use Zend\Code\Reflection\MethodReflection;
27 $this->_typeProcessor = $typeProcessor;
67 $classReflection = new \Zend\Code\Reflection\ClassReflection(
$className);
69 foreach ($classReflection->getMethods() as $methodReflection) {
70 $methodName = $methodReflection->getName();
71 if (array_key_exists($methodName,
$methods)) {
72 $data[$methodName] = $this->extractMethodData($methodReflection);
85 public function extractMethodData(\
Zend\Code\Reflection\MethodReflection
$method)
89 foreach (
$method->getParameters() as $parameter) {
91 'type' => $this->_typeProcessor->register($this->_typeProcessor->getParamType($parameter)),
92 'required' => !$parameter->isOptional(),
93 'documentation' => $this->_typeProcessor->getParamDescription($parameter),
95 if ($parameter->isOptional()) {
96 $parameterData[
'default'] = $parameter->getDefaultValue();
98 $methodData[
'interface'][
'in'][
'parameters'][$parameter->getName()] = $parameterData;
100 $returnType = $this->_typeProcessor->getGetterReturnType(
$method);
101 if ($returnType[
'type'] !=
'void' && $returnType[
'type'] !=
'null') {
102 $methodData[
'interface'][
'out'][
'parameters'][
'result'] = [
103 'type' => $this->_typeProcessor->register($returnType[
'type']),
104 'documentation' => $returnType[
'description'],
108 $exceptions = $this->_typeProcessor->getExceptions(
$method);
109 if (!empty($exceptions)) {
110 $methodData[
'interface'][
'out'][
'throws'] = $exceptions;
124 $methodReflection =
new MethodReflection(
125 $method->getDeclaringClass()->getName(),
129 $docBlock = $methodReflection->getDocBlock();
131 throw new \LogicException(
132 'The docBlock of the method '.
133 $method->getDeclaringClass()->getName() .
'::' .
$method->getName() .
' is empty.' 136 return $this->_typeProcessor->getDescription($docBlock);
147 $classReflection = new \Zend\Code\Reflection\ClassReflection(
$className);
148 $docBlock = $classReflection->getDocBlock();
152 return $this->_typeProcessor->getDescription($docBlock);
extractMethodDescription(\Zend\Code\Reflection\MethodReflection $method)
__construct(\Magento\Framework\Reflection\TypeProcessor $typeProcessor)
extractClassDescription($className)