Skip to content

Commit 18dc5ff

Browse files
committed
ReflectionDescriptor - remove null
1 parent c6d9620 commit 18dc5ff

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Type/Doctrine/Descriptors/ReflectionDescriptor.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\Broker\Broker;
66
use PHPStan\Reflection\ParametersAcceptorSelector;
77
use PHPStan\Type\Type;
8+
use PHPStan\Type\TypeCombinator;
89

910
class ReflectionDescriptor implements DoctrineTypeDescriptor
1011
{
@@ -32,12 +33,16 @@ public function getType(): string
3233

3334
public function getWritableToPropertyType(): Type
3435
{
35-
return ParametersAcceptorSelector::selectSingle($this->broker->getClass($this->type)->getNativeMethod('convertToPHPValue')->getVariants())->getReturnType();
36+
$type = ParametersAcceptorSelector::selectSingle($this->broker->getClass($this->type)->getNativeMethod('convertToPHPValue')->getVariants())->getReturnType();
37+
38+
return TypeCombinator::removeNull($type);
3639
}
3740

3841
public function getWritableToDatabaseType(): Type
3942
{
40-
return ParametersAcceptorSelector::selectSingle($this->broker->getClass($this->type)->getNativeMethod('convertToDatabaseValue')->getVariants())->getParameters()[0]->getType();
43+
$type = ParametersAcceptorSelector::selectSingle($this->broker->getClass($this->type)->getNativeMethod('convertToDatabaseValue')->getVariants())->getParameters()[0]->getType();
44+
45+
return TypeCombinator::removeNull($type);
4146
}
4247

4348
}

tests/Rules/Doctrine/ORM/data/CustomType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public function getName(): string
2222
return self::NAME;
2323
}
2424

25-
public function convertToPHPValue($value, AbstractPlatform $abstractPlatform): DateTimeInterface
25+
public function convertToPHPValue($value, AbstractPlatform $abstractPlatform): ?DateTimeInterface
2626
{
2727
return new DateTimeImmutable();
2828
}
2929

3030
/**
3131
* @param array $value
3232
*/
33-
public function convertToDatabaseValue($value, AbstractPlatform $abstractPlatform): string
33+
public function convertToDatabaseValue($value, AbstractPlatform $abstractPlatform): ?string
3434
{
3535
return '';
3636
}

0 commit comments

Comments
 (0)