Skip to content

Commit

Permalink
more return type
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 15, 2024
1 parent daf9d9f commit bb41025
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/ReflectionClassConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function __debugInfo(): array
/**
* @inheritDoc
*/
public function getDeclaringClass()
public function getDeclaringClass(): \ReflectionClass
{
return new ReflectionClass($this->className);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ReflectionFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getNode(): Function_
/**
* {@inheritDoc}
*/
public function getClosure()
public function getClosure(): \Closure
{
$this->initializeInternalReflection();

Expand Down
6 changes: 3 additions & 3 deletions src/ReflectionMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function __toString()
/**
* {@inheritDoc}
*/
public function getClosure($object = null)
public function getClosure($object = null): \Closure
{
$this->initializeInternalReflection();

Expand All @@ -148,7 +148,7 @@ public function getClosure($object = null)
/**
* {@inheritDoc}
*/
public function getDeclaringClass()
public function getDeclaringClass(): \ReflectionClass
{
return $this->declaringClass ?? new ReflectionClass($this->className);
}
Expand Down Expand Up @@ -184,7 +184,7 @@ public function getModifiers(): int
/**
* {@inheritDoc}
*/
public function getPrototype()
public function getPrototype(): \ReflectionMethod
{
$parent = $this->getDeclaringClass()->getParentClass();
if (!$parent) {
Expand Down
2 changes: 1 addition & 1 deletion src/ReflectionParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function getClass()
/**
* {@inheritDoc}
*/
public function getDeclaringClass()
public function getDeclaringClass(): ?\ReflectionClass
{
if ($this->declaringFunction instanceof \ReflectionMethod) {
return $this->declaringFunction->getDeclaringClass();
Expand Down
2 changes: 1 addition & 1 deletion src/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function __toString()
/**
* {@inheritDoc}
*/
public function getDeclaringClass()
public function getDeclaringClass(): \ReflectionClass
{
return new ReflectionClass($this->className);
}
Expand Down
35 changes: 14 additions & 21 deletions src/Traits/ReflectionClassLikeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public function getNamespaceName(): string
/**
* {@inheritDoc}
*/
public function getParentClass()
public function getParentClass(): \ReflectionClass|false
{
if (!isset($this->parentClass)) {
static $extendsField = 'extends';
Expand All @@ -479,7 +479,7 @@ public function getParentClass()
*
* @return ReflectionProperty[]
*/
public function getProperties($filter = null)
public function getProperties($filter = null): array
{
if (!isset($this->properties)) {
$directProperties = ReflectionProperty::collectFromClassNode($this->classLikeNode, $this->getName());
Expand Down Expand Up @@ -533,7 +533,7 @@ public function getProperty($name)
/**
* @inheritDoc
*/
public function getReflectionConstant($name)
public function getReflectionConstant($name): \ReflectionClassConstant|false
{
$classConstants = $this->getReflectionConstants();
foreach ($classConstants as $classConstant) {
Expand Down Expand Up @@ -577,7 +577,7 @@ function (array &$result, \ReflectionClass $instance, $isParent) {
/**
* {@inheritDoc}
*/
public function getShortName()
public function getShortName(): string
{
return $this->className;
}
Expand All @@ -595,7 +595,7 @@ public function getStartLine(): int
* @return array|null an array with new method names in keys and original names (in the format
* "TraitName::original") in values.
*/
public function getTraitAliases()
public function getTraitAliases(): array
{
$aliases = [];
$traits = $this->getTraits();
Expand Down Expand Up @@ -652,7 +652,7 @@ public function getTraits(): array
/**
* {@inheritDoc}
*/
public function hasConstant($name)
public function hasConstant($name): bool
{
$constants = $this->getConstants();
$hasConstant = isset($constants[$name]) || array_key_exists($name, $constants);
Expand All @@ -664,7 +664,7 @@ public function hasConstant($name)
* {@inheritdoc}
* @param string $name
*/
public function hasMethod($name)
public function hasMethod($name): bool
{
$methods = $this->getMethods();
foreach ($methods as $method) {
Expand All @@ -679,7 +679,7 @@ public function hasMethod($name)
/**
* {@inheritdoc}
*/
public function hasProperty($name)
public function hasProperty($name): bool
{
$properties = $this->getProperties();
foreach ($properties as $property) {
Expand All @@ -695,7 +695,7 @@ public function hasProperty($name)
* {@inheritDoc}
* @param string $interfaceName
*/
public function implementsInterface($interfaceName)
public function implementsInterface($interfaceName): bool
{
$allInterfaces = $this->getInterfaces();

Expand Down Expand Up @@ -765,7 +765,7 @@ public function isFinal(): bool
/**
* {@inheritDoc}
*/
public function isInstance($object)
public function isInstance($object): bool
{
if (!is_object($object)) {
throw new RuntimeException(sprintf('Parameter must be an object, "%s" provided.', gettype($object)));
Expand Down Expand Up @@ -897,10 +897,9 @@ public function getStaticProperties(): array
* @param mixed $default A default value to return in case the class does not declare
* a static property with the given name
*
* @return mixed
* @throws ReflectionException If there is no such property and no default value was given
*/
public function getStaticPropertyValue($name, $default = null)
public function getStaticPropertyValue($name, $default = null): mixed
{
$properties = $this->getStaticProperties();
$propertyExists = array_key_exists($name, $properties);
Expand All @@ -925,10 +924,8 @@ public function getStaticPropertyValue($name, $default = null)
*
* @param mixed $arg First argument
* @param mixed $args Accepts a variable number of arguments which are passed to the class constructor
*
* @return object
*/
public function newInstance($arg = null, ...$args)
public function newInstance($arg = null, ...$args): object
{
$args = array_slice(array_merge([$arg], $args), 0, func_num_args());
$this->initializeInternalReflection();
Expand All @@ -942,10 +939,8 @@ public function newInstance($arg = null, ...$args)
* @link http://php.net/manual/en/reflectionclass.newinstanceargs.php
*
* @param array $args The parameters to be passed to the class constructor as an array.
*
* @return object
*/
public function newInstanceArgs(array $args = [])
public function newInstanceArgs(array $args = []): ?object
{
$function = __FUNCTION__;
$this->initializeInternalReflection();
Expand All @@ -957,10 +952,8 @@ public function newInstanceArgs(array $args = [])
* Creates a new class instance without invoking the constructor.
*
* @link http://php.net/manual/en/reflectionclass.newinstancewithoutconstructor.php
*
* @return object
*/
public function newInstanceWithoutConstructor()
public function newInstanceWithoutConstructor(): object
{
$function = __FUNCTION__;
$this->initializeInternalReflection();
Expand Down
15 changes: 7 additions & 8 deletions src/Traits/ReflectionFunctionLikeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\NodeTraverser;
use ReflectionException;
use ReflectionExtension;

/**
Expand Down Expand Up @@ -53,7 +54,7 @@ trait ReflectionFunctionLikeTrait
/**
* {@inheritDoc}
*/
public function getClosureScopeClass()
public function getClosureScopeClass(): ?\ReflectionClass
{
$this->initializeInternalReflection();

Expand All @@ -63,7 +64,7 @@ public function getClosureScopeClass()
/**
* {@inheritDoc}
*/
public function getClosureThis()
public function getClosureThis(): ?object
{
$this->initializeInternalReflection();

Expand Down Expand Up @@ -175,11 +176,9 @@ public function getParameters(): array
/**
* Gets the specified return type of a function
*
* @return \ReflectionType
*
* @link http://php.net/manual/en/reflectionfunctionabstract.getreturntype.php
*/
public function getReturnType()
public function getReturnType(): ?\ReflectionType
{
$isBuiltin = false;
$returnType = $this->functionLikeNode->getReturnType();
Expand All @@ -205,13 +204,13 @@ public function getReturnType()
/**
* {@inheritDoc}
*/
public function getShortName()
public function getShortName(): string
{
if ($this->functionLikeNode instanceof Function_ || $this->functionLikeNode instanceof ClassMethod) {
return $this->functionLikeNode->name->toString();
}

return false;
throw new ReflectionException('unable to get short name');
}

public function getStartLine(): int
Expand All @@ -222,7 +221,7 @@ public function getStartLine(): int
/**
* {@inheritDoc}
*/
public function getStaticVariables()
public function getStaticVariables(): array
{
$nodeTraverser = new NodeTraverser();
$variablesCollector = new StaticVariablesCollector($this);
Expand Down

0 comments on commit bb41025

Please sign in to comment.