function ProxyBuilder::buildMethod

Same name in other branches
  1. 8.9.x core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php \Drupal\Component\ProxyBuilder\ProxyBuilder::buildMethod()
  2. 10 core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php \Drupal\Component\ProxyBuilder\ProxyBuilder::buildMethod()
  3. 11.x core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php \Drupal\Component\ProxyBuilder\ProxyBuilder::buildMethod()

Generates the string representation of a single method: signature, body.

Parameters

\ReflectionMethod $reflection_method: A reflection method for the method.

Return value

string

1 call to ProxyBuilder::buildMethod()
ProxyBuilder::build in core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php
Builds a proxy class string.

File

core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php, line 201

Class

ProxyBuilder
Generates the string representation of the proxy service.

Namespace

Drupal\Component\ProxyBuilder

Code

protected function buildMethod(\ReflectionMethod $reflection_method) {
    $parameters = [];
    foreach ($reflection_method->getParameters() as $parameter) {
        $parameters[] = $this->buildParameter($parameter);
    }
    $function_name = $reflection_method->getName();
    $reference = '';
    if ($reflection_method->returnsReference()) {
        $reference = '&';
    }
    $signature_line = <<<'EOS'
/**
 * {@inheritdoc}
 */

EOS;
    if ($reflection_method->isStatic()) {
        $signature_line .= 'public static function ' . $reference . $function_name . '(';
    }
    else {
        $signature_line .= 'public function ' . $reference . $function_name . '(';
    }
    $signature_line .= implode(', ', $parameters);
    $signature_line .= ')';
    if ($reflection_method->hasReturnType()) {
        $signature_line .= ': ';
        $return_type = $reflection_method->getReturnType();
        if ($return_type->allowsNull()) {
            $signature_line .= '?';
        }
        if (!$return_type->isBuiltin()) {
            // The parameter is a class or interface.
            $signature_line .= '\\';
        }
        $return_type_name = $return_type->getName();
        if ($return_type_name === 'self') {
            $return_type_name = $reflection_method->getDeclaringClass()
                ->getName();
        }
        $signature_line .= $return_type_name;
    }
    $output = $signature_line . "\n{\n";
    $output .= $this->buildMethodBody($reflection_method);
    $output .= "\n" . '}';
    return $output;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.