PHPUnit_Util_Class::getMethodParameters PHP Method

getMethodParameters() public static method

Returns the parameters of a function or method.
public static getMethodParameters ( ReflectionFunction | ReflectionMethod $method, boolean $forCall = FALSE ) : string
$method ReflectionFunction | ReflectionMethod
$forCall boolean
return string
    public static function getMethodParameters($method, $forCall = FALSE)
    {
        $parameters = array();
        foreach ($method->getParameters() as $i => $parameter) {
            $name = '$' . $parameter->getName();
            if ($name === '$') {
                $name .= 'arg' . $i;
            }
            $default = '';
            $typeHint = '';
            if (!$forCall) {
                if ($parameter->isArray()) {
                    $typeHint = 'array ';
                } else {
                    try {
                        $class = $parameter->getClass();
                    } catch (ReflectionException $e) {
                        $class = FALSE;
                    }
                    if ($class) {
                        $typeHint = $class->getName() . ' ';
                    }
                }
                if ($parameter->isDefaultValueAvailable()) {
                    $value = $parameter->getDefaultValue();
                    $default = ' = ' . var_export($value, TRUE);
                } else {
                    if ($parameter->isOptional()) {
                        $default = ' = null';
                    }
                }
            }
            $ref = '';
            if ($parameter->isPassedByReference()) {
                $ref = '&';
            }
            $parameters[] = $typeHint . $ref . $name . $default;
        }
        return join(', ', $parameters);
    }

Usage Example

#!/usr/bin/env php
<?php 
require dirname(__DIR__) . '/PHPUnit/Autoload.php';
$buffer = '';
$class = new ReflectionClass('PHPUnit_Framework_Assert');
$methods = array();
foreach ($class->getMethods() as $method) {
    $docblock = $method->getDocComment();
    $name = $method->getName();
    if (strpos($name, 'assert') === 0 || strpos($docblock, '@return PHPUnit_Framework_Constraint') !== FALSE) {
        $methods[$name] = array('class' => 'PHPUnit_Framework_Assert', 'docblock' => $docblock, 'sigDecl' => str_replace(array('= false', '= true'), array('= FALSE', '= TRUE'), PHPUnit_Util_Class::getMethodParameters($method)), 'sigCall' => PHPUnit_Util_Class::getMethodParameters($method, TRUE));
    }
}
$class = new ReflectionClass('PHPUnit_Framework_TestCase');
foreach ($class->getMethods() as $method) {
    $docblock = $method->getDocComment();
    $name = $method->getName();
    if (strpos($docblock, '@return PHPUnit_Framework_MockObject_Matcher') !== FALSE || strpos($docblock, '@return PHPUnit_Framework_MockObject_Stub') !== FALSE) {
        $methods[$name] = array('class' => 'PHPUnit_Framework_TestCase', 'docblock' => $docblock, 'sigDecl' => str_replace(array('= false', '= true'), array('= FALSE', '= TRUE'), PHPUnit_Util_Class::getMethodParameters($method)), 'sigCall' => PHPUnit_Util_Class::getMethodParameters($method, TRUE));
    }
}
ksort($methods);
foreach ($methods as $name => $data) {
    $buffer .= sprintf("\n\n%s\nfunction %s(%s)\n{\n    return call_user_func_array(\n      '%s::%s',\n      func_get_args()\n    );\n}", str_replace('    ', '', $data['docblock']), $name, $data['sigDecl'], $data['class'], $name, $data['sigCall']);
}
$template = new Text_Template(dirname(__DIR__) . '/PHPUnit/Framework/Assert/Functions.php.in');
$template->setVar(array('functions' => $buffer));
$template->renderTo(dirname(__DIR__) . '/PHPUnit/Framework/Assert/Functions.php');
All Usage Examples Of PHPUnit_Util_Class::getMethodParameters