Skip to content

Commit 71c60ae

Browse files
committed
Optimization
1 parent d32942a commit 71c60ae

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/Analyser/MutatingScope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3314,7 +3314,7 @@ public function enterClassMethod(
33143314
$this->getRealParameterTypes($classMethod),
33153315
array_map(static fn (Type $type): Type => TemplateTypeHelper::toArgument($type), $phpDocParameterTypes),
33163316
$this->getRealParameterDefaultValues($classMethod),
3317-
$this->transformStaticType($this->getFunctionType($classMethod->returnType, $classMethod->returnType === null, false)),
3317+
$this->transformStaticType($this->getFunctionType($classMethod->returnType, false, false)),
33183318
$phpDocReturnType !== null ? TemplateTypeHelper::toArgument($phpDocReturnType) : null,
33193319
$throwType,
33203320
$deprecatedDescription,

src/Reflection/Php/PhpParameterReflection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Reflection\PassedByReference;
77
use PHPStan\Type\ConstantTypeHelper;
88
use PHPStan\Type\MixedType;
9-
use PHPStan\Type\NullType;
109
use PHPStan\Type\Type;
1110
use PHPStan\Type\TypeCombinator;
1211
use PHPStan\Type\TypehintHelper;
@@ -47,7 +46,6 @@ public function getType(): Type
4746
if (
4847
$this->reflection->isDefaultValueAvailable()
4948
&& $this->reflection->getDefaultValue() === null
50-
&& (new NullType())->isSuperTypeOf($phpDocType)->no()
5149
) {
5250
$phpDocType = TypeCombinator::addNull($phpDocType);
5351
}

src/Type/TypeCombinator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ class TypeCombinator
3434

3535
public static function addNull(Type $type): Type
3636
{
37-
return self::union($type, new NullType());
37+
if ((new NullType())->isSuperTypeOf($type)->no()) {
38+
return self::union($type, new NullType());
39+
}
40+
41+
return $type;
3842
}
3943

4044
public static function remove(Type $fromType, Type $typeToRemove): Type

0 commit comments

Comments
 (0)