/** * Helper method for generating trivial methods. * @param $methodName * @param $body * @param $docBlock * @param $parameterInfoArray * @return MethodGenerator */ private function createMethodGenerator($methodName, $body, DocBlockGenerator $docBlock, $parameterInfoArray, $returnType = null) { $parameters = []; foreach ($parameterInfoArray as $parameterInfo) { $parameters[] = new ParameterGenerator($parameterInfo[0], $parameterInfo[1]); } $methodGenerator = new MethodGenerator($methodName); $methodGenerator->setParameters($parameters); if ($returnType != null) { if (is_array($returnType)) { $returnType = implode('|', $returnType); } $tags[] = new GenericTag('return', $returnType); $docBlock->setTags($tags); } $methodGenerator->setDocBlock($docBlock); $methodGenerator->setBody($body); return $methodGenerator; }
/** * */ function addAPIParameterAccessMethod() { foreach ($this->apiParameters as $apiParameter => $type) { $translatedParam = ucfirst($this->translateParameter($apiParameter)); $methodGenerator = new MethodGenerator('get' . $translatedParam); $body = 'return $this->' . $apiParameter . ';' . PHP_EOL; $methodGenerator->setBody($body); $methodGenerator->setDocBlock("@return {$type}"); $this->classGenerator->addMethodFromGenerator($methodGenerator); $methodGenerator = new MethodGenerator('set' . $translatedParam); $body = '$this->' . $apiParameter . ' = $value;' . PHP_EOL; $parameterParameter = new ParameterGenerator('value'); $methodGenerator->setParameter($parameterParameter); $methodGenerator->setBody($body); $this->classGenerator->addMethodFromGenerator($methodGenerator); } }