-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set min PHP version to 7.4
- Loading branch information
Showing
13 changed files
with
229 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace rg\injektor; | ||
|
||
use ReflectionNamedType; | ||
use ReflectionParameter; | ||
use UnexpectedValueException; | ||
use function get_class; | ||
use function method_exists; | ||
|
||
/** | ||
* @copyright ResearchGate GmbH | ||
*/ | ||
class ReflectionClassHelper | ||
{ | ||
/** | ||
* @throws UnexpectedValueException | ||
*/ | ||
public static function getClassNameFromReflectionParameter(ReflectionParameter $parameter): ?string | ||
{ | ||
$reflectionType = $parameter->getType(); | ||
if ($reflectionType === null) { | ||
return null; | ||
} elseif ($reflectionType instanceof ReflectionNamedType) { | ||
if ($reflectionType->isBuiltin() === false) { | ||
return $reflectionType->getName(); | ||
} | ||
} elseif (method_exists($reflectionType, 'getTypes')) { | ||
foreach($reflectionType->getTypes() as $type) { | ||
if ($type->isBuiltin() === false) { | ||
return $type->getName(); | ||
} | ||
} | ||
} else { | ||
throw new UnexpectedValueException('Unsupported Reflection type: ' . get_class($reflectionType)); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.