Skip to content

Commit

Permalink
PhpParameterReflection - prevent more reflection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 12, 2020
1 parent 57a6585 commit ce3d231
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Reflection/Php/PhpParameterReflection.php
Expand Up @@ -47,8 +47,14 @@ public function getType(): Type
{
if ($this->type === null) {
$phpDocType = $this->phpDocType;
if ($phpDocType !== null && $this->reflection->isDefaultValueAvailable() && $this->reflection->getDefaultValue() === null) {
$phpDocType = \PHPStan\Type\TypeCombinator::addNull($phpDocType);
if ($phpDocType !== null) {
try {
if ($this->reflection->isDefaultValueAvailable() && $this->reflection->getDefaultValue() === null) {
$phpDocType = \PHPStan\Type\TypeCombinator::addNull($phpDocType);
}
} catch (\Throwable $e) {
// pass
}
}

$this->type = TypehintHelper::decideTypeFromReflection(
Expand Down Expand Up @@ -99,14 +105,13 @@ public function getNativeType(): Type

public function getDefaultValue(): ?Type
{
if ($this->reflection->isDefaultValueAvailable()) {
try {
try {
if ($this->reflection->isDefaultValueAvailable()) {
$defaultValue = $this->reflection->getDefaultValue();
} catch (\Throwable $e) {
return null;
return ConstantTypeHelper::getTypeFromValue($defaultValue);
}

return ConstantTypeHelper::getTypeFromValue($defaultValue);
} catch (\Throwable $e) {
return null;
}

return null;
Expand Down

0 comments on commit ce3d231

Please sign in to comment.