protected function PHPUnit_Framework_MockObject_Generator::getMethodParameters in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php \PHPUnit_Framework_MockObject_Generator::getMethodParameters()
Returns the parameters of a function or method.
@since Method available since Release 2.0.0
Parameters
ReflectionMethod $method:
bool $forCall:
Return value
string
Throws
PHPUnit_Framework_MockObject_RuntimeException
1 call to PHPUnit_Framework_MockObject_Generator::getMethodParameters()
- PHPUnit_Framework_MockObject_Generator::generateMockedMethodDefinitionFromExisting in vendor/
phpunit/ phpunit-mock-objects/ src/ Framework/ MockObject/ Generator.php
File
- vendor/
phpunit/ phpunit-mock-objects/ src/ Framework/ MockObject/ Generator.php, line 1007
Class
- PHPUnit_Framework_MockObject_Generator
- Mock Object Code Generator
Code
protected function getMethodParameters(ReflectionMethod $method, $forCall = false) {
$parameters = array();
foreach ($method
->getParameters() as $i => $parameter) {
$name = '$' . $parameter
->getName();
/* Note: PHP extensions may use empty names for reference arguments
* or "..." for methods taking a variable number of arguments.
*/
if ($name === '$' || $name === '$...') {
$name = '$arg' . $i;
}
if ($this
->isVariadic($parameter)) {
if ($forCall) {
continue;
}
else {
$name = '...' . $name;
}
}
$default = '';
$reference = '';
$typeDeclaration = '';
if (!$forCall) {
if ($this
->hasType($parameter)) {
$typeDeclaration = (string) $parameter
->getType() . ' ';
}
elseif ($parameter
->isArray()) {
$typeDeclaration = 'array ';
}
elseif ((defined('HHVM_VERSION') || version_compare(PHP_VERSION, '5.4.0', '>=')) && $parameter
->isCallable()) {
$typeDeclaration = 'callable ';
}
else {
try {
$class = $parameter
->getClass();
} catch (ReflectionException $e) {
throw new PHPUnit_Framework_MockObject_RuntimeException(sprintf('Cannot mock %s::%s() because a class or ' . 'interface used in the signature is not loaded', $method
->getDeclaringClass()
->getName(), $method
->getName()), 0, $e);
}
if ($class !== null) {
$typeDeclaration = $class
->getName() . ' ';
}
}
if (!$this
->isVariadic($parameter)) {
if ($parameter
->isDefaultValueAvailable()) {
$value = $parameter
->getDefaultValue();
$default = ' = ' . var_export($value, true);
}
elseif ($parameter
->isOptional()) {
$default = ' = null';
}
}
}
if ($parameter
->isPassedByReference()) {
$reference = '&';
}
$parameters[] = $typeDeclaration . $reference . $name . $default;
}
return implode(', ', $parameters);
}