Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed deprecated warning in ReflectionSourceStubber #522

Merged
merged 1 commit into from
Jan 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/SourceLocator/SourceStubber/ReflectionSourceStubber.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
use ReflectionFunction as CoreReflectionFunction;
use ReflectionFunctionAbstract as CoreReflectionFunctionAbstract;
use ReflectionMethod as CoreReflectionMethod;
use ReflectionNamedType as CoreReflectionNamedType;
use ReflectionParameter;
use ReflectionProperty as CoreReflectionProperty;
use ReflectionType as CoreReflectionType;
use Reflector as CoreReflector;
use function array_diff;
use function array_key_exists;
use function assert;
use function class_exists;
use function explode;
use function function_exists;
Expand Down Expand Up @@ -358,6 +359,7 @@ private function addMethods(Declaration $classNode, CoreReflectionClass $classRe
$this->addParameters($methodNode, $methodReflection);

$returnType = $methodReflection->getReturnType();
assert($returnType instanceof CoreReflectionNamedType || $returnType === null);

if ($methodReflection->getReturnType() !== null) {
$methodNode->setReturnType($this->formatType($returnType));
Expand Down Expand Up @@ -445,6 +447,7 @@ private function addParameterModifiers(ReflectionParameter $parameterReflection,
}

$parameterType = $parameterReflection->getType();
assert($parameterType instanceof CoreReflectionNamedType || $parameterType === null);

if ($parameterReflection->getType() !== null) {
$parameterNode->setType($this->formatType($parameterType));
Expand All @@ -470,9 +473,9 @@ private function parameterDefaultValue(
/**
* @return Name|FullyQualified|NullableType
*/
private function formatType(CoreReflectionType $type) : NodeAbstract
private function formatType(CoreReflectionNamedType $type) : NodeAbstract
{
$name = (string) $type;
$name = $type->getName();
$nameNode = $type->isBuiltin() || in_array($name, ['self', 'parent'], true) ? new Name($name) : new FullyQualified($name);

return $type->allowsNull() ? new NullableType($nameNode) : $nameNode;
Expand Down