Skip to content

Commit ce3d231

Browse files
committed
PhpParameterReflection - prevent more reflection errors
1 parent 57a6585 commit ce3d231

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/Reflection/Php/PhpParameterReflection.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ public function getType(): Type
4747
{
4848
if ($this->type === null) {
4949
$phpDocType = $this->phpDocType;
50-
if ($phpDocType !== null && $this->reflection->isDefaultValueAvailable() && $this->reflection->getDefaultValue() === null) {
51-
$phpDocType = \PHPStan\Type\TypeCombinator::addNull($phpDocType);
50+
if ($phpDocType !== null) {
51+
try {
52+
if ($this->reflection->isDefaultValueAvailable() && $this->reflection->getDefaultValue() === null) {
53+
$phpDocType = \PHPStan\Type\TypeCombinator::addNull($phpDocType);
54+
}
55+
} catch (\Throwable $e) {
56+
// pass
57+
}
5258
}
5359

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

100106
public function getDefaultValue(): ?Type
101107
{
102-
if ($this->reflection->isDefaultValueAvailable()) {
103-
try {
108+
try {
109+
if ($this->reflection->isDefaultValueAvailable()) {
104110
$defaultValue = $this->reflection->getDefaultValue();
105-
} catch (\Throwable $e) {
106-
return null;
111+
return ConstantTypeHelper::getTypeFromValue($defaultValue);
107112
}
108-
109-
return ConstantTypeHelper::getTypeFromValue($defaultValue);
113+
} catch (\Throwable $e) {
114+
return null;
110115
}
111116

112117
return null;

0 commit comments

Comments
 (0)