Skip to content

Commit

Permalink
Merge pull request #309 from goaop/feature/php71-nullable-types
Browse files Browse the repository at this point in the history
Add support for nullable types for the PHP7.1
  • Loading branch information
lisachenko authored Jan 5, 2017
2 parents 96c7426 + c212ff9 commit c79ecee
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Proxy/AbstractProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ protected function getParameters(array $parameters)
protected function getParameterCode(ReflectionParameter $parameter)
{
$type = '';
if (PHP_VERSION_ID >= 50700) {
if (PHP_VERSION_ID >= 70000) {
$reflectionType = $parameter->getType();
if ($reflectionType) {
$nsPrefix = $reflectionType->isBuiltin() ? '' : '\\';
$type = $nsPrefix . (string) $reflectionType;
$nullablePrefix = $reflectionType->allowsNull() ? '?' : '';
$nsPrefix = $reflectionType->isBuiltin() ? '' : '\\';
$type = $nullablePrefix . $nsPrefix . (string) $reflectionType;
}
} else {
if ($parameter->isArray()) {
Expand Down Expand Up @@ -204,11 +205,13 @@ protected function prepareArgsLine(ReflectionFunctionAbstract $functionLike)
*/
protected function getOverriddenFunction(ReflectionFunctionAbstract $functionLike, $body)
{
$reflectionReturnType = PHP_VERSION_ID >= 50700 ? $functionLike->getReturnType() : '';
$reflectionReturnType = PHP_VERSION_ID >= 70000 ? $functionLike->getReturnType() : '';
$modifiersLine = '';
if ($reflectionReturnType) {
$nsPrefix = $reflectionReturnType->isBuiltin() ? '' : '\\';
$reflectionReturnType = $nsPrefix . (string)$reflectionReturnType;
$nullablePrefix = $reflectionReturnType->allowsNull() ? '?' : '';
$nsPrefix = $reflectionReturnType->isBuiltin() ? '' : '\\';

$reflectionReturnType = $nullablePrefix . $nsPrefix . (string) $reflectionReturnType;
}
if ($functionLike instanceof ReflectionMethod) {
$modifiersLine = join(' ', Reflection::getModifierNames($functionLike->getModifiers()));
Expand Down

0 comments on commit c79ecee

Please sign in to comment.