Skip to content

Commit

Permalink
Fix deprecated call in PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Nov 26, 2020
1 parent e86eb30 commit 1b17f80
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/ValueResolver/ContainerValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public function getParameterValue(\ReflectionParameter $parameter)
}

// Try to resolve the parameter by type.
$class = $parameter->getClass();
if ($class) {
$className = $class->getName();
$type = $parameter->getType();

foreach ($this->getClassNames($type) as $className) {
if ($this->container->has($className)) {
return $this->container->get($className);
}
Expand Down Expand Up @@ -88,4 +88,38 @@ public function getPropertyValue(\ReflectionProperty $property)

return $this->defaultValueResolver->getPropertyValue($property);
}

/**
* @return \ReflectionNamedType[]
*/
private function getReflectionNamedTypes(?\ReflectionType $type) : array
{
if ($type instanceof \ReflectionNamedType) {
return [$type];
}

if ($type instanceof \ReflectionUnionType) {
return $type->getTypes();
}

return [];
}

/**
* @return string[]
*/
private function getClassNames(?\ReflectionType $type) : array
{
$namedTypes = $this->getReflectionNamedTypes($type);

$classNames = [];

foreach ($namedTypes as $namedType) {
if (! $namedType->isBuiltin()) {
$classNames[] = $namedType->getName();
}
}

return $classNames;
}
}

0 comments on commit 1b17f80

Please sign in to comment.