Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 6, 2022
1 parent d32942a commit 71c60ae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Analyser/MutatingScope.php
Expand Up @@ -3314,7 +3314,7 @@ public function enterClassMethod(
$this->getRealParameterTypes($classMethod),
array_map(static fn (Type $type): Type => TemplateTypeHelper::toArgument($type), $phpDocParameterTypes),
$this->getRealParameterDefaultValues($classMethod),
$this->transformStaticType($this->getFunctionType($classMethod->returnType, $classMethod->returnType === null, false)),
$this->transformStaticType($this->getFunctionType($classMethod->returnType, false, false)),
$phpDocReturnType !== null ? TemplateTypeHelper::toArgument($phpDocReturnType) : null,
$throwType,
$deprecatedDescription,
Expand Down
2 changes: 0 additions & 2 deletions src/Reflection/Php/PhpParameterReflection.php
Expand Up @@ -6,7 +6,6 @@
use PHPStan\Reflection\PassedByReference;
use PHPStan\Type\ConstantTypeHelper;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypehintHelper;
Expand Down Expand Up @@ -47,7 +46,6 @@ public function getType(): Type
if (
$this->reflection->isDefaultValueAvailable()
&& $this->reflection->getDefaultValue() === null
&& (new NullType())->isSuperTypeOf($phpDocType)->no()
) {
$phpDocType = TypeCombinator::addNull($phpDocType);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Type/TypeCombinator.php
Expand Up @@ -34,7 +34,11 @@ class TypeCombinator

public static function addNull(Type $type): Type
{
return self::union($type, new NullType());
if ((new NullType())->isSuperTypeOf($type)->no()) {
return self::union($type, new NullType());
}

return $type;
}

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

0 comments on commit 71c60ae

Please sign in to comment.