protected function renderParams(Method $method, $config) { $class = $method->getDeclaringClass(); if ($class->isInternal()) { $overrides = $config->getParameterOverrides(); if (isset($overrides[strtolower($class->getName())][$method->getName()])) { return '(' . implode(',', $overrides[strtolower($class->getName())][$method->getName()]) . ')'; } } $methodParams = array(); $params = $method->getParameters(); foreach ($params as $param) { $paramDef = $param->getTypeHintAsString(); $paramDef .= $param->isPassedByReference() ? '&' : ''; $paramDef .= $param->isVariadic() ? '...' : ''; $paramDef .= '$' . $param->getName(); if (!$param->isVariadic()) { if (false !== $param->isDefaultValueAvailable()) { $paramDef .= ' = ' . var_export($param->getDefaultValue(), true); } elseif ($param->isOptional()) { $paramDef .= ' = null'; } } $methodParams[] = $paramDef; } return '(' . implode(', ', $methodParams) . ')'; }
protected function renderReturnType(Method $method) { $type = $method->getReturnType(); return $type ? sprintf(': %s', $type) : ''; }
/** * Gets the declaration code, as a string, for the passed method. * * @param Method $method * @param array $namedParameters * @return string */ private function getMethodDeclaration(Method $method, array $namedParameters) { $declaration = 'public'; $declaration .= $method->isStatic() ? ' static' : ''; $declaration .= ' function ' . $method->getName() . '('; foreach ($method->getParameters() as $index => $parameter) { $declaration .= $parameter->getTypeHintAsString() . ' '; $name = isset($namedParameters[$index]) ? $namedParameters[$index] : $parameter->getName(); $declaration .= '$' . $name; $declaration .= ','; } $declaration = rtrim($declaration, ','); $declaration .= ') '; $returnType = $method->getReturnType(); if (!empty($returnType)) { $declaration .= ': ' . $returnType; } return $declaration; }