Skip to content

Commit

Permalink
Insulating complexity in the parameter generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Mar 12, 2014
1 parent b6b90f1 commit eaaf10f
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/ProxyManager/Generator/ParameterGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@ public static function fromReflection(ParameterReflection $reflectionParameter)
$param->setType($type);
}

if ($reflectionParameter->isOptional()) {
try {
$param->setDefaultValue($reflectionParameter->getDefaultValue());
} catch (ReflectionException $e) {
$param->setDefaultValue(null);
}
}
self::setOptionalParameter($param, $reflectionParameter);

$param->setPassedByReference($reflectionParameter->isPassedByReference());

Expand Down Expand Up @@ -135,4 +129,23 @@ private function getGeneratedType()

return '\\' . trim($this->type, '\\') . ' ';
}

/**
* Set the default value for a parameter (if it is optional)
*
* @param ZendParameterGenerator $parameterGenerator
* @param ParameterReflection $reflectionParameter
*/
private static function setOptionalParameter(
ZendParameterGenerator $parameterGenerator,
ParameterReflection $reflectionParameter
) {
if ($reflectionParameter->isOptional()) {
try {
$parameterGenerator->setDefaultValue($reflectionParameter->getDefaultValue());
} catch (ReflectionException $e) {
$parameterGenerator->setDefaultValue(null);
}
}
}
}

0 comments on commit eaaf10f

Please sign in to comment.